public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: Only infer when no generic arguments have been specified
@ 2023-03-20  7:24 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-03-20  7:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:75b6a14c46e9572998f88ee211ae8e8323e0ce72

commit 75b6a14c46e9572998f88ee211ae8e8323e0ce72
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Mon Mar 13 17:02:56 2023 +0000

    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>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-path.cc           |  9 ++++-----
 gcc/testsuite/rust/compile/sizeof-stray-infer-var-bug.rs | 14 ++++++++++++++
 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 ac12eaedcb6..cd0c6703386 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 00000000000..310da661fca
--- /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;
+    }
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-20  7:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20  7:24 [gcc/devel/rust/master] gccrs: Only infer when no generic arguments have been specified Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).