Skip to content

Commit

Permalink
Do not specify return type in suggestion for some Tys
Browse files Browse the repository at this point in the history
Don't specify a suggested return type for `TyAnon`, `TyFnDef`,
`TyFnPtr`, `TyDynamic`, `TyClosure` and `TyProjection`.
  • Loading branch information
estebank committed Jun 24, 2017
1 parent ecde91a commit 27d4b31
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/librustc/ty/mod.rs
Expand Up @@ -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> {
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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?");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/block-result/issue-20862.stderr
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/block-result/issue-3563.stderr
Expand Up @@ -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
Expand Down

0 comments on commit 27d4b31

Please sign in to comment.