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`.
This commit is contained in:
Esteban Küber 2017-06-24 12:16:20 -07:00
parent ecde91a69d
commit 27d4b314c5
4 changed files with 21 additions and 5 deletions

View File

@ -481,6 +481,18 @@ impl<'tcx> TyS<'tcx> {
_ => false,
}
}
pub fn is_suggestable(&self) -> bool {
match self.sty {
TypeVariants::TyAnon(..) |
TypeVariants::TyFnDef(..) |
TypeVariants::TyFnPtr(..) |
TypeVariants::TyDynamic(..) |
TypeVariants::TyClosure(..) |
TypeVariants::TyProjection(..) => false,
_ => true,
}
}
}
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ty::TyS<'tcx> {

View File

@ -4349,9 +4349,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let &hir::FnDecl {
output: hir::FunctionRetTy::DefaultReturn(span), ..
} = fn_decl {
err.span_suggestion(span,
"possibly return type missing here?",
format!("-> {} ", ty));
if ty.is_suggestable() {
err.span_suggestion(span,
"possibly return type missing here?",
format!("-> {} ", ty));
} else {
err.span_label(span, "possibly return type missing here?");
}
}
}

View File

@ -4,7 +4,7 @@ error[E0308]: mismatched types
11 | fn foo(x: i32) {
| -
| |
| help: possibly return type missing here? `-> [closure@$DIR/issue-20862.rs:12:5: 12:14 x:_] `
| possibly return type missing here?
| expected `()` because of this default return type
12 | |y| x + y
| ^^^^^^^^^ expected (), found closure

View File

@ -10,7 +10,7 @@ error[E0308]: mismatched types
12 | fn a(&self) {
| -
| |
| help: possibly return type missing here? `-> [closure@$DIR/issue-3563.rs:13:9: 13:20 self:_] `
| possibly return type missing here?
| expected `()` because of this default return type
13 | || self.b()
| ^^^^^^^^^^^ expected (), found closure