Skip to content

Commit 27d4b31

Browse files
committed
Do not specify return type in suggestion for some Tys
Don't specify a suggested return type for `TyAnon`, `TyFnDef`, `TyFnPtr`, `TyDynamic`, `TyClosure` and `TyProjection`.
1 parent ecde91a commit 27d4b31

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

src/librustc/ty/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,18 @@ impl<'tcx> TyS<'tcx> {
481481
_ => false,
482482
}
483483
}
484+
485+
pub fn is_suggestable(&self) -> bool {
486+
match self.sty {
487+
TypeVariants::TyAnon(..) |
488+
TypeVariants::TyFnDef(..) |
489+
TypeVariants::TyFnPtr(..) |
490+
TypeVariants::TyDynamic(..) |
491+
TypeVariants::TyClosure(..) |
492+
TypeVariants::TyProjection(..) => false,
493+
_ => true,
494+
}
495+
}
484496
}
485497

486498
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::TyS<'tcx> {

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,9 +4349,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
43494349
if let &hir::FnDecl {
43504350
output: hir::FunctionRetTy::DefaultReturn(span), ..
43514351
} = fn_decl {
4352-
err.span_suggestion(span,
4353-
"possibly return type missing here?",
4354-
format!("-> {} ", ty));
4352+
if ty.is_suggestable() {
4353+
err.span_suggestion(span,
4354+
"possibly return type missing here?",
4355+
format!("-> {} ", ty));
4356+
} else {
4357+
err.span_label(span, "possibly return type missing here?");
4358+
}
43554359
}
43564360
}
43574361

src/test/ui/block-result/issue-20862.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
44
11 | fn foo(x: i32) {
55
| -
66
| |
7-
| help: possibly return type missing here? `-> [closure@$DIR/issue-20862.rs:12:5: 12:14 x:_] `
7+
| possibly return type missing here?
88
| expected `()` because of this default return type
99
12 | |y| x + y
1010
| ^^^^^^^^^ expected (), found closure

src/test/ui/block-result/issue-3563.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0308]: mismatched types
1010
12 | fn a(&self) {
1111
| -
1212
| |
13-
| help: possibly return type missing here? `-> [closure@$DIR/issue-3563.rs:13:9: 13:20 self:_] `
13+
| possibly return type missing here?
1414
| expected `()` because of this default return type
1515
13 | || self.b()
1616
| ^^^^^^^^^^^ expected (), found closure

0 commit comments

Comments
 (0)