Skip to content

Commit d9c1f5c

Browse files
authored
Rollup merge of #71311 - estebank:fn-type-param, r=varkor
On `FnDef` type annotation suggestion, use fn-pointer output Address the last point in #71209.
2 parents fb5615a + 432ab34 commit d9c1f5c

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
257257
None
258258
};
259259
printer.name_resolver = Some(Box::new(&getter));
260-
let _ = ty.print(printer);
260+
let _ = if let ty::FnDef(..) = ty.kind {
261+
// We don't want the regular output for `fn`s because it includes its path in
262+
// invalid pseduo-syntax, we want the `fn`-pointer output instead.
263+
ty.fn_sig(self.tcx).print(printer)
264+
} else {
265+
ty.print(printer)
266+
};
261267
s
262268
};
263269

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() {}
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)