Skip to content

Commit 789ebdc

Browse files
author
Yuki Okushi
authored
Rollup merge of #106581 - estebank:bad-suggestion, r=compiler-errors
Do not emit wrong E0308 suggestion for closure mismatch Found in #76353.
2 parents 6459a51 + ebbc5da commit 789ebdc

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13791379
}
13801380
}
13811381
// If we've reached our target type with just removing `&`, then just print now.
1382-
if steps == 0 {
1382+
if steps == 0 && !remove.trim().is_empty() {
13831383
return Some((
13841384
prefix_span,
13851385
format!("consider removing the `{}`", remove.trim()),
@@ -1438,6 +1438,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14381438
} else {
14391439
(prefix_span, format!("{}{}", prefix, "*".repeat(steps)))
14401440
};
1441+
if suggestion.trim().is_empty() {
1442+
return None;
1443+
}
14411444

14421445
return Some((
14431446
span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct S<'a>(&'a str);
2+
3+
fn f(inner: fn(&str, &S)) {
4+
}
5+
6+
#[allow(unreachable_code)]
7+
fn main() {
8+
let inner: fn(_, _) = unimplemented!();
9+
f(inner); //~ ERROR mismatched types
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/closure-with-wrong-borrows.rs:9:7
3+
|
4+
LL | f(inner);
5+
| - ^^^^^ one type is more general than the other
6+
| |
7+
| arguments to this function are incorrect
8+
|
9+
= note: expected fn pointer `for<'a, 'b, 'c> fn(&'a str, &'b S<'c>)`
10+
found fn pointer `fn(_, _)`
11+
note: function defined here
12+
--> $DIR/closure-with-wrong-borrows.rs:3:4
13+
|
14+
LL | fn f(inner: fn(&str, &S)) {
15+
| ^ -------------------
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)