Skip to content

Commit c47bb6d

Browse files
committed
On FnDef type annotation suggestion, use fn-pointer output
Partly addresses rust-lang#71209.
1 parent 52fa23a commit c47bb6d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/librustc_infer/infer/error_reporting/need_type_info.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
247247
None
248248
};
249249
printer.name_resolver = Some(Box::new(&getter));
250-
let _ = ty.print(printer);
250+
let _ = if let ty::FnDef(..) = ty.kind {
251+
// We don't want the regular output for `fn`s because it inscludes its path in
252+
// invalid pseduo-syntax, we want the `fn`-pointer output instead.
253+
ty.fn_sig(self.tcx).print(printer)
254+
} else {
255+
ty.print(printer)
256+
};
251257
s
252258
};
253259

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn f<A>() -> A { unimplemented!() }
2+
fn foo() {
3+
let _ = f; //~ ERROR type annotations needed for `fn() -> A`
4+
}
5+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed for `fn() -> A`
2+
--> $DIR/fn-needing-specified-return-type-param.rs:3:13
3+
|
4+
LL | let _ = f;
5+
| - ^ cannot infer type for type parameter `A` declared on the function `f`
6+
| |
7+
| consider giving this pattern the explicit type `fn() -> A`, where the type parameter `A` is specified
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)