From 27d4b314c5b663a8382a33bd69cb8b27134fb3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 24 Jun 2017 12:16:20 -0700 Subject: [PATCH] Do not specify return type in suggestion for some `Ty`s Don't specify a suggested return type for `TyAnon`, `TyFnDef`, `TyFnPtr`, `TyDynamic`, `TyClosure` and `TyProjection`. --- src/librustc/ty/mod.rs | 12 ++++++++++++ src/librustc_typeck/check/mod.rs | 10 +++++++--- src/test/ui/block-result/issue-20862.stderr | 2 +- src/test/ui/block-result/issue-3563.stderr | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 13e46a265c69..65dd11bbc625 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> for ty::TyS<'tcx> { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0467f24948e7..50e2e390d020 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 0d88a44d6b9b..57cee8f7aca4 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 e9ace85c1d91..d995dee3827b 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