aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-03-13 17:02:56 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:21:12 +0100
commitb134f7d50d7312a5cbc3c424c0b8c6c73b3b6028 (patch)
treeb575e9bc3ac2c8fb701740a8a484174974baf4e0 /gcc
parent3861c44c7e7050685ee9a5f1492d6b678b1586d6 (diff)
downloadgcc-b134f7d50d7312a5cbc3c424c0b8c6c73b3b6028.zip
gcc-b134f7d50d7312a5cbc3c424c0b8c6c73b3b6028.tar.gz
gcc-b134f7d50d7312a5cbc3c424c0b8c6c73b3b6028.tar.bz2
gccrs: Only infer when no generic arguments have been specified
On Paths such as: mem::size_of<T>() we always specified to infer the generics which is not always the case and can cause stay inference variables. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): remove infer call (TypeCheckExpr::resolve_root_path): only infer when we need to gcc/testsuite/ChangeLog: * rust/compile/sizeof-stray-infer-var-bug.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-path.cc9
-rw-r--r--gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs14
2 files changed, 18 insertions, 5 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index c56c1dc..c496cbf 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -151,11 +151,6 @@ TypeCheckExpr::visit (HIR::PathInExpression &expr)
if (tyseg->get_kind () == TyTy::TypeKind::ERROR)
return;
- if (tyseg->needs_generic_substitutions ())
- {
- tyseg = SubstMapper::InferSubst (tyseg, expr.get_locus ());
- }
-
bool fully_resolved = offset == expr.get_segments ().size ();
if (fully_resolved)
{
@@ -285,6 +280,10 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset,
if (lookup->get_kind () == TyTy::TypeKind::ERROR)
return new TyTy::ErrorType (expr.get_mappings ().get_hirid ());
}
+ else if (lookup->needs_generic_substitutions ())
+ {
+ lookup = SubstMapper::InferSubst (lookup, expr.get_locus ());
+ }
*root_resolved_node_id = ref_node_id;
*offset = *offset + 1;
diff --git a/gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs b/gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs
new file mode 100644
index 0000000..310da66
--- /dev/null
+++ b/gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs
@@ -0,0 +1,14 @@
+mod mem {
+ extern "rust-intrinsic" {
+ pub fn size_of<T>() -> usize;
+ }
+}
+
+mod ptr {
+
+ pub unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
+ let x = x as *mut T;
+ let y = y as *mut T;
+ let len = mem::size_of::<T>() * count;
+ }
+}