about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/ty/mod.rs12
-rw-r--r--src/librustc_typeck/check/mod.rs10
-rw-r--r--src/test/ui/block-result/issue-20862.stderr2
-rw-r--r--src/test/ui/block-result/issue-3563.stderr2
4 files changed, 21 insertions, 5 deletions
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 13e46a265c6..65dd11bbc62 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -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> {
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 0467f24948e..50e2e390d02 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -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?");
+            }
         }
     }
 
diff --git a/src/test/ui/block-result/issue-20862.stderr b/src/test/ui/block-result/issue-20862.stderr
index 0d88a44d6b9..57cee8f7aca 100644
--- a/src/test/ui/block-result/issue-20862.stderr
+++ b/src/test/ui/block-result/issue-20862.stderr
@@ -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
diff --git a/src/test/ui/block-result/issue-3563.stderr b/src/test/ui/block-result/issue-3563.stderr
index e9ace85c1d9..d995dee3827 100644
--- a/src/test/ui/block-result/issue-3563.stderr
+++ b/src/test/ui/block-result/issue-3563.stderr
@@ -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