Skip to content

Commit

Permalink
gccrs: coercion sites allow for type inference as well.
Browse files Browse the repository at this point in the history
Addresses #3382 and #3381

gcc/rust/ChangeLog:

	* typecheck/rust-type-util.cc (coercion_site): allow inference vars

gcc/testsuite/ChangeLog:

	* rust/compile/reference1.rs: fix error message

Signed-off-by: Philip Herron <[email protected]>
  • Loading branch information
philberty committed Feb 3, 2025
1 parent 218df42 commit 12e9f5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions gcc/rust/typecheck/rust-type-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ coercion_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
rust_debug ("coerce_default_unify(a={%s}, b={%s})",
receiver->debug_str ().c_str (), expected->debug_str ().c_str ());
TyTy::BaseType *coerced
= unify_site (id, lhs, TyTy::TyWithLocation (receiver, rhs.get_locus ()),
locus);
= unify_site_and (id, lhs,
TyTy::TyWithLocation (receiver, rhs.get_locus ()), locus,
true /*emit_error*/, true /*commit*/, true /*infer*/,
true /*cleanup*/);
context->insert_autoderef_mappings (id, std::move (result.adjustments));
return coerced;
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/reference1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ fn main() {
let a = &123;
let b: &mut i32 = a;
// { dg-error "mismatched mutability" "" { target *-*-* } .-1 }
// { dg-error "mismatched types, expected .&mut i32. but got .& i32." "" { target *-*-* } .-2 }
// { dg-error "mismatched types, expected .&mut i32. but got .& <integer>." "" { target *-*-* } .-2 }
}

0 comments on commit 12e9f5d

Please sign in to comment.