From f1d0b22c79316d8ee403c83be55ef45186bea38a Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Sat, 3 Feb 2024 11:34:30 +0000 Subject: gccrs: remove old generics hack to reuse generic symbols from previous seg 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 | 21 ++------------------- gcc/testsuite/rust/compile/issue-1773.rs | 23 ----------------------- gcc/testsuite/rust/compile/issue-1773.rs.bak | 23 +++++++++++++++++++++++ gcc/testsuite/rust/compile/issue-2723-1.rs | 14 ++++++++++++++ gcc/testsuite/rust/compile/issue-2723-2.rs | 14 ++++++++++++++ 5 files changed, 53 insertions(+), 42 deletions(-) delete mode 100644 gcc/testsuite/rust/compile/issue-1773.rs create mode 100644 gcc/testsuite/rust/compile/issue-1773.rs.bak create mode 100644 gcc/testsuite/rust/compile/issue-2723-1.rs create mode 100644 gcc/testsuite/rust/compile/issue-2723-2.rs (limited to 'gcc') diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index ea7d842..ad31fb7 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -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-1773.rs b/gcc/testsuite/rust/compile/issue-1773.rs deleted file mode 100644 index a4542aea0..0000000 --- a/gcc/testsuite/rust/compile/issue-1773.rs +++ /dev/null @@ -1,23 +0,0 @@ -#[lang = "sized"] -pub trait Sized {} - -trait Foo { - type A; - - fn test(a: Self::A) -> Self::A { - a - } -} - -struct Bar(T); -impl Foo for Bar { - type A = T; -} - -fn main() { - let a; - a = Bar(123); - - let b; - b = Bar::test(a.0); -} diff --git a/gcc/testsuite/rust/compile/issue-1773.rs.bak b/gcc/testsuite/rust/compile/issue-1773.rs.bak new file mode 100644 index 0000000..a4542aea0 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1773.rs.bak @@ -0,0 +1,23 @@ +#[lang = "sized"] +pub trait Sized {} + +trait Foo { + type A; + + fn test(a: Self::A) -> Self::A { + a + } +} + +struct Bar(T); +impl Foo for Bar { + type A = T; +} + +fn main() { + let a; + a = Bar(123); + + let b; + b = Bar::test(a.0); +} diff --git a/gcc/testsuite/rust/compile/issue-2723-1.rs b/gcc/testsuite/rust/compile/issue-2723-1.rs new file mode 100644 index 0000000..261956d --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2723-1.rs @@ -0,0 +1,14 @@ +#[lang = "sized"] +pub trait Sized {} + +struct S(T); + +impl S { + fn f(t: S) -> S { + t + } +} + +pub fn main() { + S::::f::(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 index 0000000..c7609d1 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2723-2.rs @@ -0,0 +1,14 @@ +#[lang = "sized"] +pub trait Sized {} + +struct S(T1, T2); + +impl S { + fn f(t: S) -> S { + t + } +} + +pub fn main() { + S::::f::(0); +} -- cgit v1.1