From c076392143e483f60429d148ac58522e423eea9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 6 Aug 2019 14:20:39 -0700 Subject: [PATCH 01/14] Tweak mismatched types error on break expressions --- src/librustc_typeck/check/expr.rs | 16 ++++++++++- src/test/ui/issues/issue-27042.stderr | 9 ++++--- src/test/ui/loops/loop-break-value.stderr | 18 ++++++++----- .../ui/loops/loop-labeled-break-value.stderr | 27 ++++++++++++------- .../ui/loops/loop-properly-diverging-2.stderr | 9 ++++--- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index d825358beaade..c567741be3980 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -548,7 +548,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { coerce.coerce(self, &cause, e, e_ty); } else { assert!(e_ty.is_unit()); - coerce.coerce_forced_unit(self, &cause, &mut |_| (), true); + let ty = coerce.expected_ty(); + coerce.coerce_forced_unit(self, &cause, &mut |err| { + let msg = "give it a value of the expected type"; + let label = destination.label + .map(|l| format!(" {}", l.ident)) + .unwrap_or_else(String::new); + let sugg = format!("break{} {}", label, match ty.sty { + ty::Bool => "true", + ty::Char => "'a'", + ty::Int(_) | ty::Uint(_) => "42", + ty::Float(_) => "3.14159", + _ => "value", + }); + err.span_suggestion(expr.span, msg, sugg, Applicability::HasPlaceholders); + }, false); } } else { // If `ctxt.coerce` is `None`, we can just ignore diff --git a/src/test/ui/issues/issue-27042.stderr b/src/test/ui/issues/issue-27042.stderr index 4beb752854b9c..7678984a518ba 100644 --- a/src/test/ui/issues/issue-27042.stderr +++ b/src/test/ui/issues/issue-27042.stderr @@ -12,10 +12,13 @@ error[E0308]: mismatched types --> $DIR/issue-27042.rs:6:16 | LL | loop { break }; - | ^^^^^ expected (), found i32 + | ^^^^^ + | | + | expected i32, found () + | help: give it a value of the expected type: `break 42` | - = note: expected type `()` - found type `i32` + = note: expected type `i32` + found type `()` error[E0308]: mismatched types --> $DIR/issue-27042.rs:8:9 diff --git a/src/test/ui/loops/loop-break-value.stderr b/src/test/ui/loops/loop-break-value.stderr index 1e167905ec8d7..7310790b880c2 100644 --- a/src/test/ui/loops/loop-break-value.stderr +++ b/src/test/ui/loops/loop-break-value.stderr @@ -90,10 +90,13 @@ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:4:31 | LL | let val: ! = loop { break break; }; - | ^^^^^ expected (), found ! + | ^^^^^ + | | + | expected !, found () + | help: give it a value of the expected type: `break value` | - = note: expected type `()` - found type `!` + = note: expected type `!` + found type `()` error[E0308]: mismatched types --> $DIR/loop-break-value.rs:11:19 @@ -153,10 +156,13 @@ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:90:9 | LL | break; - | ^^^^^ expected (), found integer + | ^^^^^ + | | + | expected integer, found () + | help: give it a value of the expected type: `break value` | - = note: expected type `()` - found type `{integer}` + = note: expected type `{integer}` + found type `()` error: aborting due to 16 previous errors diff --git a/src/test/ui/loops/loop-labeled-break-value.stderr b/src/test/ui/loops/loop-labeled-break-value.stderr index ad7cb4b0c2e5f..8b9468cacc1f9 100644 --- a/src/test/ui/loops/loop-labeled-break-value.stderr +++ b/src/test/ui/loops/loop-labeled-break-value.stderr @@ -2,28 +2,37 @@ error[E0308]: mismatched types --> $DIR/loop-labeled-break-value.rs:3:29 | LL | let _: i32 = loop { break }; - | ^^^^^ expected (), found i32 + | ^^^^^ + | | + | expected i32, found () + | help: give it a value of the expected type: `break 42` | - = note: expected type `()` - found type `i32` + = note: expected type `i32` + found type `()` error[E0308]: mismatched types --> $DIR/loop-labeled-break-value.rs:6:37 | LL | let _: i32 = 'inner: loop { break 'inner }; - | ^^^^^^^^^^^^ expected (), found i32 + | ^^^^^^^^^^^^ + | | + | expected i32, found () + | help: give it a value of the expected type: `break 'inner 42` | - = note: expected type `()` - found type `i32` + = note: expected type `i32` + found type `()` error[E0308]: mismatched types --> $DIR/loop-labeled-break-value.rs:9:45 | LL | let _: i32 = 'inner2: loop { loop { break 'inner2 } }; - | ^^^^^^^^^^^^^ expected (), found i32 + | ^^^^^^^^^^^^^ + | | + | expected i32, found () + | help: give it a value of the expected type: `break 'inner2 42` | - = note: expected type `()` - found type `i32` + = note: expected type `i32` + found type `()` error: aborting due to 3 previous errors diff --git a/src/test/ui/loops/loop-properly-diverging-2.stderr b/src/test/ui/loops/loop-properly-diverging-2.stderr index 6293fdb058a0f..3758bbf9f6f31 100644 --- a/src/test/ui/loops/loop-properly-diverging-2.stderr +++ b/src/test/ui/loops/loop-properly-diverging-2.stderr @@ -2,10 +2,13 @@ error[E0308]: mismatched types --> $DIR/loop-properly-diverging-2.rs:2:23 | LL | let x: i32 = loop { break }; - | ^^^^^ expected (), found i32 + | ^^^^^ + | | + | expected i32, found () + | help: give it a value of the expected type: `break 42` | - = note: expected type `()` - found type `i32` + = note: expected type `i32` + found type `()` error: aborting due to previous error From 799b13ada59d0663e98a02744d21d2c3b08501ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 6 Aug 2019 17:24:39 -0700 Subject: [PATCH 02/14] Do not suggest using ! with break --- src/librustc_typeck/check/expr.rs | 1 + src/test/ui/loops/loop-break-value.stderr | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index c567741be3980..5c859b9fd3254 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -559,6 +559,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Char => "'a'", ty::Int(_) | ty::Uint(_) => "42", ty::Float(_) => "3.14159", + ty::Error | ty::Never => return, _ => "value", }); err.span_suggestion(expr.span, msg, sugg, Applicability::HasPlaceholders); diff --git a/src/test/ui/loops/loop-break-value.stderr b/src/test/ui/loops/loop-break-value.stderr index 7310790b880c2..fef5b5873068f 100644 --- a/src/test/ui/loops/loop-break-value.stderr +++ b/src/test/ui/loops/loop-break-value.stderr @@ -90,10 +90,7 @@ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:4:31 | LL | let val: ! = loop { break break; }; - | ^^^^^ - | | - | expected !, found () - | help: give it a value of the expected type: `break value` + | ^^^^^ expected !, found () | = note: expected type `!` found type `()` From 4fbbf99c509042e89572f8575c875889874edb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 6 Aug 2019 22:20:42 -0700 Subject: [PATCH 03/14] Be more accurate when mentioning type of found match arms --- src/librustc/infer/error_reporting/mod.rs | 38 +++++-------------- .../ui/match/match-arm-resolving-to-never.rs | 19 ++++++++++ .../match/match-arm-resolving-to-never.stderr | 22 +++++++++++ 3 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 src/test/ui/match/match-arm-resolving-to-never.rs create mode 100644 src/test/ui/match/match-arm-resolving-to-never.stderr diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 8d0ead5c8fe90..2ffcd2c4ace7b 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -662,19 +662,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } _ => { + // `last_ty` can be `!`, `expected` will have better info when present. + let t = self.resolve_vars_if_possible(&match exp_found { + Some(ty::error::ExpectedFound { expected, .. }) => expected, + _ => last_ty, + }); let msg = "`match` arms have incompatible types"; err.span_label(cause.span, msg); if prior_arms.len() <= 4 { for sp in prior_arms { - err.span_label(*sp, format!( - "this is found to be of type `{}`", - self.resolve_vars_if_possible(&last_ty), - )); + err.span_label( *sp, format!("this is found to be of type `{}`", t)); } } else if let Some(sp) = prior_arms.last() { - err.span_label(*sp, format!( - "this and all prior arms are found to be of type `{}`", last_ty, - )); + err.span_label( + *sp, + format!("this and all prior arms are found to be of type `{}`", t), + ); } } }, @@ -1143,27 +1146,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } (_, false, _) => { if let Some(exp_found) = exp_found { - let (def_id, ret_ty) = match exp_found.found.sty { - ty::FnDef(def, _) => { - (Some(def), Some(self.tcx.fn_sig(def).output())) - } - _ => (None, None), - }; - - let exp_is_struct = match exp_found.expected.sty { - ty::Adt(def, _) => def.is_struct(), - _ => false, - }; - - if let (Some(def_id), Some(ret_ty)) = (def_id, ret_ty) { - if exp_is_struct && &exp_found.expected == ret_ty.skip_binder() { - let message = format!( - "did you mean `{}(/* fields */)`?", - self.tcx.def_path_str(def_id) - ); - diag.span_label(span, message); - } - } self.suggest_as_ref_where_appropriate(span, &exp_found, diag); } diff --git a/src/test/ui/match/match-arm-resolving-to-never.rs b/src/test/ui/match/match-arm-resolving-to-never.rs new file mode 100644 index 0000000000000..8f54023305e83 --- /dev/null +++ b/src/test/ui/match/match-arm-resolving-to-never.rs @@ -0,0 +1,19 @@ +enum E { + A, + B, + C, + D, + E, + F, +} + +fn main() { + match E::F { + E::A => 1, + E::B => 2, + E::C => 3, + E::D => 4, + E::E => unimplemented!(""), + E::F => "", //~ ERROR match arms have incompatible types + }; +} diff --git a/src/test/ui/match/match-arm-resolving-to-never.stderr b/src/test/ui/match/match-arm-resolving-to-never.stderr new file mode 100644 index 0000000000000..24ce97f86e760 --- /dev/null +++ b/src/test/ui/match/match-arm-resolving-to-never.stderr @@ -0,0 +1,22 @@ +error[E0308]: match arms have incompatible types + --> $DIR/match-arm-resolving-to-never.rs:17:17 + | +LL | / match E::F { +LL | | E::A => 1, +LL | | E::B => 2, +LL | | E::C => 3, +LL | | E::D => 4, +LL | | E::E => unimplemented!(""), + | | ------------------ this and all prior arms are found to be of type `{integer}` +LL | | E::F => "", + | | ^^ expected integer, found reference +LL | | }; + | |_____- `match` arms have incompatible types + | + = note: expected type `{integer}` + found type `&'static str` + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 01a61394f8d69c1720fcdf77eaac635600ff87e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 6 Aug 2019 22:22:04 -0700 Subject: [PATCH 04/14] Change wording for function without return value Fix #62677 --- src/librustc_typeck/check/mod.rs | 2 +- .../ui/block-result/consider-removing-last-semi.stderr | 4 ++-- src/test/ui/block-result/issue-11714.stderr | 2 +- src/test/ui/block-result/issue-13428.stderr | 4 ++-- .../coercion/coercion-missing-tail-expected-type.stderr | 4 ++-- src/test/ui/issues/issue-32323.stderr | 2 +- src/test/ui/issues/issue-43162.stderr | 2 +- src/test/ui/issues/issue-44023.stderr | 2 +- src/test/ui/issues/issue-6458-4.stderr | 2 +- src/test/ui/liveness/liveness-forgot-ret.stderr | 2 +- src/test/ui/liveness/liveness-missing-ret2.stderr | 2 +- .../ui/liveness/liveness-return-last-stmt-semi.stderr | 8 ++++---- src/test/ui/missing/missing-return.stderr | 2 +- src/test/ui/parser/issue-62881.stderr | 2 +- src/test/ui/parser/issue-62895.stderr | 2 +- 15 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 08033b46b8004..da9b02fcf513a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3709,7 +3709,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.consider_hint_about_removing_semicolon(blk, expected_ty, err); } if let Some(fn_span) = fn_span { - err.span_label(fn_span, "this function's body doesn't return"); + err.span_label(fn_span, "this function's body doesn't return a value"); } }, false); } diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr index 618d020ce08b5..7f8bb67c946e6 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.stderr +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | 0u8; LL | "bla".to_string(); | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn g() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | "this won't work".to_string(); LL | "removeme".to_string(); | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-11714.stderr b/src/test/ui/block-result/issue-11714.stderr index d73489a602df4..569e012540c4f 100644 --- a/src/test/ui/block-result/issue-11714.stderr +++ b/src/test/ui/block-result/issue-11714.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn blah() -> i32 { | ---- ^^^ expected i32, found () | | - | this function's body doesn't return + | this function's body doesn't return a value ... LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr index 18adb15c9615d..ca48910026d9a 100644 --- a/src/test/ui/block-result/issue-13428.stderr +++ b/src/test/ui/block-result/issue-13428.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return + | this function's body doesn't return a value ... LL | ; | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn bar() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | "foobar".to_string() LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr index 057de5b625e87..a7ac930ba670e 100644 --- a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr +++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn plus_one(x: i32) -> i32 { | -------- ^^^ expected i32, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | x + 1; | - help: consider removing this semicolon | @@ -17,7 +17,7 @@ error[E0308]: mismatched types LL | fn foo() -> Result { | --- ^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | Ok(1); | - help: consider removing this semicolon | diff --git a/src/test/ui/issues/issue-32323.stderr b/src/test/ui/issues/issue-32323.stderr index 0339fdc55b9c8..6b8bca078b5e6 100644 --- a/src/test/ui/issues/issue-32323.stderr +++ b/src/test/ui/issues/issue-32323.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | pub fn f<'a, T: Tr<'a>>() -> >::Out {} | - ^^^^^^^^^^^^^^^^^^ expected associated type, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `>::Out` found type `()` diff --git a/src/test/ui/issues/issue-43162.stderr b/src/test/ui/issues/issue-43162.stderr index cd11959ede6cb..fd62ac30ab195 100644 --- a/src/test/ui/issues/issue-43162.stderr +++ b/src/test/ui/issues/issue-43162.stderr @@ -16,7 +16,7 @@ error[E0308]: mismatched types LL | fn foo() -> bool { | --- ^^^^ expected bool, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | LL | break true; | - help: consider removing this semicolon diff --git a/src/test/ui/issues/issue-44023.stderr b/src/test/ui/issues/issue-44023.stderr index 153be363c1dea..cad202129a719 100644 --- a/src/test/ui/issues/issue-44023.stderr +++ b/src/test/ui/issues/issue-44023.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn საჭმელად_გემრიელი_სადილი ( ) -> isize { | ------------------------ ^^^^^ expected isize, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/issues/issue-6458-4.stderr b/src/test/ui/issues/issue-6458-4.stderr index 90b493e1634c4..d4f5b2ba41f69 100644 --- a/src/test/ui/issues/issue-6458-4.stderr +++ b/src/test/ui/issues/issue-6458-4.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo(b: bool) -> Result { | --- ^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | Err("bar".to_string()); | - help: consider removing this semicolon | diff --git a/src/test/ui/liveness/liveness-forgot-ret.stderr b/src/test/ui/liveness/liveness-forgot-ret.stderr index a970b80fdbbd9..6d917393663b0 100644 --- a/src/test/ui/liveness/liveness-forgot-ret.stderr +++ b/src/test/ui/liveness/liveness-forgot-ret.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f(a: isize) -> isize { if god_exists(a) { return 5; }; } | - ^^^^^ expected isize, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-missing-ret2.stderr b/src/test/ui/liveness/liveness-missing-ret2.stderr index ab7d411880bba..a71b9296702b7 100644 --- a/src/test/ui/liveness/liveness-missing-ret2.stderr +++ b/src/test/ui/liveness/liveness-missing-ret2.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { | - ^^^^^ expected isize, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr index a5d9734c069ec..3a08699170643 100644 --- a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr +++ b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr @@ -5,7 +5,7 @@ LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } } | --- ^^^ - help: consider removing this semicolon | | | | | expected i32, found () - | this function's body doesn't return + | this function's body doesn't return a value ... LL | test!(); | -------- in this macro invocation @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn no_return() -> i32 {} | --------- ^^^ expected i32, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `i32` found type `()` @@ -30,7 +30,7 @@ error[E0308]: mismatched types LL | fn bar(x: u32) -> u32 { | --- ^^^ expected u32, found () | | - | this function's body doesn't return + | this function's body doesn't return a value LL | x * 2; | - help: consider removing this semicolon | @@ -43,7 +43,7 @@ error[E0308]: mismatched types LL | fn baz(x: u64) -> u32 { | --- ^^^ expected u32, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `u32` found type `()` diff --git a/src/test/ui/missing/missing-return.stderr b/src/test/ui/missing/missing-return.stderr index 42466e2fc6574..c7d7116a9cd7c 100644 --- a/src/test/ui/missing/missing-return.stderr +++ b/src/test/ui/missing/missing-return.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { } | - ^^^^^ expected isize, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62881.stderr b/src/test/ui/parser/issue-62881.stderr index 85c3575fd9288..b2e2da35a2700 100644 --- a/src/test/ui/parser/issue-62881.stderr +++ b/src/test/ui/parser/issue-62881.stderr @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { fn f() -> isize {} pub f< | - ^^^^^ expected isize, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62895.stderr b/src/test/ui/parser/issue-62895.stderr index 7def7b562ca59..6c3a8fb766c0a 100644 --- a/src/test/ui/parser/issue-62895.stderr +++ b/src/test/ui/parser/issue-62895.stderr @@ -38,7 +38,7 @@ error[E0308]: mismatched types LL | fn v() -> isize { | - ^^^^^ expected isize, found () | | - | this function's body doesn't return + | this function's body doesn't return a value | = note: expected type `isize` found type `()` From 94fe8a3c1761acadd5043b24ad821b0b369922ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 6 Aug 2019 22:29:10 -0700 Subject: [PATCH 05/14] Suggest calling function on type error when finding bare fn --- src/librustc_typeck/check/mod.rs | 43 ++++++++++++++++++++ src/test/ui/issues/issue-35241.stderr | 5 ++- src/test/ui/resolve/privacy-enum-ctor.stderr | 24 +++++++++-- src/test/ui/substs-ppaux.normal.stderr | 32 +++++++++++++-- src/test/ui/substs-ppaux.verbose.stderr | 32 +++++++++++++-- 5 files changed, 124 insertions(+), 12 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index da9b02fcf513a..6600f83393857 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3819,6 +3819,41 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pointing_at_return_type } + fn suggest_fn_call( + &self, + err: &mut DiagnosticBuilder<'tcx>, + expr: &hir::Expr, + expected: Ty<'tcx>, + found: Ty<'tcx>, + ) -> bool { + if let ty::FnDef(..) | ty::FnPtr(_) = &found.sty { + let sig = found.fn_sig(self.tcx); + let sig = self + .replace_bound_vars_with_fresh_vars(expr.span, infer::FnCall, &sig) + .0; + let sig = self.normalize_associated_types_in(expr.span, &sig); + if let Ok(_) = self.try_coerce(expr, sig.output(), expected, AllowTwoPhase::No) { + if let Ok(code) = self.sess().source_map().span_to_snippet(expr.span) { + err.span_suggestion(expr.span, "use parentheses to call this function", format!( + "{}({})", + code, + if sig.inputs().len() > 0 { + "..." + } else { + "" + }), if sig.inputs().len() > 0 { + Applicability::MachineApplicable + } else { + Applicability::HasPlaceholders + } + ); + return true; + } + } + } + false + } + pub fn suggest_ref_or_into( &self, err: &mut DiagnosticBuilder<'tcx>, @@ -3833,6 +3868,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { suggestion, Applicability::MachineApplicable, ); + } else if let (ty::FnDef(def_id, ..), true) = ( + &found.sty, + self.suggest_fn_call(err, expr, expected, found), + ) { + if let Some(sp) = self.tcx.hir().span_if_local(*def_id) { + let sp = self.sess().source_map().def_span(sp); + err.span_label(sp, &format!("{} defined here", found)); + } } else if !self.check_for_cast(err, expr, found, expected) { let is_struct_pat_shorthand_field = self.is_hir_id_from_struct_pattern_shorthand_field( expr.hir_id, diff --git a/src/test/ui/issues/issue-35241.stderr b/src/test/ui/issues/issue-35241.stderr index 8fda58abadb6e..248e6f0f46b19 100644 --- a/src/test/ui/issues/issue-35241.stderr +++ b/src/test/ui/issues/issue-35241.stderr @@ -1,11 +1,14 @@ error[E0308]: mismatched types --> $DIR/issue-35241.rs:3:20 | +LL | struct Foo(u32); + | ---------------- fn(u32) -> Foo {Foo} defined here +LL | LL | fn test() -> Foo { Foo } | --- ^^^ | | | | | expected struct `Foo`, found fn item - | | did you mean `Foo(/* fields */)`? + | | help: use parentheses to call this function: `Foo(...)` | expected `Foo` because of return type | = note: expected type `Foo` diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index a1a8714ab3f38..07cbffb009406 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -195,8 +195,14 @@ LL | let _: Z = m::n::Z::Unit {}; error[E0308]: mismatched types --> $DIR/privacy-enum-ctor.rs:27:20 | +LL | Fn(u8), + | ------ fn(u8) -> m::n::Z {m::n::Z::Fn} defined here +... LL | let _: Z = Z::Fn; - | ^^^^^ expected enum `m::n::Z`, found fn item + | ^^^^^ + | | + | expected enum `m::n::Z`, found fn item + | help: use parentheses to call this function: `Z::Fn(...)` | = note: expected type `m::n::Z` found type `fn(u8) -> m::n::Z {m::n::Z::Fn}` @@ -219,8 +225,14 @@ LL | let _ = Z::Unit; error[E0308]: mismatched types --> $DIR/privacy-enum-ctor.rs:43:16 | +LL | Fn(u8), + | ------ fn(u8) -> m::E {m::E::Fn} defined here +... LL | let _: E = m::E::Fn; - | ^^^^^^^^ expected enum `m::E`, found fn item + | ^^^^^^^^ + | | + | expected enum `m::E`, found fn item + | help: use parentheses to call this function: `m::E::Fn(...)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` @@ -243,8 +255,14 @@ LL | let _: E = m::E::Unit; error[E0308]: mismatched types --> $DIR/privacy-enum-ctor.rs:51:16 | +LL | Fn(u8), + | ------ fn(u8) -> m::E {m::E::Fn} defined here +... LL | let _: E = E::Fn; - | ^^^^^ expected enum `m::E`, found fn item + | ^^^^^ + | | + | expected enum `m::E`, found fn item + | help: use parentheses to call this function: `E::Fn(...)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` diff --git a/src/test/ui/substs-ppaux.normal.stderr b/src/test/ui/substs-ppaux.normal.stderr index 123dd86b90549..b3b879ef9acbe 100644 --- a/src/test/ui/substs-ppaux.normal.stderr +++ b/src/test/ui/substs-ppaux.normal.stderr @@ -1,8 +1,14 @@ error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:16:17 | +LL | fn bar<'a, T>() where T: 'a {} + | --------------------------- fn() {>::bar::<'static, char>} defined here +... LL | let x: () = >::bar::<'static, char>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `>::bar::<'static, char>()` | = note: expected type `()` found type `fn() {>::bar::<'static, char>}` @@ -10,8 +16,14 @@ LL | let x: () = >::bar::<'static, char>; error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:25:17 | +LL | fn bar<'a, T>() where T: 'a {} + | --------------------------- fn() {>::bar::<'static, char>} defined here +... LL | let x: () = >::bar::<'static, char>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `>::bar::<'static, char>()` | = note: expected type `()` found type `fn() {>::bar::<'static, char>}` @@ -19,8 +31,14 @@ LL | let x: () = >::bar::<'static, char>; error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:33:17 | +LL | fn baz() {} + | -------- fn() {>::baz} defined here +... LL | let x: () = >::baz; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `>::baz()` | = note: expected type `()` found type `fn() {>::baz}` @@ -28,8 +46,14 @@ LL | let x: () = >::baz; error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:41:17 | +LL | fn foo<'z>() where &'z (): Sized { + | -------------------------------- fn() {foo::<'static>} defined here +... LL | let x: () = foo::<'static>; - | ^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `foo::<'static>()` | = note: expected type `()` found type `fn() {foo::<'static>}` diff --git a/src/test/ui/substs-ppaux.verbose.stderr b/src/test/ui/substs-ppaux.verbose.stderr index 9167346282bab..363018db232d8 100644 --- a/src/test/ui/substs-ppaux.verbose.stderr +++ b/src/test/ui/substs-ppaux.verbose.stderr @@ -1,8 +1,14 @@ error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:16:17 | +LL | fn bar<'a, T>() where T: 'a {} + | --------------------------- fn() {>::bar::} defined here +... LL | let x: () = >::bar::<'static, char>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `>::bar::<'static, char>()` | = note: expected type `()` found type `fn() {>::bar::}` @@ -10,8 +16,14 @@ LL | let x: () = >::bar::<'static, char>; error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:25:17 | +LL | fn bar<'a, T>() where T: 'a {} + | --------------------------- fn() {>::bar::} defined here +... LL | let x: () = >::bar::<'static, char>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `>::bar::<'static, char>()` | = note: expected type `()` found type `fn() {>::bar::}` @@ -19,8 +31,14 @@ LL | let x: () = >::bar::<'static, char>; error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:33:17 | +LL | fn baz() {} + | -------- fn() {>::baz} defined here +... LL | let x: () = >::baz; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `>::baz()` | = note: expected type `()` found type `fn() {>::baz}` @@ -28,8 +46,14 @@ LL | let x: () = >::baz; error[E0308]: mismatched types --> $DIR/substs-ppaux.rs:41:17 | +LL | fn foo<'z>() where &'z (): Sized { + | -------------------------------- fn() {foo::} defined here +... LL | let x: () = foo::<'static>; - | ^^^^^^^^^^^^^^ expected (), found fn item + | ^^^^^^^^^^^^^^ + | | + | expected (), found fn item + | help: use parentheses to call this function: `foo::<'static>()` | = note: expected type `()` found type `fn() {foo::}` From 195d837f18e2efb7d621d6568212a59c29fc184e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 12:01:22 -0700 Subject: [PATCH 06/14] When suggesting fn call use an appropriate number of placeholder arguments --- src/librustc_typeck/check/mod.rs | 43 ++++++--- src/test/ui/issues/issue-35241.stderr | 2 +- src/test/ui/resolve/privacy-enum-ctor.stderr | 6 +- .../fn-or-tuple-struct-without-args.rs | 20 ++++ .../fn-or-tuple-struct-without-args.stderr | 93 +++++++++++++++++++ 5 files changed, 148 insertions(+), 16 deletions(-) create mode 100644 src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs create mode 100644 src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6600f83393857..130cc8f3a6050 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3833,19 +3833,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .0; let sig = self.normalize_associated_types_in(expr.span, &sig); if let Ok(_) = self.try_coerce(expr, sig.output(), expected, AllowTwoPhase::No) { - if let Ok(code) = self.sess().source_map().span_to_snippet(expr.span) { - err.span_suggestion(expr.span, "use parentheses to call this function", format!( - "{}({})", - code, - if sig.inputs().len() > 0 { - "..." - } else { - "" - }), if sig.inputs().len() > 0 { - Applicability::MachineApplicable - } else { - Applicability::HasPlaceholders + let (mut sugg_call, applicability) = if sig.inputs().is_empty() { + (String::new(), Applicability::MachineApplicable) + } else { + ("...".to_owned(), Applicability::HasPlaceholders) + }; + let mut msg = "call this function"; + if let ty::FnDef(def_id, ..) = found.sty { + match self.tcx.hir().get_if_local(def_id) { + Some(Node::Item(hir::Item { + node: ItemKind::Fn(.., body_id), + .. + })) => { + let body = self.tcx.hir().body(*body_id); + sugg_call = body.arguments.iter() + .map(|arg| hir::print::to_string( + hir::print::NO_ANN, + |s| s.print_pat(&arg.pat), + )).collect::>().join(", "); + } + Some(Node::Ctor(hir::VariantData::Tuple(field, _))) => { + sugg_call = field.iter().map(|_| "_").collect::>().join(", "); + msg = "instatiate this tuple struct"; } + _ => {} + } + }; + if let Ok(code) = self.sess().source_map().span_to_snippet(expr.span) { + err.span_suggestion( + expr.span, + &format!("use parentheses to {}", msg), + format!("{}({})", code, sugg_call), + applicability, ); return true; } diff --git a/src/test/ui/issues/issue-35241.stderr b/src/test/ui/issues/issue-35241.stderr index 248e6f0f46b19..8befc6873857e 100644 --- a/src/test/ui/issues/issue-35241.stderr +++ b/src/test/ui/issues/issue-35241.stderr @@ -8,7 +8,7 @@ LL | fn test() -> Foo { Foo } | --- ^^^ | | | | | expected struct `Foo`, found fn item - | | help: use parentheses to call this function: `Foo(...)` + | | help: use parentheses to instatiate this tuple struct: `Foo(_)` | expected `Foo` because of return type | = note: expected type `Foo` diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index 07cbffb009406..49092562feeba 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -202,7 +202,7 @@ LL | let _: Z = Z::Fn; | ^^^^^ | | | expected enum `m::n::Z`, found fn item - | help: use parentheses to call this function: `Z::Fn(...)` + | help: use parentheses to instatiate this tuple struct: `Z::Fn(_)` | = note: expected type `m::n::Z` found type `fn(u8) -> m::n::Z {m::n::Z::Fn}` @@ -232,7 +232,7 @@ LL | let _: E = m::E::Fn; | ^^^^^^^^ | | | expected enum `m::E`, found fn item - | help: use parentheses to call this function: `m::E::Fn(...)` + | help: use parentheses to instatiate this tuple struct: `m::E::Fn(_)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` @@ -262,7 +262,7 @@ LL | let _: E = E::Fn; | ^^^^^ | | | expected enum `m::E`, found fn item - | help: use parentheses to call this function: `E::Fn(...)` + | help: use parentheses to instatiate this tuple struct: `E::Fn(_)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs new file mode 100644 index 0000000000000..6758c1d5f238e --- /dev/null +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs @@ -0,0 +1,20 @@ +fn foo(a: usize, b: usize) -> usize { a } + +fn bar() -> usize { 42 } + +struct S(usize, usize); +struct V(); + +trait T { + fn baz(x: usize, y: usize) -> usize { x } + fn bat() -> usize { 42 } +} + +fn main() { + let _: usize = foo; //~ ERROR mismatched types + let _: S = S; //~ ERROR mismatched types + let _: usize = bar; //~ ERROR mismatched types + let _: V = V; //~ ERROR mismatched types + let _: usize = T::baz; //~ ERROR mismatched types + let _: usize = T::bat; //~ ERROR mismatched types +} diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr new file mode 100644 index 0000000000000..524c779979e3b --- /dev/null +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -0,0 +1,93 @@ +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:14:20 + | +LL | fn foo(a: usize, b: usize) -> usize { a } + | ----------------------------------- fn(usize, usize) -> usize {foo} defined here +... +LL | let _: usize = foo; + | ^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `foo(a, b)` + | + = note: expected type `usize` + found type `fn(usize, usize) -> usize {foo}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:15:16 + | +LL | struct S(usize, usize); + | ----------------------- fn(usize, usize) -> S {S} defined here +... +LL | let _: S = S; + | ^ + | | + | expected struct `S`, found fn item + | help: use parentheses to instatiate this tuple struct: `S(_, _)` + | + = note: expected type `S` + found type `fn(usize, usize) -> S {S}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:16:20 + | +LL | fn bar() -> usize { 42 } + | ----------------- fn() -> usize {bar} defined here +... +LL | let _: usize = bar; + | ^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `bar()` + | + = note: expected type `usize` + found type `fn() -> usize {bar}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:17:16 + | +LL | struct V(); + | ----------- fn() -> V {V} defined here +... +LL | let _: V = V; + | ^ + | | + | expected struct `V`, found fn item + | help: use parentheses to instatiate this tuple struct: `V()` + | + = note: expected type `V` + found type `fn() -> V {V}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:18:20 + | +LL | fn baz(x: usize, y: usize) -> usize { x } + | ----------------------------------- fn(usize, usize) -> usize {<_ as T>::baz} defined here +... +LL | let _: usize = T::baz; + | ^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `T::baz(...)` + | + = note: expected type `usize` + found type `fn(usize, usize) -> usize {<_ as T>::baz}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:19:20 + | +LL | fn bat() -> usize { 42 } + | ----------------- fn() -> usize {<_ as T>::bat} defined here +... +LL | let _: usize = T::bat; + | ^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `T::bat()` + | + = note: expected type `usize` + found type `fn() -> usize {<_ as T>::bat}` + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. From b7f7756566c9e10983ee51bc97afe9852838299a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 12:31:24 -0700 Subject: [PATCH 07/14] Recover parser from `foo(_, _)` --- src/libsyntax/parse/parser.rs | 70 +++++++++++++------ src/test/ui/issues/issue-34334.rs | 1 + src/test/ui/issues/issue-34334.stderr | 10 ++- ...fn-or-tuple-struct-with-underscore-args.rs | 19 +++++ ...r-tuple-struct-with-underscore-args.stderr | 38 ++++++++++ 5 files changed, 116 insertions(+), 22 deletions(-) create mode 100644 src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.rs create mode 100644 src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.stderr diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d85c2df16a350..30e16592113b6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2052,9 +2052,23 @@ impl<'a> Parser<'a> { while self.token != token::CloseDelim(token::Paren) { es.push(match self.parse_expr() { Ok(es) => es, - Err(err) => { + Err(mut err) => { // recover from parse error in tuple list - return Ok(self.recover_seq_parse_error(token::Paren, lo, Err(err))); + match self.token.kind { + token::Ident(name, false) + if name == kw::Underscore && self.look_ahead(1, |t| { + t == &token::Comma + }) => { + // Special-case handling of `Foo<(_, _, _)>` + err.emit(); + let sp = self.token.span; + self.bump(); + self.mk_expr(sp, ExprKind::Err, ThinVec::new()) + } + _ => return Ok( + self.recover_seq_parse_error(token::Paren, lo, Err(err)), + ), + } } }); recovered = self.expect_one_of( @@ -2456,9 +2470,10 @@ impl<'a> Parser<'a> { } /// Parses `a.b` or `a(13)` or `a[4]` or just `a`. - fn parse_dot_or_call_expr(&mut self, - already_parsed_attrs: Option>) - -> PResult<'a, P> { + fn parse_dot_or_call_expr( + &mut self, + already_parsed_attrs: Option>, + ) -> PResult<'a, P> { let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?; let b = self.parse_bottom_expr(); @@ -2466,16 +2481,16 @@ impl<'a> Parser<'a> { self.parse_dot_or_call_expr_with(b, span, attrs) } - fn parse_dot_or_call_expr_with(&mut self, - e0: P, - lo: Span, - mut attrs: ThinVec) - -> PResult<'a, P> { + fn parse_dot_or_call_expr_with( + &mut self, + e0: P, + lo: Span, + mut attrs: ThinVec, + ) -> PResult<'a, P> { // Stitch the list of outer attributes onto the return value. // A little bit ugly, but the best way given the current code // structure - self.parse_dot_or_call_expr_with_(e0, lo) - .map(|expr| + self.parse_dot_or_call_expr_with_(e0, lo).map(|expr| expr.map(|mut expr| { attrs.extend::>(expr.attrs.into()); expr.attrs = attrs; @@ -2483,10 +2498,7 @@ impl<'a> Parser<'a> { ExprKind::If(..) if !expr.attrs.is_empty() => { // Just point to the first attribute in there... let span = expr.attrs[0].span; - - self.span_err(span, - "attributes are not yet allowed on `if` \ - expressions"); + self.span_err(span, "attributes are not yet allowed on `if` expressions"); } _ => {} } @@ -2624,7 +2636,24 @@ impl<'a> Parser<'a> { } fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec>> { - self.parse_paren_comma_seq(|p| p.parse_expr()).map(|(r, _)| r) + self.parse_paren_comma_seq(|p| { + match p.parse_expr() { + Ok(expr) => Ok(expr), + Err(mut err) => match p.token.kind { + token::Ident(name, false) + if name == kw::Underscore && p.look_ahead(1, |t| { + t == &token::Comma + }) => { + // Special-case handling of `foo(_, _, _)` + err.emit(); + let sp = p.token.span; + p.bump(); + Ok(p.mk_expr(sp, ExprKind::Err, ThinVec::new())) + } + _ => Err(err), + }, + } + }).map(|(r, _)| r) } crate fn process_potential_macro_variable(&mut self) { @@ -2806,9 +2835,10 @@ impl<'a> Parser<'a> { /// This parses an expression accounting for associativity and precedence of the operators in /// the expression. #[inline] - fn parse_assoc_expr(&mut self, - already_parsed_attrs: Option>) - -> PResult<'a, P> { + fn parse_assoc_expr( + &mut self, + already_parsed_attrs: Option>, + ) -> PResult<'a, P> { self.parse_assoc_expr_with(0, already_parsed_attrs.into()) } diff --git a/src/test/ui/issues/issue-34334.rs b/src/test/ui/issues/issue-34334.rs index 928d217441ef2..4457d71cbb4a7 100644 --- a/src/test/ui/issues/issue-34334.rs +++ b/src/test/ui/issues/issue-34334.rs @@ -5,6 +5,7 @@ fn main () { //~| ERROR mismatched types //~| ERROR invalid left-hand side expression //~| ERROR expected expression, found reserved identifier `_` + //~| ERROR expected expression, found reserved identifier `_` let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); //~^ ERROR no method named `iter` found for type `()` in the current scope } diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index e8386fd8de9e5..7f89caf92abe1 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -4,6 +4,12 @@ error: expected expression, found reserved identifier `_` LL | let sr: Vec<(u32, _, _) = vec![]; | ^ expected expression +error: expected expression, found reserved identifier `_` + --> $DIR/issue-34334.rs:2:26 + | +LL | let sr: Vec<(u32, _, _) = vec![]; + | ^ expected expression + error: expected one of `,` or `>`, found `=` --> $DIR/issue-34334.rs:2:29 | @@ -36,12 +42,12 @@ LL | let sr: Vec<(u32, _, _) = vec![]; | ^^^^^^^^^^^^^^^^^^^^^^^^ left-hand of expression not valid error[E0599]: no method named `iter` found for type `()` in the current scope - --> $DIR/issue-34334.rs:8:36 + --> $DIR/issue-34334.rs:9:36 | LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); | ^^^^ -error: aborting due to 6 previous errors +error: aborting due to 7 previous errors Some errors have detailed explanations: E0070, E0308, E0423, E0599. For more information about an error, try `rustc --explain E0070`. diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.rs b/src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.rs new file mode 100644 index 0000000000000..a8ea3faefe876 --- /dev/null +++ b/src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.rs @@ -0,0 +1,19 @@ +fn foo(a: usize, b: usize) -> usize { a } + +struct S(usize, usize); + +trait T { + fn baz(x: usize, y: usize) -> usize { x } +} + +fn main() { + let _: usize = foo(_, _); + //~^ ERROR expected expression + //~| ERROR expected expression + let _: S = S(_, _); + //~^ ERROR expected expression + //~| ERROR expected expression + let _: usize = T::baz(_, _); + //~^ ERROR expected expression + //~| ERROR expected expression +} diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.stderr new file mode 100644 index 0000000000000..a6d1c4b859f2f --- /dev/null +++ b/src/test/ui/suggestions/fn-or-tuple-struct-with-underscore-args.stderr @@ -0,0 +1,38 @@ +error: expected expression, found reserved identifier `_` + --> $DIR/fn-or-tuple-struct-with-underscore-args.rs:10:24 + | +LL | let _: usize = foo(_, _); + | ^ expected expression + +error: expected expression, found reserved identifier `_` + --> $DIR/fn-or-tuple-struct-with-underscore-args.rs:10:27 + | +LL | let _: usize = foo(_, _); + | ^ expected expression + +error: expected expression, found reserved identifier `_` + --> $DIR/fn-or-tuple-struct-with-underscore-args.rs:13:18 + | +LL | let _: S = S(_, _); + | ^ expected expression + +error: expected expression, found reserved identifier `_` + --> $DIR/fn-or-tuple-struct-with-underscore-args.rs:13:21 + | +LL | let _: S = S(_, _); + | ^ expected expression + +error: expected expression, found reserved identifier `_` + --> $DIR/fn-or-tuple-struct-with-underscore-args.rs:16:27 + | +LL | let _: usize = T::baz(_, _); + | ^ expected expression + +error: expected expression, found reserved identifier `_` + --> $DIR/fn-or-tuple-struct-with-underscore-args.rs:16:30 + | +LL | let _: usize = T::baz(_, _); + | ^ expected expression + +error: aborting due to 6 previous errors + From 0d53f699eaa7d1fec1e6013a6a42b39992c119d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 12:32:18 -0700 Subject: [PATCH 08/14] review comments --- src/librustc_typeck/check/expr.rs | 13 ++--- src/librustc_typeck/check/mod.rs | 89 +++++++++++++++++-------------- 2 files changed, 56 insertions(+), 46 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 5c859b9fd3254..9680f61d69903 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -550,18 +550,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { assert!(e_ty.is_unit()); let ty = coerce.expected_ty(); coerce.coerce_forced_unit(self, &cause, &mut |err| { - let msg = "give it a value of the expected type"; - let label = destination.label - .map(|l| format!(" {}", l.ident)) - .unwrap_or_else(String::new); - let sugg = format!("break{} {}", label, match ty.sty { + let val = match ty.sty { ty::Bool => "true", ty::Char => "'a'", ty::Int(_) | ty::Uint(_) => "42", ty::Float(_) => "3.14159", ty::Error | ty::Never => return, _ => "value", - }); + }; + let msg = "give it a value of the expected type"; + let label = destination.label + .map(|l| format!(" {}", l.ident)) + .unwrap_or_else(String::new); + let sugg = format!("break{} {}", label, val); err.span_suggestion(expr.span, msg, sugg, Applicability::HasPlaceholders); }, false); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 130cc8f3a6050..be2af2db66d59 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3819,6 +3819,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pointing_at_return_type } + /// When encountering an fn-like ctor that needs to unify with a value, check whether calling + /// the ctor would successfully solve the type mismatch and if so, suggest it: + /// ``` + /// fn foo(x: usize) -> usize { x } + /// let x: usize = foo; // suggest calling the `foo` function: `foo(42)` + /// ``` fn suggest_fn_call( &self, err: &mut DiagnosticBuilder<'tcx>, @@ -3826,48 +3832,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, found: Ty<'tcx>, ) -> bool { - if let ty::FnDef(..) | ty::FnPtr(_) = &found.sty { - let sig = found.fn_sig(self.tcx); - let sig = self - .replace_bound_vars_with_fresh_vars(expr.span, infer::FnCall, &sig) - .0; - let sig = self.normalize_associated_types_in(expr.span, &sig); - if let Ok(_) = self.try_coerce(expr, sig.output(), expected, AllowTwoPhase::No) { - let (mut sugg_call, applicability) = if sig.inputs().is_empty() { - (String::new(), Applicability::MachineApplicable) - } else { - ("...".to_owned(), Applicability::HasPlaceholders) - }; - let mut msg = "call this function"; - if let ty::FnDef(def_id, ..) = found.sty { - match self.tcx.hir().get_if_local(def_id) { - Some(Node::Item(hir::Item { - node: ItemKind::Fn(.., body_id), - .. - })) => { - let body = self.tcx.hir().body(*body_id); - sugg_call = body.arguments.iter() - .map(|arg| hir::print::to_string( - hir::print::NO_ANN, - |s| s.print_pat(&arg.pat), - )).collect::>().join(", "); - } - Some(Node::Ctor(hir::VariantData::Tuple(field, _))) => { - sugg_call = field.iter().map(|_| "_").collect::>().join(", "); - msg = "instatiate this tuple struct"; - } - _ => {} + match found.sty { + ty::FnDef(..) | ty::FnPtr(_) => {} + _ => return false, + } + + let sig = found.fn_sig(self.tcx); + let sig = self + .replace_bound_vars_with_fresh_vars(expr.span, infer::FnCall, &sig) + .0; + let sig = self.normalize_associated_types_in(expr.span, &sig); + if let Ok(_) = self.try_coerce(expr, sig.output(), expected, AllowTwoPhase::No) { + let (mut sugg_call, applicability) = if sig.inputs().is_empty() { + (String::new(), Applicability::MachineApplicable) + } else { + ("...".to_owned(), Applicability::HasPlaceholders) + }; + let mut msg = "call this function"; + if let ty::FnDef(def_id, ..) = found.sty { + match self.tcx.hir().get_if_local(def_id) { + Some(Node::Item(hir::Item { + node: ItemKind::Fn(.., body_id), + .. + })) => { + let body = self.tcx.hir().body(*body_id); + sugg_call = body.arguments.iter() + .map(|arg| hir::print::to_string( + hir::print::NO_ANN, + |s| s.print_pat(&arg.pat), + )).collect::>().join(", "); } - }; - if let Ok(code) = self.sess().source_map().span_to_snippet(expr.span) { - err.span_suggestion( - expr.span, - &format!("use parentheses to {}", msg), - format!("{}({})", code, sugg_call), - applicability, - ); - return true; + Some(Node::Ctor(hir::VariantData::Tuple(field, _))) => { + sugg_call = field.iter().map(|_| "_").collect::>().join(", "); + msg = "instatiate this tuple struct"; + } + _ => {} } + }; + if let Ok(code) = self.sess().source_map().span_to_snippet(expr.span) { + err.span_suggestion( + expr.span, + &format!("use parentheses to {}", msg), + format!("{}({})", code, sugg_call), + applicability, + ); + return true; } } false From efa62d66e36306fba6025528aee381dd165fa8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 14:53:00 -0700 Subject: [PATCH 09/14] Tweak wording of fn without explicit return --- src/librustc_typeck/check/mod.rs | 5 ++++- .../ui/block-result/consider-removing-last-semi.stderr | 4 ++-- src/test/ui/block-result/issue-11714.stderr | 2 +- src/test/ui/block-result/issue-13428.stderr | 4 ++-- .../coercion/coercion-missing-tail-expected-type.stderr | 4 ++-- src/test/ui/issues/issue-32323.stderr | 2 +- src/test/ui/issues/issue-43162.stderr | 2 +- src/test/ui/issues/issue-44023.stderr | 2 +- src/test/ui/issues/issue-6458-4.stderr | 2 +- src/test/ui/liveness/liveness-forgot-ret.stderr | 2 +- src/test/ui/liveness/liveness-missing-ret2.stderr | 2 +- .../ui/liveness/liveness-return-last-stmt-semi.stderr | 8 ++++---- src/test/ui/missing/missing-return.stderr | 2 +- src/test/ui/parser/issue-62881.stderr | 2 +- src/test/ui/parser/issue-62895.stderr | 2 +- 15 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index be2af2db66d59..726922c8e5346 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3709,7 +3709,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.consider_hint_about_removing_semicolon(blk, expected_ty, err); } if let Some(fn_span) = fn_span { - err.span_label(fn_span, "this function's body doesn't return a value"); + err.span_label( + fn_span, + "this function's body doesn't `return` a value", + ); } }, false); } diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr index 7f8bb67c946e6..f3dfc8b12eafe 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.stderr +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | 0u8; LL | "bla".to_string(); | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn g() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | "this won't work".to_string(); LL | "removeme".to_string(); | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-11714.stderr b/src/test/ui/block-result/issue-11714.stderr index 569e012540c4f..021a25ece2f4d 100644 --- a/src/test/ui/block-result/issue-11714.stderr +++ b/src/test/ui/block-result/issue-11714.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn blah() -> i32 { | ---- ^^^ expected i32, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value ... LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr index ca48910026d9a..8fa6ae9c528b4 100644 --- a/src/test/ui/block-result/issue-13428.stderr +++ b/src/test/ui/block-result/issue-13428.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value ... LL | ; | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn bar() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | "foobar".to_string() LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr index a7ac930ba670e..6ecb1d3eaef4a 100644 --- a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr +++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn plus_one(x: i32) -> i32 { | -------- ^^^ expected i32, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | x + 1; | - help: consider removing this semicolon | @@ -17,7 +17,7 @@ error[E0308]: mismatched types LL | fn foo() -> Result { | --- ^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | Ok(1); | - help: consider removing this semicolon | diff --git a/src/test/ui/issues/issue-32323.stderr b/src/test/ui/issues/issue-32323.stderr index 6b8bca078b5e6..376676bda7dbf 100644 --- a/src/test/ui/issues/issue-32323.stderr +++ b/src/test/ui/issues/issue-32323.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | pub fn f<'a, T: Tr<'a>>() -> >::Out {} | - ^^^^^^^^^^^^^^^^^^ expected associated type, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `>::Out` found type `()` diff --git a/src/test/ui/issues/issue-43162.stderr b/src/test/ui/issues/issue-43162.stderr index fd62ac30ab195..22d347778c8f4 100644 --- a/src/test/ui/issues/issue-43162.stderr +++ b/src/test/ui/issues/issue-43162.stderr @@ -16,7 +16,7 @@ error[E0308]: mismatched types LL | fn foo() -> bool { | --- ^^^^ expected bool, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | LL | break true; | - help: consider removing this semicolon diff --git a/src/test/ui/issues/issue-44023.stderr b/src/test/ui/issues/issue-44023.stderr index cad202129a719..7760af8145b07 100644 --- a/src/test/ui/issues/issue-44023.stderr +++ b/src/test/ui/issues/issue-44023.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn საჭმელად_გემრიელი_სადილი ( ) -> isize { | ------------------------ ^^^^^ expected isize, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/issues/issue-6458-4.stderr b/src/test/ui/issues/issue-6458-4.stderr index d4f5b2ba41f69..e29be76087416 100644 --- a/src/test/ui/issues/issue-6458-4.stderr +++ b/src/test/ui/issues/issue-6458-4.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo(b: bool) -> Result { | --- ^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | Err("bar".to_string()); | - help: consider removing this semicolon | diff --git a/src/test/ui/liveness/liveness-forgot-ret.stderr b/src/test/ui/liveness/liveness-forgot-ret.stderr index 6d917393663b0..68cbdb2cfdba6 100644 --- a/src/test/ui/liveness/liveness-forgot-ret.stderr +++ b/src/test/ui/liveness/liveness-forgot-ret.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f(a: isize) -> isize { if god_exists(a) { return 5; }; } | - ^^^^^ expected isize, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-missing-ret2.stderr b/src/test/ui/liveness/liveness-missing-ret2.stderr index a71b9296702b7..62e0aa5d29d95 100644 --- a/src/test/ui/liveness/liveness-missing-ret2.stderr +++ b/src/test/ui/liveness/liveness-missing-ret2.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { | - ^^^^^ expected isize, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr index 3a08699170643..c5018af74f347 100644 --- a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr +++ b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr @@ -5,7 +5,7 @@ LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } } | --- ^^^ - help: consider removing this semicolon | | | | | expected i32, found () - | this function's body doesn't return a value + | this function's body doesn't `return` a value ... LL | test!(); | -------- in this macro invocation @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn no_return() -> i32 {} | --------- ^^^ expected i32, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `i32` found type `()` @@ -30,7 +30,7 @@ error[E0308]: mismatched types LL | fn bar(x: u32) -> u32 { | --- ^^^ expected u32, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value LL | x * 2; | - help: consider removing this semicolon | @@ -43,7 +43,7 @@ error[E0308]: mismatched types LL | fn baz(x: u64) -> u32 { | --- ^^^ expected u32, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `u32` found type `()` diff --git a/src/test/ui/missing/missing-return.stderr b/src/test/ui/missing/missing-return.stderr index c7d7116a9cd7c..4cd516ba81d6a 100644 --- a/src/test/ui/missing/missing-return.stderr +++ b/src/test/ui/missing/missing-return.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { } | - ^^^^^ expected isize, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62881.stderr b/src/test/ui/parser/issue-62881.stderr index b2e2da35a2700..11b8836a89a76 100644 --- a/src/test/ui/parser/issue-62881.stderr +++ b/src/test/ui/parser/issue-62881.stderr @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { fn f() -> isize {} pub f< | - ^^^^^ expected isize, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62895.stderr b/src/test/ui/parser/issue-62895.stderr index 6c3a8fb766c0a..d9d3baf622708 100644 --- a/src/test/ui/parser/issue-62895.stderr +++ b/src/test/ui/parser/issue-62895.stderr @@ -38,7 +38,7 @@ error[E0308]: mismatched types LL | fn v() -> isize { | - ^^^^^ expected isize, found () | | - | this function's body doesn't return a value + | this function's body doesn't `return` a value | = note: expected type `isize` found type `()` From 52da091ee687f3d065713626a10b4cc961f04f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 14:59:24 -0700 Subject: [PATCH 10/14] Differentiate between tuple structs and tuple variants --- src/librustc/hir/map/mod.rs | 2 +- src/librustc_typeck/check/mod.rs | 29 ++++++++----- src/test/ui/resolve/privacy-enum-ctor.stderr | 6 +-- .../fn-or-tuple-struct-without-args.rs | 6 +++ .../fn-or-tuple-struct-without-args.stderr | 41 +++++++++++++++---- 5 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 0d477ae796822..b85738dd29a6d 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -287,7 +287,7 @@ impl<'hir> Map<'hir> { self.definitions.def_index_to_hir_id(def_id.to_def_id().index) } - fn def_kind(&self, hir_id: HirId) -> Option { + pub fn def_kind(&self, hir_id: HirId) -> Option { let node = if let Some(node) = self.find(hir_id) { node } else { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 726922c8e5346..629b8da355e23 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3839,6 +3839,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::FnDef(..) | ty::FnPtr(_) => {} _ => return false, } + let hir = self.tcx.hir(); let sig = found.fn_sig(self.tcx); let sig = self @@ -3849,25 +3850,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (mut sugg_call, applicability) = if sig.inputs().is_empty() { (String::new(), Applicability::MachineApplicable) } else { - ("...".to_owned(), Applicability::HasPlaceholders) + ("...".to_string(), Applicability::HasPlaceholders) }; let mut msg = "call this function"; if let ty::FnDef(def_id, ..) = found.sty { - match self.tcx.hir().get_if_local(def_id) { + match hir.get_if_local(def_id) { Some(Node::Item(hir::Item { node: ItemKind::Fn(.., body_id), .. })) => { - let body = self.tcx.hir().body(*body_id); + let body = hir.body(*body_id); sugg_call = body.arguments.iter() - .map(|arg| hir::print::to_string( - hir::print::NO_ANN, - |s| s.print_pat(&arg.pat), - )).collect::>().join(", "); + .map(|arg| match &arg.pat.node { + hir::PatKind::Binding(_, _, ident, None) => ident.to_string(), + _ => "_".to_string(), + }).collect::>().join(", "); } - Some(Node::Ctor(hir::VariantData::Tuple(field, _))) => { - sugg_call = field.iter().map(|_| "_").collect::>().join(", "); - msg = "instatiate this tuple struct"; + Some(Node::Ctor(hir::VariantData::Tuple(fields, _))) => { + sugg_call = fields.iter().map(|_| "_").collect::>().join(", "); + match hir.as_local_hir_id(def_id).and_then(|hir_id| hir.def_kind(hir_id)) { + Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, _)) => { + msg = "instatiate this tuple variant"; + } + Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Struct, _)) => { + msg = "instatiate this tuple struct"; + } + _ => {} + } } _ => {} } diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index 49092562feeba..3e924f7d161bd 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -202,7 +202,7 @@ LL | let _: Z = Z::Fn; | ^^^^^ | | | expected enum `m::n::Z`, found fn item - | help: use parentheses to instatiate this tuple struct: `Z::Fn(_)` + | help: use parentheses to instatiate this tuple variant: `Z::Fn(_)` | = note: expected type `m::n::Z` found type `fn(u8) -> m::n::Z {m::n::Z::Fn}` @@ -232,7 +232,7 @@ LL | let _: E = m::E::Fn; | ^^^^^^^^ | | | expected enum `m::E`, found fn item - | help: use parentheses to instatiate this tuple struct: `m::E::Fn(_)` + | help: use parentheses to instatiate this tuple variant: `m::E::Fn(_)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` @@ -262,7 +262,7 @@ LL | let _: E = E::Fn; | ^^^^^ | | | expected enum `m::E`, found fn item - | help: use parentheses to instatiate this tuple struct: `E::Fn(_)` + | help: use parentheses to instatiate this tuple variant: `E::Fn(_)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs index 6758c1d5f238e..838ef78e4fd6a 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs @@ -3,6 +3,10 @@ fn foo(a: usize, b: usize) -> usize { a } fn bar() -> usize { 42 } struct S(usize, usize); +enum E { + A(usize), + B { a: usize }, +} struct V(); trait T { @@ -17,4 +21,6 @@ fn main() { let _: V = V; //~ ERROR mismatched types let _: usize = T::baz; //~ ERROR mismatched types let _: usize = T::bat; //~ ERROR mismatched types + let _: E = E::A; //~ ERROR mismatched types + let _: E = E::B; //~ ERROR expected value, found struct variant `E::B` } diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr index 524c779979e3b..cb128822fcce8 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -1,5 +1,14 @@ +error[E0423]: expected value, found struct variant `E::B` + --> $DIR/fn-or-tuple-struct-without-args.rs:25:16 + | +LL | let _: E = E::B; + | ^^^- + | | | + | | help: a tuple variant with a similar name exists: `A` + | did you mean `E::B { /* fields */ }`? + error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:14:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:18:20 | LL | fn foo(a: usize, b: usize) -> usize { a } | ----------------------------------- fn(usize, usize) -> usize {foo} defined here @@ -14,7 +23,7 @@ LL | let _: usize = foo; found type `fn(usize, usize) -> usize {foo}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:15:16 + --> $DIR/fn-or-tuple-struct-without-args.rs:19:16 | LL | struct S(usize, usize); | ----------------------- fn(usize, usize) -> S {S} defined here @@ -29,7 +38,7 @@ LL | let _: S = S; found type `fn(usize, usize) -> S {S}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:16:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:20:20 | LL | fn bar() -> usize { 42 } | ----------------- fn() -> usize {bar} defined here @@ -44,7 +53,7 @@ LL | let _: usize = bar; found type `fn() -> usize {bar}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:17:16 + --> $DIR/fn-or-tuple-struct-without-args.rs:21:16 | LL | struct V(); | ----------- fn() -> V {V} defined here @@ -59,7 +68,7 @@ LL | let _: V = V; found type `fn() -> V {V}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:18:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:22:20 | LL | fn baz(x: usize, y: usize) -> usize { x } | ----------------------------------- fn(usize, usize) -> usize {<_ as T>::baz} defined here @@ -74,7 +83,7 @@ LL | let _: usize = T::baz; found type `fn(usize, usize) -> usize {<_ as T>::baz}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:19:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:23:20 | LL | fn bat() -> usize { 42 } | ----------------- fn() -> usize {<_ as T>::bat} defined here @@ -88,6 +97,22 @@ LL | let _: usize = T::bat; = note: expected type `usize` found type `fn() -> usize {<_ as T>::bat}` -error: aborting due to 6 previous errors +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:24:16 + | +LL | A(usize), + | -------- fn(usize) -> E {E::A} defined here +... +LL | let _: E = E::A; + | ^^^^ + | | + | expected enum `E`, found fn item + | help: use parentheses to instatiate this tuple variant: `E::A(_)` + | + = note: expected type `E` + found type `fn(usize) -> E {E::A}` + +error: aborting due to 8 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0308, E0423. +For more information about an error, try `rustc --explain E0308`. From 5a54945b6f637eadd4848874db39b49d2764839f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 15:53:32 -0700 Subject: [PATCH 11/14] Extend suggestion support for traits and foreign items --- src/librustc_typeck/check/mod.rs | 25 +++- .../fn-or-tuple-struct-without-args.rs | 21 ++- .../fn-or-tuple-struct-without-args.stderr | 132 ++++++++++++++++-- 3 files changed, 161 insertions(+), 17 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 629b8da355e23..d389563aea639 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3858,11 +3858,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(Node::Item(hir::Item { node: ItemKind::Fn(.., body_id), .. + })) | + Some(Node::ImplItem(hir::ImplItem { + node: hir::ImplItemKind::Method(_, body_id), + .. + })) | + Some(Node::TraitItem(hir::TraitItem { + node: hir::TraitItemKind::Method(.., hir::TraitMethod::Provided(body_id)), + .. })) => { let body = hir.body(*body_id); sugg_call = body.arguments.iter() .map(|arg| match &arg.pat.node { - hir::PatKind::Binding(_, _, ident, None) => ident.to_string(), + hir::PatKind::Binding(_, _, ident, None) + if ident.name != kw::SelfLower => ident.to_string(), _ => "_".to_string(), }).collect::>().join(", "); } @@ -3878,6 +3887,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => {} } } + Some(Node::ForeignItem(hir::ForeignItem { + node: hir::ForeignItemKind::Fn(_, idents, _), + .. + })) | + Some(Node::TraitItem(hir::TraitItem { + node: hir::TraitItemKind::Method(.., hir::TraitMethod::Required(idents)), + .. + })) => sugg_call = idents.iter() + .map(|ident| if ident.name != kw::SelfLower { + ident.to_string() + } else { + "_".to_string() + }).collect::>() + .join(", "), _ => {} } }; diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs index 838ef78e4fd6a..9b6b10748172b 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.rs @@ -11,7 +11,18 @@ struct V(); trait T { fn baz(x: usize, y: usize) -> usize { x } - fn bat() -> usize { 42 } + fn bat(x: usize) -> usize { 42 } + fn bax(x: usize) -> usize { 42 } + fn bach(x: usize) -> usize; + fn ban(&self) -> usize { 42 } + fn bal(&self) -> usize; +} + +struct X; + +impl T for X { + fn bach(x: usize) -> usize { 42 } + fn bal(&self) -> usize { 42 } } fn main() { @@ -23,4 +34,12 @@ fn main() { let _: usize = T::bat; //~ ERROR mismatched types let _: E = E::A; //~ ERROR mismatched types let _: E = E::B; //~ ERROR expected value, found struct variant `E::B` + let _: usize = X::baz; //~ ERROR mismatched types + let _: usize = X::bat; //~ ERROR mismatched types + let _: usize = X::bax; //~ ERROR mismatched types + let _: usize = X::bach; //~ ERROR mismatched types + let _: usize = X::ban; //~ ERROR mismatched types + let _: usize = X::bal; //~ ERROR mismatched types + let _: usize = X.ban; //~ ERROR attempted to take value of method + let _: usize = X.bal; //~ ERROR attempted to take value of method } diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr index cb128822fcce8..e3012144513fd 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -1,5 +1,5 @@ error[E0423]: expected value, found struct variant `E::B` - --> $DIR/fn-or-tuple-struct-without-args.rs:25:16 + --> $DIR/fn-or-tuple-struct-without-args.rs:36:16 | LL | let _: E = E::B; | ^^^- @@ -8,7 +8,7 @@ LL | let _: E = E::B; | did you mean `E::B { /* fields */ }`? error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:18:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:29:20 | LL | fn foo(a: usize, b: usize) -> usize { a } | ----------------------------------- fn(usize, usize) -> usize {foo} defined here @@ -23,7 +23,7 @@ LL | let _: usize = foo; found type `fn(usize, usize) -> usize {foo}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:19:16 + --> $DIR/fn-or-tuple-struct-without-args.rs:30:16 | LL | struct S(usize, usize); | ----------------------- fn(usize, usize) -> S {S} defined here @@ -38,7 +38,7 @@ LL | let _: S = S; found type `fn(usize, usize) -> S {S}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:20:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:31:20 | LL | fn bar() -> usize { 42 } | ----------------- fn() -> usize {bar} defined here @@ -53,7 +53,7 @@ LL | let _: usize = bar; found type `fn() -> usize {bar}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:21:16 + --> $DIR/fn-or-tuple-struct-without-args.rs:32:16 | LL | struct V(); | ----------- fn() -> V {V} defined here @@ -68,7 +68,7 @@ LL | let _: V = V; found type `fn() -> V {V}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:22:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:33:20 | LL | fn baz(x: usize, y: usize) -> usize { x } | ----------------------------------- fn(usize, usize) -> usize {<_ as T>::baz} defined here @@ -77,28 +77,28 @@ LL | let _: usize = T::baz; | ^^^^^^ | | | expected usize, found fn item - | help: use parentheses to call this function: `T::baz(...)` + | help: use parentheses to call this function: `T::baz(x, y)` | = note: expected type `usize` found type `fn(usize, usize) -> usize {<_ as T>::baz}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:23:20 + --> $DIR/fn-or-tuple-struct-without-args.rs:34:20 | -LL | fn bat() -> usize { 42 } - | ----------------- fn() -> usize {<_ as T>::bat} defined here +LL | fn bat(x: usize) -> usize { 42 } + | ------------------------- fn(usize) -> usize {<_ as T>::bat} defined here ... LL | let _: usize = T::bat; | ^^^^^^ | | | expected usize, found fn item - | help: use parentheses to call this function: `T::bat()` + | help: use parentheses to call this function: `T::bat(x)` | = note: expected type `usize` - found type `fn() -> usize {<_ as T>::bat}` + found type `fn(usize) -> usize {<_ as T>::bat}` error[E0308]: mismatched types - --> $DIR/fn-or-tuple-struct-without-args.rs:24:16 + --> $DIR/fn-or-tuple-struct-without-args.rs:35:16 | LL | A(usize), | -------- fn(usize) -> E {E::A} defined here @@ -112,7 +112,109 @@ LL | let _: E = E::A; = note: expected type `E` found type `fn(usize) -> E {E::A}` -error: aborting due to 8 previous errors +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:37:20 + | +LL | fn baz(x: usize, y: usize) -> usize { x } + | ----------------------------------- fn(usize, usize) -> usize {::baz} defined here +... +LL | let _: usize = X::baz; + | ^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `X::baz(x, y)` + | + = note: expected type `usize` + found type `fn(usize, usize) -> usize {::baz}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:38:20 + | +LL | fn bat(x: usize) -> usize { 42 } + | ------------------------- fn(usize) -> usize {::bat} defined here +... +LL | let _: usize = X::bat; + | ^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `X::bat(x)` + | + = note: expected type `usize` + found type `fn(usize) -> usize {::bat}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:39:20 + | +LL | fn bax(x: usize) -> usize { 42 } + | ------------------------- fn(usize) -> usize {::bax} defined here +... +LL | let _: usize = X::bax; + | ^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `X::bax(x)` + | + = note: expected type `usize` + found type `fn(usize) -> usize {::bax}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:40:20 + | +LL | fn bach(x: usize) -> usize; + | --------------------------- fn(usize) -> usize {::bach} defined here +... +LL | let _: usize = X::bach; + | ^^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `X::bach(x)` + | + = note: expected type `usize` + found type `fn(usize) -> usize {::bach}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:41:20 + | +LL | fn ban(&self) -> usize { 42 } + | ---------------------- for<'r> fn(&'r X) -> usize {::ban} defined here +... +LL | let _: usize = X::ban; + | ^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `X::ban(_)` + | + = note: expected type `usize` + found type `for<'r> fn(&'r X) -> usize {::ban}` + +error[E0308]: mismatched types + --> $DIR/fn-or-tuple-struct-without-args.rs:42:20 + | +LL | fn bal(&self) -> usize; + | ----------------------- for<'r> fn(&'r X) -> usize {::bal} defined here +... +LL | let _: usize = X::bal; + | ^^^^^^ + | | + | expected usize, found fn item + | help: use parentheses to call this function: `X::bal(_)` + | + = note: expected type `usize` + found type `for<'r> fn(&'r X) -> usize {::bal}` + +error[E0615]: attempted to take value of method `ban` on type `X` + --> $DIR/fn-or-tuple-struct-without-args.rs:43:22 + | +LL | let _: usize = X.ban; + | ^^^ help: use parentheses to call the method: `ban()` + +error[E0615]: attempted to take value of method `bal` on type `X` + --> $DIR/fn-or-tuple-struct-without-args.rs:44:22 + | +LL | let _: usize = X.bal; + | ^^^ help: use parentheses to call the method: `bal()` + +error: aborting due to 16 previous errors -Some errors have detailed explanations: E0308, E0423. +Some errors have detailed explanations: E0308, E0423, E0615. For more information about an error, try `rustc --explain E0308`. From 33d1082d6e3cb9fe5e0fd090f52a3effa9871fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 15:55:18 -0700 Subject: [PATCH 12/14] review comment: review wording or missing return error --- src/librustc_typeck/check/mod.rs | 3 ++- .../ui/block-result/consider-removing-last-semi.stderr | 4 ++-- src/test/ui/block-result/issue-11714.stderr | 2 +- src/test/ui/block-result/issue-13428.stderr | 4 ++-- .../coercion/coercion-missing-tail-expected-type.stderr | 4 ++-- src/test/ui/issues/issue-32323.stderr | 2 +- src/test/ui/issues/issue-43162.stderr | 2 +- src/test/ui/issues/issue-44023.stderr | 2 +- src/test/ui/issues/issue-6458-4.stderr | 2 +- src/test/ui/liveness/liveness-forgot-ret.stderr | 2 +- src/test/ui/liveness/liveness-missing-ret2.stderr | 2 +- .../ui/liveness/liveness-return-last-stmt-semi.stderr | 8 ++++---- src/test/ui/missing/missing-return.stderr | 2 +- src/test/ui/parser/issue-62881.stderr | 2 +- src/test/ui/parser/issue-62895.stderr | 2 +- 15 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d389563aea639..086f3d419576a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3711,7 +3711,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(fn_span) = fn_span { err.span_label( fn_span, - "this function's body doesn't `return` a value", + "this function implicitly returns `()` as its body has no tail \ + or `return` expression", ); } }, false); diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr index f3dfc8b12eafe..4c421e6ada405 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.stderr +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | 0u8; LL | "bla".to_string(); | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn g() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | "this won't work".to_string(); LL | "removeme".to_string(); | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-11714.stderr b/src/test/ui/block-result/issue-11714.stderr index 021a25ece2f4d..a0bdbd693f2cf 100644 --- a/src/test/ui/block-result/issue-11714.stderr +++ b/src/test/ui/block-result/issue-11714.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn blah() -> i32 { | ---- ^^^ expected i32, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression ... LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr index 8fa6ae9c528b4..53f8eaa1ae227 100644 --- a/src/test/ui/block-result/issue-13428.stderr +++ b/src/test/ui/block-result/issue-13428.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression ... LL | ; | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn bar() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | "foobar".to_string() LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr index 6ecb1d3eaef4a..fde41567d8002 100644 --- a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr +++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn plus_one(x: i32) -> i32 { | -------- ^^^ expected i32, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | x + 1; | - help: consider removing this semicolon | @@ -17,7 +17,7 @@ error[E0308]: mismatched types LL | fn foo() -> Result { | --- ^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | Ok(1); | - help: consider removing this semicolon | diff --git a/src/test/ui/issues/issue-32323.stderr b/src/test/ui/issues/issue-32323.stderr index 376676bda7dbf..138b058f44d9e 100644 --- a/src/test/ui/issues/issue-32323.stderr +++ b/src/test/ui/issues/issue-32323.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | pub fn f<'a, T: Tr<'a>>() -> >::Out {} | - ^^^^^^^^^^^^^^^^^^ expected associated type, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `>::Out` found type `()` diff --git a/src/test/ui/issues/issue-43162.stderr b/src/test/ui/issues/issue-43162.stderr index 22d347778c8f4..e90531bce3e86 100644 --- a/src/test/ui/issues/issue-43162.stderr +++ b/src/test/ui/issues/issue-43162.stderr @@ -16,7 +16,7 @@ error[E0308]: mismatched types LL | fn foo() -> bool { | --- ^^^^ expected bool, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | LL | break true; | - help: consider removing this semicolon diff --git a/src/test/ui/issues/issue-44023.stderr b/src/test/ui/issues/issue-44023.stderr index 7760af8145b07..4a27531b4be8f 100644 --- a/src/test/ui/issues/issue-44023.stderr +++ b/src/test/ui/issues/issue-44023.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn საჭმელად_გემრიელი_სადილი ( ) -> isize { | ------------------------ ^^^^^ expected isize, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/issues/issue-6458-4.stderr b/src/test/ui/issues/issue-6458-4.stderr index e29be76087416..4db3daede758f 100644 --- a/src/test/ui/issues/issue-6458-4.stderr +++ b/src/test/ui/issues/issue-6458-4.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo(b: bool) -> Result { | --- ^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | Err("bar".to_string()); | - help: consider removing this semicolon | diff --git a/src/test/ui/liveness/liveness-forgot-ret.stderr b/src/test/ui/liveness/liveness-forgot-ret.stderr index 68cbdb2cfdba6..24106f775794c 100644 --- a/src/test/ui/liveness/liveness-forgot-ret.stderr +++ b/src/test/ui/liveness/liveness-forgot-ret.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f(a: isize) -> isize { if god_exists(a) { return 5; }; } | - ^^^^^ expected isize, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-missing-ret2.stderr b/src/test/ui/liveness/liveness-missing-ret2.stderr index 62e0aa5d29d95..9502e4467499c 100644 --- a/src/test/ui/liveness/liveness-missing-ret2.stderr +++ b/src/test/ui/liveness/liveness-missing-ret2.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { | - ^^^^^ expected isize, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr index c5018af74f347..7ee4cb178a6c5 100644 --- a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr +++ b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr @@ -5,7 +5,7 @@ LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } } | --- ^^^ - help: consider removing this semicolon | | | | | expected i32, found () - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression ... LL | test!(); | -------- in this macro invocation @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn no_return() -> i32 {} | --------- ^^^ expected i32, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `i32` found type `()` @@ -30,7 +30,7 @@ error[E0308]: mismatched types LL | fn bar(x: u32) -> u32 { | --- ^^^ expected u32, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression LL | x * 2; | - help: consider removing this semicolon | @@ -43,7 +43,7 @@ error[E0308]: mismatched types LL | fn baz(x: u64) -> u32 { | --- ^^^ expected u32, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `u32` found type `()` diff --git a/src/test/ui/missing/missing-return.stderr b/src/test/ui/missing/missing-return.stderr index 4cd516ba81d6a..541e9fa4a4016 100644 --- a/src/test/ui/missing/missing-return.stderr +++ b/src/test/ui/missing/missing-return.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { } | - ^^^^^ expected isize, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62881.stderr b/src/test/ui/parser/issue-62881.stderr index 11b8836a89a76..40f64ec8fd0e2 100644 --- a/src/test/ui/parser/issue-62881.stderr +++ b/src/test/ui/parser/issue-62881.stderr @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { fn f() -> isize {} pub f< | - ^^^^^ expected isize, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62895.stderr b/src/test/ui/parser/issue-62895.stderr index d9d3baf622708..4c872d0c9d367 100644 --- a/src/test/ui/parser/issue-62895.stderr +++ b/src/test/ui/parser/issue-62895.stderr @@ -38,7 +38,7 @@ error[E0308]: mismatched types LL | fn v() -> isize { | - ^^^^^ expected isize, found () | | - | this function's body doesn't `return` a value + | this function implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` From bc1a4f52e3bcb092142267c7d1e6b90b718d557e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Aug 2019 16:56:57 -0700 Subject: [PATCH 13/14] review comments: typo and rewording --- src/librustc_typeck/check/mod.rs | 8 ++++---- .../ui/block-result/consider-removing-last-semi.stderr | 4 ++-- src/test/ui/block-result/issue-11714.stderr | 2 +- src/test/ui/block-result/issue-13428.stderr | 4 ++-- .../coercion/coercion-missing-tail-expected-type.stderr | 4 ++-- src/test/ui/issues/issue-32323.stderr | 2 +- src/test/ui/issues/issue-35241.stderr | 2 +- src/test/ui/issues/issue-43162.stderr | 2 +- src/test/ui/issues/issue-44023.stderr | 2 +- src/test/ui/issues/issue-6458-4.stderr | 2 +- src/test/ui/liveness/liveness-forgot-ret.stderr | 2 +- src/test/ui/liveness/liveness-missing-ret2.stderr | 2 +- .../ui/liveness/liveness-return-last-stmt-semi.stderr | 8 ++++---- src/test/ui/missing/missing-return.stderr | 2 +- src/test/ui/parser/issue-62881.stderr | 2 +- src/test/ui/parser/issue-62895.stderr | 2 +- src/test/ui/resolve/privacy-enum-ctor.stderr | 6 +++--- .../ui/suggestions/fn-or-tuple-struct-without-args.stderr | 6 +++--- 18 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 086f3d419576a..4fb28db6e94fa 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3711,8 +3711,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(fn_span) = fn_span { err.span_label( fn_span, - "this function implicitly returns `()` as its body has no tail \ - or `return` expression", + "implicitly returns `()` as its body has no tail or `return` \ + expression", ); } }, false); @@ -3880,10 +3880,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sugg_call = fields.iter().map(|_| "_").collect::>().join(", "); match hir.as_local_hir_id(def_id).and_then(|hir_id| hir.def_kind(hir_id)) { Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, _)) => { - msg = "instatiate this tuple variant"; + msg = "instantiate this tuple variant"; } Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Struct, _)) => { - msg = "instatiate this tuple struct"; + msg = "instantiate this tuple struct"; } _ => {} } diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr index 4c421e6ada405..f4984ca446309 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.stderr +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | 0u8; LL | "bla".to_string(); | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn g() -> String { | - ^^^^^^ expected struct `std::string::String`, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | "this won't work".to_string(); LL | "removeme".to_string(); | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-11714.stderr b/src/test/ui/block-result/issue-11714.stderr index a0bdbd693f2cf..cfb42c601279a 100644 --- a/src/test/ui/block-result/issue-11714.stderr +++ b/src/test/ui/block-result/issue-11714.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn blah() -> i32 { | ---- ^^^ expected i32, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression ... LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr index 53f8eaa1ae227..f7cafab3d773b 100644 --- a/src/test/ui/block-result/issue-13428.stderr +++ b/src/test/ui/block-result/issue-13428.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression ... LL | ; | - help: consider removing this semicolon @@ -18,7 +18,7 @@ error[E0308]: mismatched types LL | fn bar() -> String { | --- ^^^^^^ expected struct `std::string::String`, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | "foobar".to_string() LL | ; | - help: consider removing this semicolon diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr index fde41567d8002..955793e8586e7 100644 --- a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr +++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn plus_one(x: i32) -> i32 { | -------- ^^^ expected i32, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | x + 1; | - help: consider removing this semicolon | @@ -17,7 +17,7 @@ error[E0308]: mismatched types LL | fn foo() -> Result { | --- ^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | Ok(1); | - help: consider removing this semicolon | diff --git a/src/test/ui/issues/issue-32323.stderr b/src/test/ui/issues/issue-32323.stderr index 138b058f44d9e..6256dc0c55022 100644 --- a/src/test/ui/issues/issue-32323.stderr +++ b/src/test/ui/issues/issue-32323.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | pub fn f<'a, T: Tr<'a>>() -> >::Out {} | - ^^^^^^^^^^^^^^^^^^ expected associated type, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `>::Out` found type `()` diff --git a/src/test/ui/issues/issue-35241.stderr b/src/test/ui/issues/issue-35241.stderr index 8befc6873857e..586146cbaa4ee 100644 --- a/src/test/ui/issues/issue-35241.stderr +++ b/src/test/ui/issues/issue-35241.stderr @@ -8,7 +8,7 @@ LL | fn test() -> Foo { Foo } | --- ^^^ | | | | | expected struct `Foo`, found fn item - | | help: use parentheses to instatiate this tuple struct: `Foo(_)` + | | help: use parentheses to instantiate this tuple struct: `Foo(_)` | expected `Foo` because of return type | = note: expected type `Foo` diff --git a/src/test/ui/issues/issue-43162.stderr b/src/test/ui/issues/issue-43162.stderr index e90531bce3e86..6d3e8b5ba2323 100644 --- a/src/test/ui/issues/issue-43162.stderr +++ b/src/test/ui/issues/issue-43162.stderr @@ -16,7 +16,7 @@ error[E0308]: mismatched types LL | fn foo() -> bool { | --- ^^^^ expected bool, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | LL | break true; | - help: consider removing this semicolon diff --git a/src/test/ui/issues/issue-44023.stderr b/src/test/ui/issues/issue-44023.stderr index 4a27531b4be8f..258ffe558e9ba 100644 --- a/src/test/ui/issues/issue-44023.stderr +++ b/src/test/ui/issues/issue-44023.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn საჭმელად_გემრიელი_სადილი ( ) -> isize { | ------------------------ ^^^^^ expected isize, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/issues/issue-6458-4.stderr b/src/test/ui/issues/issue-6458-4.stderr index 4db3daede758f..ecf729e1032b1 100644 --- a/src/test/ui/issues/issue-6458-4.stderr +++ b/src/test/ui/issues/issue-6458-4.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn foo(b: bool) -> Result { | --- ^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | Err("bar".to_string()); | - help: consider removing this semicolon | diff --git a/src/test/ui/liveness/liveness-forgot-ret.stderr b/src/test/ui/liveness/liveness-forgot-ret.stderr index 24106f775794c..4baf351f7eb2d 100644 --- a/src/test/ui/liveness/liveness-forgot-ret.stderr +++ b/src/test/ui/liveness/liveness-forgot-ret.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f(a: isize) -> isize { if god_exists(a) { return 5; }; } | - ^^^^^ expected isize, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-missing-ret2.stderr b/src/test/ui/liveness/liveness-missing-ret2.stderr index 9502e4467499c..1f60560b45043 100644 --- a/src/test/ui/liveness/liveness-missing-ret2.stderr +++ b/src/test/ui/liveness/liveness-missing-ret2.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { | - ^^^^^ expected isize, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr index 7ee4cb178a6c5..2497d93daa494 100644 --- a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr +++ b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr @@ -5,7 +5,7 @@ LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } } | --- ^^^ - help: consider removing this semicolon | | | | | expected i32, found () - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression ... LL | test!(); | -------- in this macro invocation @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn no_return() -> i32 {} | --------- ^^^ expected i32, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `i32` found type `()` @@ -30,7 +30,7 @@ error[E0308]: mismatched types LL | fn bar(x: u32) -> u32 { | --- ^^^ expected u32, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression LL | x * 2; | - help: consider removing this semicolon | @@ -43,7 +43,7 @@ error[E0308]: mismatched types LL | fn baz(x: u64) -> u32 { | --- ^^^ expected u32, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `u32` found type `()` diff --git a/src/test/ui/missing/missing-return.stderr b/src/test/ui/missing/missing-return.stderr index 541e9fa4a4016..3c8ecdcfbcbe4 100644 --- a/src/test/ui/missing/missing-return.stderr +++ b/src/test/ui/missing/missing-return.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { } | - ^^^^^ expected isize, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62881.stderr b/src/test/ui/parser/issue-62881.stderr index 40f64ec8fd0e2..3d58b6fba0baf 100644 --- a/src/test/ui/parser/issue-62881.stderr +++ b/src/test/ui/parser/issue-62881.stderr @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | fn f() -> isize { fn f() -> isize {} pub f< | - ^^^^^ expected isize, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/parser/issue-62895.stderr b/src/test/ui/parser/issue-62895.stderr index 4c872d0c9d367..39ce980964b77 100644 --- a/src/test/ui/parser/issue-62895.stderr +++ b/src/test/ui/parser/issue-62895.stderr @@ -38,7 +38,7 @@ error[E0308]: mismatched types LL | fn v() -> isize { | - ^^^^^ expected isize, found () | | - | this function implicitly returns `()` as its body has no tail or `return` expression + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `isize` found type `()` diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index 3e924f7d161bd..2538bbbf8067f 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -202,7 +202,7 @@ LL | let _: Z = Z::Fn; | ^^^^^ | | | expected enum `m::n::Z`, found fn item - | help: use parentheses to instatiate this tuple variant: `Z::Fn(_)` + | help: use parentheses to instantiate this tuple variant: `Z::Fn(_)` | = note: expected type `m::n::Z` found type `fn(u8) -> m::n::Z {m::n::Z::Fn}` @@ -232,7 +232,7 @@ LL | let _: E = m::E::Fn; | ^^^^^^^^ | | | expected enum `m::E`, found fn item - | help: use parentheses to instatiate this tuple variant: `m::E::Fn(_)` + | help: use parentheses to instantiate this tuple variant: `m::E::Fn(_)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` @@ -262,7 +262,7 @@ LL | let _: E = E::Fn; | ^^^^^ | | | expected enum `m::E`, found fn item - | help: use parentheses to instatiate this tuple variant: `E::Fn(_)` + | help: use parentheses to instantiate this tuple variant: `E::Fn(_)` | = note: expected type `m::E` found type `fn(u8) -> m::E {m::E::Fn}` diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr index e3012144513fd..0686b56f97ded 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -32,7 +32,7 @@ LL | let _: S = S; | ^ | | | expected struct `S`, found fn item - | help: use parentheses to instatiate this tuple struct: `S(_, _)` + | help: use parentheses to instantiate this tuple struct: `S(_, _)` | = note: expected type `S` found type `fn(usize, usize) -> S {S}` @@ -62,7 +62,7 @@ LL | let _: V = V; | ^ | | | expected struct `V`, found fn item - | help: use parentheses to instatiate this tuple struct: `V()` + | help: use parentheses to instantiate this tuple struct: `V()` | = note: expected type `V` found type `fn() -> V {V}` @@ -107,7 +107,7 @@ LL | let _: E = E::A; | ^^^^ | | | expected enum `E`, found fn item - | help: use parentheses to instatiate this tuple variant: `E::A(_)` + | help: use parentheses to instantiate this tuple variant: `E::A(_)` | = note: expected type `E` found type `fn(usize) -> E {E::A}` From 45a5bc7619d19e58cbb1497f571e2ba987d1d53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 9 Aug 2019 07:57:16 -0700 Subject: [PATCH 14/14] fix tests --- .../async-block-control-flow-static-semantics.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr b/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr index 96927ac9632d6..f3f2d14584ef7 100644 --- a/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr +++ b/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr @@ -16,7 +16,7 @@ error[E0308]: mismatched types LL | fn return_targets_async_block_not_fn() -> u8 { | --------------------------------- ^^ expected u8, found () | | - | this function's body doesn't return + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `u8` found type `()` @@ -57,7 +57,7 @@ error[E0308]: mismatched types LL | fn rethrow_targets_async_block_not_fn() -> Result { | ---------------------------------- ^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't return + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `std::result::Result` found type `()` @@ -68,7 +68,7 @@ error[E0308]: mismatched types LL | fn rethrow_targets_async_block_not_async_fn() -> Result { | ---------------------------------------- ^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found () | | - | this function's body doesn't return + | implicitly returns `()` as its body has no tail or `return` expression | = note: expected type `std::result::Result` found type `()`