From c13a913e5b4136ecb81ec835586e596ecef1a4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 24 Jun 2017 19:28:43 -0700 Subject: [PATCH] Don't naively point to return type on type error --- src/librustc_typeck/check/coercion.rs | 6 ----- src/librustc_typeck/check/mod.rs | 22 ------------------- src/test/ui/block-result/issue-13624.stderr | 2 -- src/test/ui/block-result/issue-20862.stderr | 5 +---- src/test/ui/block-result/issue-22645.stderr | 3 --- src/test/ui/block-result/issue-3563.stderr | 5 +---- src/test/ui/block-result/issue-5500.stderr | 2 -- .../unexpected-return-on-unit.stderr | 2 -- src/test/ui/impl-trait/equality.stderr | 3 --- src/test/ui/mismatched_types/abridged.stderr | 12 ---------- .../ui/mismatched_types/issue-19109.stderr | 5 +---- .../ui/resolve/token-error-correct-3.stderr | 3 --- 12 files changed, 3 insertions(+), 67 deletions(-) diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 660f6c5a093f..4b5d02f99955 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -1174,12 +1174,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> expected, found, cause.span, blk_id); } - ObligationCauseCode::ReturnType(ret_id) => { - db = fcx.report_mismatched_types(cause, expected, found, err); - if let Some((fn_decl, _)) = fcx.get_fn_decl(ret_id) { - fcx.point_to_type_requirement(&mut db, &fn_decl, expected); - } - } _ => { db = fcx.report_mismatched_types(cause, expected, found, err); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 50e2e390d020..7c4b6a858d95 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4261,7 +4261,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.suggest_missing_semicolon(err, expression, expected, cause_span); if let Some((fn_decl, is_main)) = self.get_fn_decl(blk_id) { - self.point_to_type_requirement(err, &fn_decl, expected); // `fn main()` must return `()`, do not suggest changing return type if !is_main { self.suggest_missing_return_type(err, &fn_decl, found); @@ -4269,27 +4268,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - pub fn point_to_type_requirement(&self, - err: &mut DiagnosticBuilder<'tcx>, - fn_decl: &hir::FnDecl, - ty: Ty<'tcx>) { - let msg = if let &hir::FnDecl { - output: hir::FunctionRetTy::DefaultReturn(_), .. - } = fn_decl { - "default " - } else { - "" - }; - let ty = self.resolve_type_vars_if_possible(&ty); - if ty.to_string().len() < 10 { - err.span_label(fn_decl.output.span(), - format!("expected `{}` because of this {}return type", ty, msg)); - } else { - err.span_label(fn_decl.output.span(), - format!("expected because of this {}return type", msg)); - } - } - /// A common error is to forget to add a semicolon at the end of a block: /// /// ``` diff --git a/src/test/ui/block-result/issue-13624.stderr b/src/test/ui/block-result/issue-13624.stderr index 69c6e647cfc2..72ff859d7e93 100644 --- a/src/test/ui/block-result/issue-13624.stderr +++ b/src/test/ui/block-result/issue-13624.stderr @@ -1,8 +1,6 @@ error[E0308]: mismatched types --> $DIR/issue-13624.rs:17:5 | -16 | pub fn get_enum_struct_variant() -> () { - | -- expected `()` because of this return type 17 | Enum::EnumStructVariant { x: 1, y: 2, z: 3 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `a::Enum` | diff --git a/src/test/ui/block-result/issue-20862.stderr b/src/test/ui/block-result/issue-20862.stderr index 57cee8f7aca4..e4367f170ce1 100644 --- a/src/test/ui/block-result/issue-20862.stderr +++ b/src/test/ui/block-result/issue-20862.stderr @@ -2,10 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-20862.rs:12:5 | 11 | fn foo(x: i32) { - | - - | | - | possibly return type missing here? - | expected `()` because of this default return type + | - possibly return type missing here? 12 | |y| x + y | ^^^^^^^^^ expected (), found closure | diff --git a/src/test/ui/block-result/issue-22645.stderr b/src/test/ui/block-result/issue-22645.stderr index 93da3c6a4893..3921a301c922 100644 --- a/src/test/ui/block-result/issue-22645.stderr +++ b/src/test/ui/block-result/issue-22645.stderr @@ -11,9 +11,6 @@ error[E0277]: the trait bound `{integer}: Scalar` is not satisfied error[E0308]: mismatched types --> $DIR/issue-22645.rs:25:3 | -23 | fn main() { - | - expected `()` because of this default return type -24 | let b = Bob + 3.5; 25 | b + 3 //~ ERROR E0277 | ^^^^^ expected (), found struct `Bob` | diff --git a/src/test/ui/block-result/issue-3563.stderr b/src/test/ui/block-result/issue-3563.stderr index d995dee3827b..c6ab4cbb2a7c 100644 --- a/src/test/ui/block-result/issue-3563.stderr +++ b/src/test/ui/block-result/issue-3563.stderr @@ -8,10 +8,7 @@ error[E0308]: mismatched types --> $DIR/issue-3563.rs:13:9 | 12 | fn a(&self) { - | - - | | - | possibly return type missing here? - | expected `()` because of this default return type + | - possibly return type missing here? 13 | || self.b() | ^^^^^^^^^^^ expected (), found closure | diff --git a/src/test/ui/block-result/issue-5500.stderr b/src/test/ui/block-result/issue-5500.stderr index 6fda2aa00ffb..bffe2a82ca8d 100644 --- a/src/test/ui/block-result/issue-5500.stderr +++ b/src/test/ui/block-result/issue-5500.stderr @@ -1,8 +1,6 @@ error[E0308]: mismatched types --> $DIR/issue-5500.rs:12:5 | -11 | fn main() { - | - expected `()` because of this default return type 12 | &panic!() | ^^^^^^^^^ expected (), found reference | diff --git a/src/test/ui/block-result/unexpected-return-on-unit.stderr b/src/test/ui/block-result/unexpected-return-on-unit.stderr index e5481ffd3166..18d0cc481405 100644 --- a/src/test/ui/block-result/unexpected-return-on-unit.stderr +++ b/src/test/ui/block-result/unexpected-return-on-unit.stderr @@ -1,8 +1,6 @@ error[E0308]: mismatched types --> $DIR/unexpected-return-on-unit.rs:19:5 | -18 | fn bar() { - | - expected `()` because of this default return type 19 | foo() | ^^^^^ expected (), found usize | diff --git a/src/test/ui/impl-trait/equality.stderr b/src/test/ui/impl-trait/equality.stderr index ca37596f1b96..2206234b7774 100644 --- a/src/test/ui/impl-trait/equality.stderr +++ b/src/test/ui/impl-trait/equality.stderr @@ -1,9 +1,6 @@ error[E0308]: mismatched types --> $DIR/equality.rs:25:5 | -21 | fn two(x: bool) -> impl Foo { - | -------- expected `i32` because of this return type -... 25 | 0_u32 | ^^^^^ expected i32, found u32 | diff --git a/src/test/ui/mismatched_types/abridged.stderr b/src/test/ui/mismatched_types/abridged.stderr index 6282541ba0e4..78b5dcda1d9d 100644 --- a/src/test/ui/mismatched_types/abridged.stderr +++ b/src/test/ui/mismatched_types/abridged.stderr @@ -1,8 +1,6 @@ error[E0308]: mismatched types --> $DIR/abridged.rs:26:5 | -25 | fn a() -> Foo { - | --- expected `Foo` because of this return type 26 | Some(Foo { bar: 1 }) | ^^^^^^^^^^^^^^^^^^^^ expected struct `Foo`, found enum `std::option::Option` | @@ -12,8 +10,6 @@ error[E0308]: mismatched types error[E0308]: mismatched types --> $DIR/abridged.rs:30:5 | -29 | fn a2() -> Foo { - | --- expected `Foo` because of this return type 30 | Ok(Foo { bar: 1}) | ^^^^^^^^^^^^^^^^^ expected struct `Foo`, found enum `std::result::Result` | @@ -23,8 +19,6 @@ error[E0308]: mismatched types error[E0308]: mismatched types --> $DIR/abridged.rs:34:5 | -33 | fn b() -> Option { - | ----------- expected because of this return type 34 | Foo { bar: 1 } | ^^^^^^^^^^^^^^ expected enum `std::option::Option`, found struct `Foo` | @@ -34,8 +28,6 @@ error[E0308]: mismatched types error[E0308]: mismatched types --> $DIR/abridged.rs:38:5 | -37 | fn c() -> Result { - | ---------------- expected because of this return type 38 | Foo { bar: 1 } | ^^^^^^^^^^^^^^ expected enum `std::result::Result`, found struct `Foo` | @@ -45,8 +37,6 @@ error[E0308]: mismatched types error[E0308]: mismatched types --> $DIR/abridged.rs:42:5 | -41 | fn d() -> X, String> { - | ---------------------------- expected because of this return type 42 | / X { 43 | | x: X { 44 | | x: "".to_string(), @@ -62,8 +52,6 @@ error[E0308]: mismatched types error[E0308]: mismatched types --> $DIR/abridged.rs:52:5 | -51 | fn e() -> X, String> { - | ---------------------------- expected because of this return type 52 | / X { 53 | | x: X { 54 | | x: "".to_string(), diff --git a/src/test/ui/mismatched_types/issue-19109.stderr b/src/test/ui/mismatched_types/issue-19109.stderr index 5efa3fa6a1d5..083c1f953330 100644 --- a/src/test/ui/mismatched_types/issue-19109.stderr +++ b/src/test/ui/mismatched_types/issue-19109.stderr @@ -2,10 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-19109.rs:14:5 | 13 | fn function(t: &mut Trait) { - | - - | | - | help: possibly return type missing here? `-> *mut Trait ` - | expected `()` because of this default return type + | - help: possibly return type missing here? `-> *mut Trait ` 14 | t as *mut Trait | ^^^^^^^^^^^^^^^ expected (), found *-ptr | diff --git a/src/test/ui/resolve/token-error-correct-3.stderr b/src/test/ui/resolve/token-error-correct-3.stderr index 2a50428dbb9f..53e9cb217789 100644 --- a/src/test/ui/resolve/token-error-correct-3.stderr +++ b/src/test/ui/resolve/token-error-correct-3.stderr @@ -34,9 +34,6 @@ error[E0425]: cannot find function `is_directory` in this scope error[E0308]: mismatched types --> $DIR/token-error-correct-3.rs:25:13 | -20 | -> io::Result { - | ---------------- expected `()` because of this return type -... 25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: did you mean to add a semicolon here? `;` | |