Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccrs: fix bad type inference on local patterns #3237

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ());
}
Expand Down
9 changes: 9 additions & 0 deletions gcc/testsuite/rust/compile/issue-2323.rs
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading