]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: remove old generics hack to reuse generic symbols from previous seg
authorPhilip Herron <herron.philip@googlemail.com>
Sat, 3 Feb 2024 11:34:30 +0000 (11:34 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Sun, 4 Feb 2024 00:21:21 +0000 (00:21 +0000)
This patch introduces one regression because generics are getting better
understood over time. The code here used to apply generics with the same
symbol from previous segments which was a bit of a hack with out limited
inference variable support. The regression looks like it will be related
to another issue which needs to default integer inference variables much
more aggresivly to default integer.

Fixes #2723

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): remove hack

gcc/testsuite/ChangeLog:

* rust/compile/issue-1773.rs: Moved to...
* rust/compile/issue-1773.rs.bak: ...here.
* rust/compile/issue-2723-1.rs: New test.
* rust/compile/issue-2723-2.rs: New test.

gcc/rust/typecheck/rust-hir-type-check-path.cc
gcc/testsuite/rust/compile/issue-1773.rs.bak [moved from gcc/testsuite/rust/compile/issue-1773.rs with 100% similarity]
gcc/testsuite/rust/compile/issue-2723-1.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-2723-2.rs [new file with mode: 0644]

index 2066bbe4ce4af1feddddbb2f54539db304f23df5..5d0062eb8c4c0f2695003b9d5a0b1f1e3209d0e5 100644 (file)
@@ -456,27 +456,10 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
            }
        }
 
-      if (tyseg->needs_generic_substitutions ())
-       {
-         if (!prev_segment->needs_generic_substitutions ())
-           {
-             auto used_args_in_prev_segment
-               = GetUsedSubstArgs::From (prev_segment);
-
-             if (!used_args_in_prev_segment.is_error ())
-               {
-                 if (SubstMapperInternal::mappings_are_bound (
-                       tyseg, used_args_in_prev_segment))
-                   {
-                     tyseg = SubstMapperInternal::Resolve (
-                       tyseg, used_args_in_prev_segment);
-                   }
-               }
-           }
-       }
-
       if (seg.has_generic_args ())
        {
+         rust_debug_loc (seg.get_locus (), "applying segment generics: %s",
+                         tyseg->as_string ().c_str ());
          tyseg
            = SubstMapper::Resolve (tyseg, expr_locus, &seg.get_generic_args (),
                                    context->regions_from_generic_args (
diff --git a/gcc/testsuite/rust/compile/issue-2723-1.rs b/gcc/testsuite/rust/compile/issue-2723-1.rs
new file mode 100644 (file)
index 0000000..261956d
--- /dev/null
@@ -0,0 +1,14 @@
+#[lang = "sized"]
+pub trait Sized {}
+
+struct S<T>(T);
+
+impl S<i32> {
+    fn f<S>(t: S) -> S {
+        t
+    }
+}
+
+pub fn main() {
+    S::<i32>::f::<i32>(0);
+}
diff --git a/gcc/testsuite/rust/compile/issue-2723-2.rs b/gcc/testsuite/rust/compile/issue-2723-2.rs
new file mode 100644 (file)
index 0000000..c7609d1
--- /dev/null
@@ -0,0 +1,14 @@
+#[lang = "sized"]
+pub trait Sized {}
+
+struct S<T1, T2>(T1, T2);
+
+impl S<i32, i32> {
+    fn f<S>(t: S) -> S {
+        t
+    }
+}
+
+pub fn main() {
+    S::<i32, i32>::f::<i32>(0);
+}