Skip to content

Commit

Permalink
fix rust-lang#11847 a mismatch case
Browse files Browse the repository at this point in the history
  • Loading branch information
bitgaoshu committed May 4, 2022
1 parent 6262b60 commit 84921a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,16 @@ impl<'a> InferenceContext<'a> {
for ty in result.type_of_pat.values_mut() {
*ty = table.resolve_completely(ty.clone());
}
for mismatch in result.type_mismatches.values_mut() {
mismatch.expected = table.resolve_completely(mismatch.expected.clone());
mismatch.actual = table.resolve_completely(mismatch.actual.clone());
let mut n_type_mismatches = FxHashMap::default();
for (expr, TypeMismatch { expected, actual }) in result.type_mismatches.into_iter() {
let n_expected = table.resolve_completely(expected.clone());
let n_actual = table.resolve_completely(actual.clone());
if table.coerce(&n_actual, &n_expected).is_err() {
n_type_mismatches
.insert(expr, TypeMismatch { expected: n_expected, actual: n_actual });
}
}
result.type_mismatches = n_type_mismatches;
for (_, subst) in result.method_resolutions.values_mut() {
*subst = table.resolve_completely(subst.clone());
}
Expand Down
14 changes: 14 additions & 0 deletions crates/hir-ty/src/tests/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,20 @@ fn test() {
);
}

#[test]
fn coerce_inference_callback() {
check_no_mismatches(
r#"
//- minicore: coerce_unsized
fn print_me_later(x:&dyn core::fmt::Debug) {
}
fn main() {
print_me_later(&22);
}
"#,
);
}
#[test]
fn coerce_type_var() {
check_types(
Expand Down

0 comments on commit 84921a2

Please sign in to comment.