diff options
author | Philip Herron <herron.philip@googlemail.com> | 2024-11-01 16:18:28 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2024-11-01 17:03:01 +0000 |
commit | 4686e63c4e840417f2522fabb5611701eee92eca (patch) | |
tree | b92e6191106d0d8f220624fe0169c5211d76c375 /gcc | |
parent | 94957c0502bdee5567224f2fe556000b94cb4192 (diff) | |
download | gcc-4686e63c4e840417f2522fabb5611701eee92eca.zip gcc-4686e63c4e840417f2522fabb5611701eee92eca.tar.gz gcc-4686e63c4e840417f2522fabb5611701eee92eca.tar.bz2 |
gccrs: fix bad type inferencing on path's
This catch to inject inference variables into generic paths was a
catch all 'hack' that we needed before we handled generics correctly
as we do now.
Fixes #3009
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): remove hack
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3009.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.cc | 8 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-3009.rs | 24 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/nr2/exclude | 1 |
3 files changed, 25 insertions, 8 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index d2962e6..ddf2abc 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -490,14 +490,6 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, } rust_assert (resolved_node_id != UNKNOWN_NODEID); - if (tyseg->needs_generic_substitutions () && !reciever_is_generic) - { - location_t locus = segments.back ().get_locus (); - tyseg = SubstMapper::InferSubst (tyseg, locus); - if (tyseg->get_kind () == TyTy::TypeKind::ERROR) - return; - } - context->insert_receiver (expr_mappings.get_hirid (), prev_segment); // name scope first diff --git a/gcc/testsuite/rust/compile/issue-3009.rs b/gcc/testsuite/rust/compile/issue-3009.rs new file mode 100644 index 0000000..2eb4ef3 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3009.rs @@ -0,0 +1,24 @@ +#[lang = "sized"] +trait Sized {} + +struct Foo { + // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 } + t: u64, +} + +impl Foo { + fn of<T>() -> Foo { + // { dg-warning "associated function is never used" "" { target *-*-* } .-1 } + Foo { t: 14 } + } +} + +trait Bar { + fn bar() -> Foo; +} + +impl<T> Bar for T { + fn bar() -> Foo { + Foo::of::<T>() + } +} diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index ceada8b..4ba27d3 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -221,4 +221,5 @@ issue-3032-2.rs if_let_expr_simple.rs iflet.rs issue-3033.rs +issue-3009.rs # please don't delete the trailing newline |