diff options
author | Philip Herron <herron.philip@googlemail.com> | 2024-11-04 14:43:25 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:32:55 +0100 |
commit | 389756b2ac97beeb72cd160eeefee5ea381e55e9 (patch) | |
tree | e29f313e3ff5bd327348680aa3dd19a2b0b7120a /gcc | |
parent | cbab7a138956c7a83639b501194ca4031289e028 (diff) | |
download | gcc-389756b2ac97beeb72cd160eeefee5ea381e55e9.zip gcc-389756b2ac97beeb72cd160eeefee5ea381e55e9.tar.gz gcc-389756b2ac97beeb72cd160eeefee5ea381e55e9.tar.bz2 |
gccrs: fix bad type inference on local patterns
We do not need to inject inference variables on generic patterns
with generic blocks. This will just cause unconstrained inference
variables as they may not unify against something.
Fixes Rust-GCC#2323
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): dont infer here
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-2323.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 | 3 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2323.rs | 9 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/nr2/exclude | 1 |
3 files changed, 12 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 231ddd6..7b934b3 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -245,6 +245,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset, auto seg_is_module = mappings.lookup_module (ref).has_value (); auto seg_is_crate = mappings.is_local_hirid_crate (ref); + auto seg_is_pattern = mappings.lookup_hir_pattern (ref).has_value (); if (seg_is_module || seg_is_crate) { // A::B::C::this_is_a_module::D::E::F @@ -321,7 +322,7 @@ 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 ()) + else if (lookup->needs_generic_substitutions () && !seg_is_pattern) { lookup = SubstMapper::InferSubst (lookup, expr.get_locus ()); } diff --git a/gcc/testsuite/rust/compile/issue-2323.rs b/gcc/testsuite/rust/compile/issue-2323.rs new file mode 100644 index 0000000..02a3f90 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2323.rs @@ -0,0 +1,9 @@ +#[lang = "sized"] +trait Sized {} + +pub struct S<T>(T); + +pub fn foo<T>(x: T) { + let y = S(x); + y.0; +} diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index 4ba27d3..eaa2a1e 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -222,4 +222,5 @@ if_let_expr_simple.rs iflet.rs issue-3033.rs issue-3009.rs +issue-2323.rs # please don't delete the trailing newline |