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:
commit
789ebdca47
@ -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,
|
||||
|
10
src/test/ui/type/closure-with-wrong-borrows.rs
Normal file
10
src/test/ui/type/closure-with-wrong-borrows.rs
Normal 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
|
||||
}
|
19
src/test/ui/type/closure-with-wrong-borrows.stderr
Normal file
19
src/test/ui/type/closure-with-wrong-borrows.stderr
Normal 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`.
|
Loading…
x
Reference in New Issue
Block a user