Skip to content

Commit 591b547

Browse files
Point out expectation even if we have RegionsInsufficientlyPolymorphic
1 parent f525bb4 commit 591b547

9 files changed

+36
-28
lines changed

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1645,10 +1645,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16451645

16461646
augment_error(&mut err);
16471647

1648-
let is_insufficiently_polymorphic =
1649-
matches!(coercion_error, TypeError::RegionsInsufficientlyPolymorphic(..));
1650-
1651-
if !is_insufficiently_polymorphic && let Some(expr) = expression {
1648+
if let Some(expr) = expression {
16521649
fcx.emit_coerce_suggestions(
16531650
&mut err,
16541651
expr,

Diff for: compiler/rustc_hir_typeck/src/demand.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8484

8585
self.annotate_expected_due_to_let_ty(err, expr, error);
8686

87+
// FIXME(#73154): For now, we do leak check when coercing function
88+
// pointers in typeck, instead of only during borrowck. This can lead
89+
// to these `RegionsInsufficientlyPolymorphic` errors that aren't helpful.
90+
if matches!(error, Some(TypeError::RegionsInsufficientlyPolymorphic(..))) {
91+
return;
92+
}
93+
8794
if self.is_destruct_assignment_desugaring(expr) {
8895
return;
8996
}
@@ -263,22 +270,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
263270
let expr_ty = self.resolve_vars_with_obligations(checked_ty);
264271
let mut err = self.err_ctxt().report_mismatched_types(&cause, expected, expr_ty, e);
265272

266-
let is_insufficiently_polymorphic =
267-
matches!(e, TypeError::RegionsInsufficientlyPolymorphic(..));
268-
269-
// FIXME(#73154): For now, we do leak check when coercing function
270-
// pointers in typeck, instead of only during borrowck. This can lead
271-
// to these `RegionsInsufficientlyPolymorphic` errors that aren't helpful.
272-
if !is_insufficiently_polymorphic {
273-
self.emit_coerce_suggestions(
274-
&mut err,
275-
expr,
276-
expr_ty,
277-
expected,
278-
expected_ty_expr,
279-
Some(e),
280-
);
281-
}
273+
self.emit_coerce_suggestions(&mut err, expr, expr_ty, expected, expected_ty_expr, Some(e));
282274

283275
(expected, Some(err))
284276
}

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19271927
true
19281928
};
19291929

1930-
if should_suggest_fixes {
1930+
// FIXME(#73154): For now, we do leak check when coercing function
1931+
// pointers in typeck, instead of only during borrowck. This can lead
1932+
// to these `RegionsInsufficientlyPolymorphic` errors that aren't helpful.
1933+
if should_suggest_fixes
1934+
&& !matches!(terr, TypeError::RegionsInsufficientlyPolymorphic(..))
1935+
{
19311936
self.suggest_tuple_pattern(cause, &exp_found, diag);
19321937
self.suggest_accessing_field_where_appropriate(cause, &exp_found, diag);
19331938
self.suggest_await_on_expect_found(cause, span, &exp_found, diag);

Diff for: tests/ui/higher-ranked/subtype/placeholder-pattern-fail.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/placeholder-pattern-fail.rs:9:47
33
|
44
LL | let _: for<'a, 'b> fn(Inv<'a>, Inv<'b>) = sub;
5-
| ^^^ one type is more general than the other
5+
| -------------------------------- ^^^ one type is more general than the other
6+
| |
7+
| expected due to this
68
|
79
= note: expected fn pointer `for<'a, 'b> fn(Inv<'a>, Inv<'b>)`
810
found fn pointer `for<'a> fn(Inv<'a>, Inv<'a>)`

Diff for: tests/ui/higher-ranked/trait-bounds/hrtb-exists-forall-fn.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/hrtb-exists-forall-fn.rs:17:34
33
|
44
LL | let _: for<'b> fn(&'b u32) = foo();
5-
| ^^^^^ one type is more general than the other
5+
| ------------------- ^^^^^ one type is more general than the other
6+
| |
7+
| expected due to this
68
|
79
= note: expected fn pointer `for<'b> fn(&'b u32)`
810
found fn pointer `fn(&u32)`

Diff for: tests/ui/regions/higher-ranked-implied.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/higher-ranked-implied.rs:12:16
33
|
44
LL | let y: B = x;
5-
| ^ one type is more general than the other
5+
| - ^ one type is more general than the other
6+
| |
7+
| expected due to this
68
|
79
= note: expected fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>)`
810
found fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>)`
@@ -11,7 +13,9 @@ error[E0308]: mismatched types
1113
--> $DIR/higher-ranked-implied.rs:13:16
1214
|
1315
LL | let _: A = y;
14-
| ^ one type is more general than the other
16+
| - ^ one type is more general than the other
17+
| |
18+
| expected due to this
1519
|
1620
= note: expected fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'a ()>)`
1721
found fn pointer `for<'a, 'b> fn(Inv<&'a &'b ()>, Inv<&'b &'a ()>, Inv<&'b ()>)`

Diff for: tests/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:20:43
33
|
44
LL | let _: fn(&mut &isize, &mut &isize) = a;
5-
| ^ one type is more general than the other
5+
| ---------------------------- ^ one type is more general than the other
6+
| |
7+
| expected due to this
68
|
79
= note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)`
810
found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}`

Diff for: tests/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:22:56
33
|
44
LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a;
5-
| ^ one type is more general than the other
5+
| ----------------------------------------- ^ one type is more general than the other
6+
| |
7+
| expected due to this
68
|
79
= note: expected fn pointer `for<'a, 'b, 'c, 'd, 'e, 'f> fn(&'a mut &'b isize, &'c mut &'d isize, &'e mut &'f isize)`
810
found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a::<'_, '_, '_>}`

Diff for: tests/ui/regions/regions-lifetime-bounds-on-fns.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/regions-lifetime-bounds-on-fns.rs:20:43
33
|
44
LL | let _: fn(&mut &isize, &mut &isize) = a;
5-
| ^ one type is more general than the other
5+
| ---------------------------- ^ one type is more general than the other
6+
| |
7+
| expected due to this
68
|
79
= note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)`
810
found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}`

0 commit comments

Comments
 (0)