Rollup merge of #106581 - estebank:bad-suggestion, r=compiler-errors

Do not emit wrong E0308 suggestion for closure mismatch

Found in #76353.
This commit is contained in:
Yuki Okushi 2023-01-08 17:01:49 +09:00 committed by GitHub
commit 789ebdca47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 1 deletions

View File

@ -1379,7 +1379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
// If we've reached our target type with just removing `&`, then just print now.
if steps == 0 {
if steps == 0 && !remove.trim().is_empty() {
return Some((
prefix_span,
format!("consider removing the `{}`", remove.trim()),
@ -1438,6 +1438,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
(prefix_span, format!("{}{}", prefix, "*".repeat(steps)))
};
if suggestion.trim().is_empty() {
return None;
}
return Some((
span,

View File

@ -0,0 +1,10 @@
struct S<'a>(&'a str);
fn f(inner: fn(&str, &S)) {
}
#[allow(unreachable_code)]
fn main() {
let inner: fn(_, _) = unimplemented!();
f(inner); //~ ERROR mismatched types
}

View File

@ -0,0 +1,19 @@
error[E0308]: mismatched types
--> $DIR/closure-with-wrong-borrows.rs:9:7
|
LL | f(inner);
| - ^^^^^ one type is more general than the other
| |
| arguments to this function are incorrect
|
= note: expected fn pointer `for<'a, 'b, 'c> fn(&'a str, &'b S<'c>)`
found fn pointer `fn(_, _)`
note: function defined here
--> $DIR/closure-with-wrong-borrows.rs:3:4
|
LL | fn f(inner: fn(&str, &S)) {
| ^ -------------------
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.