From 4a286639e8448476b0235c8fb2c8eeb7779b9251 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 16 May 2017 15:11:34 +0200 Subject: [PATCH 1/3] Move some tests from compile-fail to ui --- .../ui-fulldeps/auxiliary/attr_proc_macro.rs | 23 ++++++ .../ui-fulldeps/auxiliary/bang_proc_macro.rs | 23 ++++++ .../ui-fulldeps/auxiliary/derive-clona.rs | 23 ++++++ src/test/ui-fulldeps/auxiliary/derive-foo.rs | 23 ++++++ .../resolve-error.rs | 17 ----- src/test/ui-fulldeps/resolve-error.stderr | 76 +++++++++++++++++++ ...cast-to-unsized-trait-object-suggestion.rs | 6 -- ...-to-unsized-trait-object-suggestion.stderr | 18 +++++ src/test/{compile-fail => ui}/issue-35675.rs | 0 src/test/ui/issue-35675.stderr | 74 ++++++++++++++++++ .../macros}/macro-name-typo.rs | 2 - src/test/ui/macros/macro-name-typo.stderr | 10 +++ .../macros}/macro_undefined.rs | 4 - src/test/ui/macros/macro_undefined.stderr | 18 +++++ src/test/ui/resolve-error.stderr | 76 +++++++++++++++++++ 15 files changed, 364 insertions(+), 29 deletions(-) create mode 100644 src/test/ui-fulldeps/auxiliary/attr_proc_macro.rs create mode 100644 src/test/ui-fulldeps/auxiliary/bang_proc_macro.rs create mode 100644 src/test/ui-fulldeps/auxiliary/derive-clona.rs create mode 100644 src/test/ui-fulldeps/auxiliary/derive-foo.rs rename src/test/{compile-fail-fulldeps/proc-macro => ui-fulldeps}/resolve-error.rs (57%) create mode 100644 src/test/ui-fulldeps/resolve-error.stderr rename src/test/{compile-fail => ui}/cast-to-unsized-trait-object-suggestion.rs (67%) create mode 100644 src/test/ui/cast-to-unsized-trait-object-suggestion.stderr rename src/test/{compile-fail => ui}/issue-35675.rs (100%) create mode 100644 src/test/ui/issue-35675.stderr rename src/test/{compile-fail => ui/macros}/macro-name-typo.rs (87%) create mode 100644 src/test/ui/macros/macro-name-typo.stderr rename src/test/{compile-fail => ui/macros}/macro_undefined.rs (74%) create mode 100644 src/test/ui/macros/macro_undefined.stderr create mode 100644 src/test/ui/resolve-error.stderr diff --git a/src/test/ui-fulldeps/auxiliary/attr_proc_macro.rs b/src/test/ui-fulldeps/auxiliary/attr_proc_macro.rs new file mode 100644 index 0000000000000..db0c19e96f821 --- /dev/null +++ b/src/test/ui-fulldeps/auxiliary/attr_proc_macro.rs @@ -0,0 +1,23 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// force-host +// no-prefer-dynamic +#![feature(proc_macro)] +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_attribute] +pub fn attr_proc_macro(_: TokenStream, input: TokenStream) -> TokenStream { + input +} diff --git a/src/test/ui-fulldeps/auxiliary/bang_proc_macro.rs b/src/test/ui-fulldeps/auxiliary/bang_proc_macro.rs new file mode 100644 index 0000000000000..89ac11b309d75 --- /dev/null +++ b/src/test/ui-fulldeps/auxiliary/bang_proc_macro.rs @@ -0,0 +1,23 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// force-host +// no-prefer-dynamic +#![feature(proc_macro)] +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro] +pub fn bang_proc_macro(input: TokenStream) -> TokenStream { + input +} diff --git a/src/test/ui-fulldeps/auxiliary/derive-clona.rs b/src/test/ui-fulldeps/auxiliary/derive-clona.rs new file mode 100644 index 0000000000000..719fbdb15ef2a --- /dev/null +++ b/src/test/ui-fulldeps/auxiliary/derive-clona.rs @@ -0,0 +1,23 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(Clona)] +pub fn derive_clonea(input: TokenStream) -> TokenStream { + "".parse().unwrap() +} diff --git a/src/test/ui-fulldeps/auxiliary/derive-foo.rs b/src/test/ui-fulldeps/auxiliary/derive-foo.rs new file mode 100644 index 0000000000000..64dcf72ba2029 --- /dev/null +++ b/src/test/ui-fulldeps/auxiliary/derive-foo.rs @@ -0,0 +1,23 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(FooWithLongName)] +pub fn derive_foo(input: TokenStream) -> TokenStream { + "".parse().unwrap() +} diff --git a/src/test/compile-fail-fulldeps/proc-macro/resolve-error.rs b/src/test/ui-fulldeps/resolve-error.rs similarity index 57% rename from src/test/compile-fail-fulldeps/proc-macro/resolve-error.rs rename to src/test/ui-fulldeps/resolve-error.rs index ddd8631f02e62..dfaa1d7a32e57 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/resolve-error.rs +++ b/src/test/ui-fulldeps/resolve-error.rs @@ -35,46 +35,29 @@ macro_rules! attr_proc_mac { } #[derive(FooWithLongNan)] -//~^ ERROR cannot find derive macro `FooWithLongNan` in this scope -//~^^ HELP did you mean `FooWithLongName`? struct Foo; #[attr_proc_macra] -//~^ ERROR cannot find attribute macro `attr_proc_macra` in this scope -//~^^ HELP did you mean `attr_proc_macro`? struct Bar; #[FooWithLongNan] -//~^ ERROR cannot find attribute macro `FooWithLongNan` in this scope struct Asdf; #[derive(Dlone)] -//~^ ERROR cannot find derive macro `Dlone` in this scope -//~^^ HELP did you mean `Clone`? struct A; #[derive(Dlona)] -//~^ ERROR cannot find derive macro `Dlona` in this scope -//~^^ HELP did you mean `Clona`? struct B; #[derive(attr_proc_macra)] -//~^ ERROR cannot find derive macro `attr_proc_macra` in this scope struct C; fn main() { FooWithLongNama!(); - //~^ ERROR cannot find macro `FooWithLongNama!` in this scope - //~^^ HELP did you mean `FooWithLongNam!`? attr_proc_macra!(); - //~^ ERROR cannot find macro `attr_proc_macra!` in this scope - //~^^ HELP did you mean `attr_proc_mac!`? Dlona!(); - //~^ ERROR cannot find macro `Dlona!` in this scope bang_proc_macrp!(); - //~^ ERROR cannot find macro `bang_proc_macrp!` in this scope - //~^^ HELP did you mean `bang_proc_macro!`? } diff --git a/src/test/ui-fulldeps/resolve-error.stderr b/src/test/ui-fulldeps/resolve-error.stderr new file mode 100644 index 0000000000000..cfc15d69feb63 --- /dev/null +++ b/src/test/ui-fulldeps/resolve-error.stderr @@ -0,0 +1,76 @@ +error: cannot find derive macro `FooWithLongNan` in this scope + --> $DIR/resolve-error.rs:36:10 + | +36 | #[derive(FooWithLongNan)] + | ^^^^^^^^^^^^^^ + | + = help: did you mean `FooWithLongName`? + +error: cannot find attribute macro `attr_proc_macra` in this scope + --> $DIR/resolve-error.rs:39:3 + | +39 | #[attr_proc_macra] + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `attr_proc_macro`? + +error: cannot find attribute macro `FooWithLongNan` in this scope + --> $DIR/resolve-error.rs:42:3 + | +42 | #[FooWithLongNan] + | ^^^^^^^^^^^^^^ + +error: cannot find derive macro `Dlone` in this scope + --> $DIR/resolve-error.rs:45:10 + | +45 | #[derive(Dlone)] + | ^^^^^ + | + = help: did you mean `Clone`? + +error: cannot find derive macro `Dlona` in this scope + --> $DIR/resolve-error.rs:48:10 + | +48 | #[derive(Dlona)] + | ^^^^^ + | + = help: did you mean `Clona`? + +error: cannot find derive macro `attr_proc_macra` in this scope + --> $DIR/resolve-error.rs:51:10 + | +51 | #[derive(attr_proc_macra)] + | ^^^^^^^^^^^^^^^ + +error: cannot find macro `FooWithLongNama!` in this scope + --> $DIR/resolve-error.rs:55:5 + | +55 | FooWithLongNama!(); + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `FooWithLongNam!`? + +error: cannot find macro `attr_proc_macra!` in this scope + --> $DIR/resolve-error.rs:57:5 + | +57 | attr_proc_macra!(); + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `attr_proc_mac!`? + +error: cannot find macro `Dlona!` in this scope + --> $DIR/resolve-error.rs:59:5 + | +59 | Dlona!(); + | ^^^^^ + +error: cannot find macro `bang_proc_macrp!` in this scope + --> $DIR/resolve-error.rs:61:5 + | +61 | bang_proc_macrp!(); + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `bang_proc_macro!`? + +error: aborting due to 10 previous errors + diff --git a/src/test/compile-fail/cast-to-unsized-trait-object-suggestion.rs b/src/test/ui/cast-to-unsized-trait-object-suggestion.rs similarity index 67% rename from src/test/compile-fail/cast-to-unsized-trait-object-suggestion.rs rename to src/test/ui/cast-to-unsized-trait-object-suggestion.rs index d18746cdf0ba5..c793454798275 100644 --- a/src/test/compile-fail/cast-to-unsized-trait-object-suggestion.rs +++ b/src/test/ui/cast-to-unsized-trait-object-suggestion.rs @@ -10,11 +10,5 @@ fn main() { &1 as Send; - //~^ ERROR cast to unsized type - //~| HELP try casting to a reference instead: - //~| SUGGESTION &1 as &Send; Box::new(1) as Send; - //~^ ERROR cast to unsized type - //~| HELP try casting to a `Box` instead: - //~| SUGGESTION Box::new(1) as Box; } diff --git a/src/test/ui/cast-to-unsized-trait-object-suggestion.stderr b/src/test/ui/cast-to-unsized-trait-object-suggestion.stderr new file mode 100644 index 0000000000000..dd9c2d14ef24e --- /dev/null +++ b/src/test/ui/cast-to-unsized-trait-object-suggestion.stderr @@ -0,0 +1,18 @@ +error: cast to unsized type: `&{integer}` as `std::marker::Send` + --> $DIR/cast-to-unsized-trait-object-suggestion.rs:12:5 + | +12 | &1 as Send; + | ^^^^^^---- + | | + | help: try casting to a reference instead: `&Send` + +error: cast to unsized type: `std::boxed::Box<{integer}>` as `std::marker::Send` + --> $DIR/cast-to-unsized-trait-object-suggestion.rs:13:5 + | +13 | Box::new(1) as Send; + | ^^^^^^^^^^^^^^^---- + | | + | help: try casting to a `Box` instead: `Box` + +error: aborting due to previous error(s) + diff --git a/src/test/compile-fail/issue-35675.rs b/src/test/ui/issue-35675.rs similarity index 100% rename from src/test/compile-fail/issue-35675.rs rename to src/test/ui/issue-35675.rs diff --git a/src/test/ui/issue-35675.stderr b/src/test/ui/issue-35675.stderr new file mode 100644 index 0000000000000..22322a388c5f2 --- /dev/null +++ b/src/test/ui/issue-35675.stderr @@ -0,0 +1,74 @@ +error[E0412]: cannot find type `Apple` in this scope + --> $DIR/issue-35675.rs:20:29 + | +20 | fn should_return_fruit() -> Apple { + | ^^^^^ not found in this scope + | +help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`? + --> $DIR/issue-35675.rs:14:5 + | +14 | Apple(i64), + | ^^^^^^^^^^ + +error[E0425]: cannot find function `Apple` in this scope + --> $DIR/issue-35675.rs:23:5 + | +23 | Apple(5) + | ^^^^^ not found in this scope + | +help: possible candidate is found in another module, you can import it into scope + | use Fruit::Apple; + +error[E0573]: expected type, found variant `Fruit::Apple` + --> $DIR/issue-35675.rs:28:33 + | +28 | fn should_return_fruit_too() -> Fruit::Apple { + | ^^^^^^^^^^^^ not a type + | +help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`? + --> $DIR/issue-35675.rs:14:5 + | +14 | Apple(i64), + | ^^^^^^^^^^ + +error[E0425]: cannot find function `Apple` in this scope + --> $DIR/issue-35675.rs:31:5 + | +31 | Apple(5) + | ^^^^^ not found in this scope + | +help: possible candidate is found in another module, you can import it into scope + | use Fruit::Apple; + +error[E0573]: expected type, found variant `Ok` + --> $DIR/issue-35675.rs:36:13 + | +36 | fn foo() -> Ok { + | ^^ not a type + | + = help: there is an enum variant `std::prelude::v1::Ok`, did you mean to use `std::prelude::v1`? + = help: there is an enum variant `std::prelude::v1::Result::Ok`, did you mean to use `std::prelude::v1::Result`? + +error[E0412]: cannot find type `Variant3` in this scope + --> $DIR/issue-35675.rs:44:13 + | +44 | fn bar() -> Variant3 { + | ^^^^^^^^ not found in this scope + | +help: there is an enum variant `x::Enum::Variant3`, did you mean to use `x::Enum`? + --> $DIR/issue-35675.rs:63:9 + | +63 | Variant3(usize), + | ^^^^^^^^^^^^^^^ + +error[E0573]: expected type, found variant `Some` + --> $DIR/issue-35675.rs:49:13 + | +49 | fn qux() -> Some { + | ^^^^ not a type + | + = help: there is an enum variant `std::option::Option::Some`, did you mean to use `std::option::Option`? + = help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`? + +error: aborting due to previous error(s) + diff --git a/src/test/compile-fail/macro-name-typo.rs b/src/test/ui/macros/macro-name-typo.rs similarity index 87% rename from src/test/compile-fail/macro-name-typo.rs rename to src/test/ui/macros/macro-name-typo.rs index 4840205fee4c3..ec8d27f9138f7 100644 --- a/src/test/compile-fail/macro-name-typo.rs +++ b/src/test/ui/macros/macro-name-typo.rs @@ -10,6 +10,4 @@ fn main() { printlx!("oh noes!"); - //~^ ERROR cannot find macro - //~^^ HELP did you mean `println!`? } diff --git a/src/test/ui/macros/macro-name-typo.stderr b/src/test/ui/macros/macro-name-typo.stderr new file mode 100644 index 0000000000000..c54de468d133f --- /dev/null +++ b/src/test/ui/macros/macro-name-typo.stderr @@ -0,0 +1,10 @@ +error: cannot find macro `printlx!` in this scope + --> $DIR/macro-name-typo.rs:12:5 + | +12 | printlx!("oh noes!"); + | ^^^^^^^ + | + = help: did you mean `println!`? + +error: aborting due to previous error(s) + diff --git a/src/test/compile-fail/macro_undefined.rs b/src/test/ui/macros/macro_undefined.rs similarity index 74% rename from src/test/compile-fail/macro_undefined.rs rename to src/test/ui/macros/macro_undefined.rs index 00c8d44f30602..db93ba5e2c41d 100644 --- a/src/test/compile-fail/macro_undefined.rs +++ b/src/test/ui/macros/macro_undefined.rs @@ -19,9 +19,5 @@ mod m { fn main() { k!(); - //~^ ERROR cannot find macro `k!` in this scope - //~^^ HELP did you mean `kl!`? kl!(); - //~^ ERROR cannot find macro `kl!` in this scope - //~^^ HELP have you added the `#[macro_use]` on the module/import? } diff --git a/src/test/ui/macros/macro_undefined.stderr b/src/test/ui/macros/macro_undefined.stderr new file mode 100644 index 0000000000000..152de056991c8 --- /dev/null +++ b/src/test/ui/macros/macro_undefined.stderr @@ -0,0 +1,18 @@ +error: cannot find macro `kl!` in this scope + --> $DIR/macro_undefined.rs:22:5 + | +22 | kl!(); + | ^^ + | + = help: have you added the `#[macro_use]` on the module/import? + +error: cannot find macro `k!` in this scope + --> $DIR/macro_undefined.rs:21:5 + | +21 | k!(); + | ^ + | + = help: did you mean `kl!`? + +error: aborting due to previous error(s) + diff --git a/src/test/ui/resolve-error.stderr b/src/test/ui/resolve-error.stderr new file mode 100644 index 0000000000000..946eaba45fc13 --- /dev/null +++ b/src/test/ui/resolve-error.stderr @@ -0,0 +1,76 @@ +error: cannot find derive macro `FooWithLongNan` in this scope + --> $DIR/resolve-error.rs:37:10 + | +37 | #[derive(FooWithLongNan)] + | ^^^^^^^^^^^^^^ + | + = help: did you mean `FooWithLongName`? + +error: cannot find attribute macro `attr_proc_macra` in this scope + --> $DIR/resolve-error.rs:40:3 + | +40 | #[attr_proc_macra] + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `attr_proc_macro`? + +error: cannot find attribute macro `FooWithLongNan` in this scope + --> $DIR/resolve-error.rs:43:3 + | +43 | #[FooWithLongNan] + | ^^^^^^^^^^^^^^ + +error: cannot find derive macro `Dlone` in this scope + --> $DIR/resolve-error.rs:46:10 + | +46 | #[derive(Dlone)] + | ^^^^^ + | + = help: did you mean `Clone`? + +error: cannot find derive macro `Dlona` in this scope + --> $DIR/resolve-error.rs:49:10 + | +49 | #[derive(Dlona)] + | ^^^^^ + | + = help: did you mean `Clona`? + +error: cannot find derive macro `attr_proc_macra` in this scope + --> $DIR/resolve-error.rs:52:10 + | +52 | #[derive(attr_proc_macra)] + | ^^^^^^^^^^^^^^^ + +error: cannot find macro `FooWithLongNama!` in this scope + --> $DIR/resolve-error.rs:56:5 + | +56 | FooWithLongNama!(); + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `FooWithLongNam!`? + +error: cannot find macro `attr_proc_macra!` in this scope + --> $DIR/resolve-error.rs:58:5 + | +58 | attr_proc_macra!(); + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `attr_proc_mac!`? + +error: cannot find macro `Dlona!` in this scope + --> $DIR/resolve-error.rs:60:5 + | +60 | Dlona!(); + | ^^^^^ + +error: cannot find macro `bang_proc_macrp!` in this scope + --> $DIR/resolve-error.rs:62:5 + | +62 | bang_proc_macrp!(); + | ^^^^^^^^^^^^^^^ + | + = help: did you mean `bang_proc_macro!`? + +error: aborting due to previous error(s) + From a9d9a4aab4f6c51d16c2f13e69abcbe8f6c76725 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 16 May 2017 15:12:24 +0200 Subject: [PATCH 2/3] Change some helps to suggestions --- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_errors/diagnostic.rs | 12 ++++ src/librustc_errors/emitter.rs | 2 +- src/librustc_resolve/lib.rs | 20 +++--- src/librustc_resolve/macros.rs | 5 +- src/librustc_typeck/check/cast.rs | 4 +- src/librustc_typeck/check/op.rs | 2 +- src/libsyntax/parse/parser.rs | 4 +- src/test/ui-fulldeps/resolve-error.stderr | 68 ++++++++----------- ...-to-unsized-trait-object-suggestion.stderr | 6 +- src/test/ui/issue-35675.stderr | 51 +++++++------- .../issue-40402-1.stderr | 2 +- src/test/ui/macros/macro-name-typo.stderr | 6 +- src/test/ui/macros/macro_undefined.stderr | 6 +- .../ui/mismatched_types/issue-19109.stderr | 2 +- src/test/ui/resolve-error.stderr | 28 ++------ src/test/ui/resolve/issue-14254.stderr | 38 +++++------ src/test/ui/resolve/issue-2356.stderr | 12 ++-- .../resolve/resolve-assoc-suggestions.stderr | 6 +- .../resolve-speculative-adjustment.stderr | 4 +- .../ui/resolve/token-error-correct-3.stderr | 2 +- .../unresolved_static_type_field.stderr | 2 +- src/test/ui/span/issue-39018.stderr | 2 +- src/test/ui/span/suggestion-non-ascii.stderr | 2 +- .../ui/suggestions/tuple-float-index.stderr | 2 +- .../ui/type-check/assignment-in-if.stderr | 8 +-- 26 files changed, 139 insertions(+), 159 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 3be7c43cab938..1bfc5805bc8fd 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -991,7 +991,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { .span_suggestion(err.span, &format!("to force the closure to take ownership of {} \ (and any other referenced variables), \ - use the `move` keyword, as shown:", + use the `move` keyword", cmt_path_or_string), suggestion) .emit(); diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index d7c21127474a4..ee07b6e909f7d 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -211,6 +211,18 @@ impl Diagnostic { /// Prints out a message with a suggested edit of the code. /// + /// In case of short messages and a simple suggestion, + /// rustc displays it as a label like + /// + /// "try adding parentheses: `(tup.0).1`" + /// + /// The message + /// * should not end in any punctuation (a `:` is added automatically) + /// * should not be a question + /// * should not contain any parts like "the following", "as shown" + /// * may look like "to do xyz, use" or "to do xyz, use abc" + /// * may contain a name of a function, variable or type, but not whole expressions + /// /// See `diagnostic::CodeSuggestion` for more information. pub fn span_suggestion(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self { self.suggestions.push(CodeSuggestion { diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 2aea6d125f201..3e8bd093f4f93 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -51,7 +51,7 @@ impl Emitter for EmitterWriter { // This substitution is only removal, don't show it format!("help: {}", sugg.msg) } else { - format!("help: {} `{}`", sugg.msg, substitution) + format!("help: {}: `{}`", sugg.msg, substitution) }; primary_span.push_span_label(sugg.substitution_spans().next().unwrap(), msg); } else { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 7754cd7366ecf..49e6929aeef1d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2409,13 +2409,15 @@ impl<'a> Resolver<'a> { .map(|suggestion| import_candidate_to_paths(&suggestion)).collect::>(); enum_candidates.sort(); for (sp, variant_path, enum_path) in enum_candidates { - let msg = format!("there is an enum variant `{}`, did you mean to use `{}`?", - variant_path, - enum_path); if sp == DUMMY_SP { + let msg = format!("there is an enum variant `{}`, \ + try using `{}`?", + variant_path, + enum_path); err.help(&msg); } else { - err.span_help(sp, &msg); + err.span_suggestion(span, "you can try using the variant's enum", + enum_path); } } } @@ -2424,18 +2426,20 @@ impl<'a> Resolver<'a> { let self_is_available = this.self_value_is_available(path[0].ctxt, span); match candidate { AssocSuggestion::Field => { - err.span_label(span, format!("did you mean `self.{}`?", path_str)); + err.span_suggestion(span, "try", + format!("self.{}", path_str)); if !self_is_available { err.span_label(span, format!("`self` value is only available in \ methods with `self` parameter")); } } AssocSuggestion::MethodWithSelf if self_is_available => { - err.span_label(span, format!("did you mean `self.{}(...)`?", - path_str)); + err.span_suggestion(span, "try", + format!("self.{}", path_str)); } AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => { - err.span_label(span, format!("did you mean `Self::{}`?", path_str)); + err.span_suggestion(span, "try", + format!("Self::{}", path_str)); } } return err; diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 0fbc596f2e1c2..a993aca92dd12 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -658,9 +658,10 @@ impl<'a> Resolver<'a> { if let Some(suggestion) = suggestion { if suggestion != name { if let MacroKind::Bang = kind { - err.help(&format!("did you mean `{}!`?", suggestion)); + err.span_suggestion(span, "you could try the macro", + format!("{}!", suggestion)); } else { - err.help(&format!("did you mean `{}`?", suggestion)); + err.span_suggestion(span, "try", suggestion.to_string()); } } else { err.help("have you added the `#[macro_use]` on the module/import?"); diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 7bd24c939caf0..b3f62de5b570b 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -253,7 +253,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { match fcx.tcx.sess.codemap().span_to_snippet(self.cast_span) { Ok(s) => { err.span_suggestion(self.cast_span, - "try casting to a reference instead:", + "try casting to a reference instead", format!("&{}{}", mtstr, s)); } Err(_) => { @@ -272,7 +272,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { match fcx.tcx.sess.codemap().span_to_snippet(self.cast_span) { Ok(s) => { err.span_suggestion(self.cast_span, - "try casting to a `Box` instead:", + "try casting to a `Box` instead", format!("Box<{}>", s)); } Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr), diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 4d69b37b113cf..032e37a34a887 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -320,7 +320,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { from a string reference. String concatenation \ appends the string on the right to the string \ on the left and may require reallocation. This \ - requires ownership of the string on the left."), suggestion); + requires ownership of the string on the left"), suggestion); is_string_addition = true; } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 74b2ea1df323a..90d9ae383a491 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1490,7 +1490,7 @@ impl<'a> Parser<'a> { s.print_bounds(" +", &bounds)?; s.pclose() }); - err.span_suggestion(sum_span, "try adding parentheses:", sum_with_parens); + err.span_suggestion(sum_span, "try adding parentheses", sum_with_parens); } TyKind::Ptr(..) | TyKind::BareFn(..) => { err.span_label(sum_span, "perhaps you forgot parentheses?"); @@ -5280,7 +5280,7 @@ impl<'a> Parser<'a> { `pub(in path::to::module)`: visible only on the specified path"##; let path = self.parse_path(PathStyle::Mod)?; let path_span = self.prev_span; - let help_msg = format!("make this visible only to module `{}` with `in`:", path); + let help_msg = format!("make this visible only to module `{}` with `in`", path); self.expect(&token::CloseDelim(token::Paren))?; // `)` let mut err = self.span_fatal_help(path_span, msg, suggestion); err.span_suggestion(path_span, &help_msg, format!("in {}", path)); diff --git a/src/test/ui-fulldeps/resolve-error.stderr b/src/test/ui-fulldeps/resolve-error.stderr index cfc15d69feb63..754f6bc4f1c1c 100644 --- a/src/test/ui-fulldeps/resolve-error.stderr +++ b/src/test/ui-fulldeps/resolve-error.stderr @@ -1,76 +1,62 @@ error: cannot find derive macro `FooWithLongNan` in this scope - --> $DIR/resolve-error.rs:36:10 + --> $DIR/resolve-error.rs:37:10 | -36 | #[derive(FooWithLongNan)] - | ^^^^^^^^^^^^^^ - | - = help: did you mean `FooWithLongName`? +37 | #[derive(FooWithLongNan)] + | ^^^^^^^^^^^^^^ help: try: `FooWithLongName` error: cannot find attribute macro `attr_proc_macra` in this scope - --> $DIR/resolve-error.rs:39:3 - | -39 | #[attr_proc_macra] - | ^^^^^^^^^^^^^^^ + --> $DIR/resolve-error.rs:40:3 | - = help: did you mean `attr_proc_macro`? +40 | #[attr_proc_macra] + | ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro` error: cannot find attribute macro `FooWithLongNan` in this scope - --> $DIR/resolve-error.rs:42:3 + --> $DIR/resolve-error.rs:43:3 | -42 | #[FooWithLongNan] +43 | #[FooWithLongNan] | ^^^^^^^^^^^^^^ error: cannot find derive macro `Dlone` in this scope - --> $DIR/resolve-error.rs:45:10 + --> $DIR/resolve-error.rs:46:10 | -45 | #[derive(Dlone)] - | ^^^^^ - | - = help: did you mean `Clone`? +46 | #[derive(Dlone)] + | ^^^^^ help: try: `Clone` error: cannot find derive macro `Dlona` in this scope - --> $DIR/resolve-error.rs:48:10 - | -48 | #[derive(Dlona)] - | ^^^^^ + --> $DIR/resolve-error.rs:49:10 | - = help: did you mean `Clona`? +49 | #[derive(Dlona)] + | ^^^^^ help: try: `Clona` error: cannot find derive macro `attr_proc_macra` in this scope - --> $DIR/resolve-error.rs:51:10 + --> $DIR/resolve-error.rs:52:10 | -51 | #[derive(attr_proc_macra)] +52 | #[derive(attr_proc_macra)] | ^^^^^^^^^^^^^^^ error: cannot find macro `FooWithLongNama!` in this scope - --> $DIR/resolve-error.rs:55:5 + --> $DIR/resolve-error.rs:56:5 | -55 | FooWithLongNama!(); - | ^^^^^^^^^^^^^^^ - | - = help: did you mean `FooWithLongNam!`? +56 | FooWithLongNama!(); + | ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam!` error: cannot find macro `attr_proc_macra!` in this scope - --> $DIR/resolve-error.rs:57:5 - | -57 | attr_proc_macra!(); - | ^^^^^^^^^^^^^^^ + --> $DIR/resolve-error.rs:58:5 | - = help: did you mean `attr_proc_mac!`? +58 | attr_proc_macra!(); + | ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac!` error: cannot find macro `Dlona!` in this scope - --> $DIR/resolve-error.rs:59:5 + --> $DIR/resolve-error.rs:60:5 | -59 | Dlona!(); +60 | Dlona!(); | ^^^^^ error: cannot find macro `bang_proc_macrp!` in this scope - --> $DIR/resolve-error.rs:61:5 - | -61 | bang_proc_macrp!(); - | ^^^^^^^^^^^^^^^ + --> $DIR/resolve-error.rs:62:5 | - = help: did you mean `bang_proc_macro!`? +62 | bang_proc_macrp!(); + | ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro!` error: aborting due to 10 previous errors diff --git a/src/test/ui/cast-to-unsized-trait-object-suggestion.stderr b/src/test/ui/cast-to-unsized-trait-object-suggestion.stderr index dd9c2d14ef24e..4d4eb7b4ecfdb 100644 --- a/src/test/ui/cast-to-unsized-trait-object-suggestion.stderr +++ b/src/test/ui/cast-to-unsized-trait-object-suggestion.stderr @@ -1,4 +1,4 @@ -error: cast to unsized type: `&{integer}` as `std::marker::Send` +error[E0620]: cast to unsized type: `&{integer}` as `std::marker::Send` --> $DIR/cast-to-unsized-trait-object-suggestion.rs:12:5 | 12 | &1 as Send; @@ -6,7 +6,7 @@ error: cast to unsized type: `&{integer}` as `std::marker::Send` | | | help: try casting to a reference instead: `&Send` -error: cast to unsized type: `std::boxed::Box<{integer}>` as `std::marker::Send` +error[E0620]: cast to unsized type: `std::boxed::Box<{integer}>` as `std::marker::Send` --> $DIR/cast-to-unsized-trait-object-suggestion.rs:13:5 | 13 | Box::new(1) as Send; @@ -14,5 +14,5 @@ error: cast to unsized type: `std::boxed::Box<{integer}>` as `std::marker::Send` | | | help: try casting to a `Box` instead: `Box` -error: aborting due to previous error(s) +error: aborting due to 2 previous errors diff --git a/src/test/ui/issue-35675.stderr b/src/test/ui/issue-35675.stderr index 22322a388c5f2..36fdbe986262c 100644 --- a/src/test/ui/issue-35675.stderr +++ b/src/test/ui/issue-35675.stderr @@ -2,13 +2,10 @@ error[E0412]: cannot find type `Apple` in this scope --> $DIR/issue-35675.rs:20:29 | 20 | fn should_return_fruit() -> Apple { - | ^^^^^ not found in this scope - | -help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`? - --> $DIR/issue-35675.rs:14:5 - | -14 | Apple(i64), - | ^^^^^^^^^^ + | ^^^^^ + | | + | not found in this scope + | help: you can try using the variant's enum: `Fruit` error[E0425]: cannot find function `Apple` in this scope --> $DIR/issue-35675.rs:23:5 @@ -17,19 +14,18 @@ error[E0425]: cannot find function `Apple` in this scope | ^^^^^ not found in this scope | help: possible candidate is found in another module, you can import it into scope - | use Fruit::Apple; + | +12 | use Fruit::Apple; + | error[E0573]: expected type, found variant `Fruit::Apple` --> $DIR/issue-35675.rs:28:33 | 28 | fn should_return_fruit_too() -> Fruit::Apple { - | ^^^^^^^^^^^^ not a type - | -help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`? - --> $DIR/issue-35675.rs:14:5 - | -14 | Apple(i64), - | ^^^^^^^^^^ + | ^^^^^^^^^^^^ + | | + | not a type + | help: you can try using the variant's enum: `Fruit` error[E0425]: cannot find function `Apple` in this scope --> $DIR/issue-35675.rs:31:5 @@ -38,7 +34,9 @@ error[E0425]: cannot find function `Apple` in this scope | ^^^^^ not found in this scope | help: possible candidate is found in another module, you can import it into scope - | use Fruit::Apple; + | +12 | use Fruit::Apple; + | error[E0573]: expected type, found variant `Ok` --> $DIR/issue-35675.rs:36:13 @@ -46,20 +44,17 @@ error[E0573]: expected type, found variant `Ok` 36 | fn foo() -> Ok { | ^^ not a type | - = help: there is an enum variant `std::prelude::v1::Ok`, did you mean to use `std::prelude::v1`? - = help: there is an enum variant `std::prelude::v1::Result::Ok`, did you mean to use `std::prelude::v1::Result`? + = help: there is an enum variant `std::prelude::v1::Ok`, try using `std::prelude::v1`? + = help: there is an enum variant `std::result::Result::Ok`, try using `std::result::Result`? error[E0412]: cannot find type `Variant3` in this scope --> $DIR/issue-35675.rs:44:13 | 44 | fn bar() -> Variant3 { - | ^^^^^^^^ not found in this scope - | -help: there is an enum variant `x::Enum::Variant3`, did you mean to use `x::Enum`? - --> $DIR/issue-35675.rs:63:9 - | -63 | Variant3(usize), - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^ + | | + | not found in this scope + | help: you can try using the variant's enum: `x::Enum` error[E0573]: expected type, found variant `Some` --> $DIR/issue-35675.rs:49:13 @@ -67,8 +62,8 @@ error[E0573]: expected type, found variant `Some` 49 | fn qux() -> Some { | ^^^^ not a type | - = help: there is an enum variant `std::option::Option::Some`, did you mean to use `std::option::Option`? - = help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`? + = help: there is an enum variant `std::option::Option::Some`, try using `std::option::Option`? + = help: there is an enum variant `std::prelude::v1::Some`, try using `std::prelude::v1`? -error: aborting due to previous error(s) +error: aborting due to 7 previous errors diff --git a/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr b/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr index de110ac12b703..26f150811b7db 100644 --- a/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr +++ b/src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr @@ -4,7 +4,7 @@ error[E0507]: cannot move out of indexed content 19 | let e = f.v[0]; | ^^^^^^ | | - | help: consider using a reference instead `&f.v[0]` + | help: consider using a reference instead: `&f.v[0]` | cannot move out of indexed content error: aborting due to previous error diff --git a/src/test/ui/macros/macro-name-typo.stderr b/src/test/ui/macros/macro-name-typo.stderr index c54de468d133f..7c83250fe8ada 100644 --- a/src/test/ui/macros/macro-name-typo.stderr +++ b/src/test/ui/macros/macro-name-typo.stderr @@ -2,9 +2,7 @@ error: cannot find macro `printlx!` in this scope --> $DIR/macro-name-typo.rs:12:5 | 12 | printlx!("oh noes!"); - | ^^^^^^^ - | - = help: did you mean `println!`? + | ^^^^^^^ help: you could try the macro: `println!` -error: aborting due to previous error(s) +error: aborting due to previous error diff --git a/src/test/ui/macros/macro_undefined.stderr b/src/test/ui/macros/macro_undefined.stderr index 152de056991c8..5c33ae99734e8 100644 --- a/src/test/ui/macros/macro_undefined.stderr +++ b/src/test/ui/macros/macro_undefined.stderr @@ -10,9 +10,7 @@ error: cannot find macro `k!` in this scope --> $DIR/macro_undefined.rs:21:5 | 21 | k!(); - | ^ - | - = help: did you mean `kl!`? + | ^ help: you could try the macro: `kl!` -error: aborting due to previous error(s) +error: aborting due to 2 previous errors diff --git a/src/test/ui/mismatched_types/issue-19109.stderr b/src/test/ui/mismatched_types/issue-19109.stderr index 2b4b8242af6fb..2d8d557d9f35f 100644 --- a/src/test/ui/mismatched_types/issue-19109.stderr +++ b/src/test/ui/mismatched_types/issue-19109.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-19109.rs:14:5 | 13 | fn function(t: &mut Trait) { - | - help: possibly return type missing here? `-> *mut Trait ` + | - help: possibly return type missing here?: `-> *mut Trait ` 14 | t as *mut Trait | ^^^^^^^^^^^^^^^ expected (), found *-ptr | diff --git a/src/test/ui/resolve-error.stderr b/src/test/ui/resolve-error.stderr index 946eaba45fc13..27f93939246c0 100644 --- a/src/test/ui/resolve-error.stderr +++ b/src/test/ui/resolve-error.stderr @@ -2,17 +2,13 @@ error: cannot find derive macro `FooWithLongNan` in this scope --> $DIR/resolve-error.rs:37:10 | 37 | #[derive(FooWithLongNan)] - | ^^^^^^^^^^^^^^ - | - = help: did you mean `FooWithLongName`? + | ^^^^^^^^^^^^^^ help: try: `FooWithLongName` error: cannot find attribute macro `attr_proc_macra` in this scope --> $DIR/resolve-error.rs:40:3 | 40 | #[attr_proc_macra] - | ^^^^^^^^^^^^^^^ - | - = help: did you mean `attr_proc_macro`? + | ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro` error: cannot find attribute macro `FooWithLongNan` in this scope --> $DIR/resolve-error.rs:43:3 @@ -24,17 +20,13 @@ error: cannot find derive macro `Dlone` in this scope --> $DIR/resolve-error.rs:46:10 | 46 | #[derive(Dlone)] - | ^^^^^ - | - = help: did you mean `Clone`? + | ^^^^^ help: try: `Clone` error: cannot find derive macro `Dlona` in this scope --> $DIR/resolve-error.rs:49:10 | 49 | #[derive(Dlona)] - | ^^^^^ - | - = help: did you mean `Clona`? + | ^^^^^ help: try: `Clona` error: cannot find derive macro `attr_proc_macra` in this scope --> $DIR/resolve-error.rs:52:10 @@ -46,17 +38,13 @@ error: cannot find macro `FooWithLongNama!` in this scope --> $DIR/resolve-error.rs:56:5 | 56 | FooWithLongNama!(); - | ^^^^^^^^^^^^^^^ - | - = help: did you mean `FooWithLongNam!`? + | ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam!` error: cannot find macro `attr_proc_macra!` in this scope --> $DIR/resolve-error.rs:58:5 | 58 | attr_proc_macra!(); - | ^^^^^^^^^^^^^^^ - | - = help: did you mean `attr_proc_mac!`? + | ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac!` error: cannot find macro `Dlona!` in this scope --> $DIR/resolve-error.rs:60:5 @@ -68,9 +56,7 @@ error: cannot find macro `bang_proc_macrp!` in this scope --> $DIR/resolve-error.rs:62:5 | 62 | bang_proc_macrp!(); - | ^^^^^^^^^^^^^^^ - | - = help: did you mean `bang_proc_macro!`? + | ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro!` error: aborting due to previous error(s) diff --git a/src/test/ui/resolve/issue-14254.stderr b/src/test/ui/resolve/issue-14254.stderr index 11268e593c413..7aa0c2707b56f 100644 --- a/src/test/ui/resolve/issue-14254.stderr +++ b/src/test/ui/resolve/issue-14254.stderr @@ -2,7 +2,7 @@ error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:29:9 | 29 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `a` in this scope --> $DIR/issue-14254.rs:32:9 @@ -14,19 +14,19 @@ error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:40:9 | 40 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `x` in this scope --> $DIR/issue-14254.rs:43:9 | 43 | x; - | ^ did you mean `self.x`? + | ^ help: try: `self.x` error[E0425]: cannot find value `y` in this scope --> $DIR/issue-14254.rs:46:9 | 46 | y; - | ^ did you mean `self.y`? + | ^ help: try: `self.y` error[E0425]: cannot find value `a` in this scope --> $DIR/issue-14254.rs:49:9 @@ -38,7 +38,7 @@ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:52:9 | 52 | bah; - | ^^^ did you mean `Self::bah`? + | ^^^ help: try: `Self::bah` error[E0425]: cannot find value `b` in this scope --> $DIR/issue-14254.rs:55:9 @@ -50,19 +50,19 @@ error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:63:9 | 63 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `x` in this scope --> $DIR/issue-14254.rs:66:9 | 66 | x; - | ^ did you mean `self.x`? + | ^ help: try: `self.x` error[E0425]: cannot find value `y` in this scope --> $DIR/issue-14254.rs:69:9 | 69 | y; - | ^ did you mean `self.y`? + | ^ help: try: `self.y` error[E0425]: cannot find value `a` in this scope --> $DIR/issue-14254.rs:72:9 @@ -74,7 +74,7 @@ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:75:9 | 75 | bah; - | ^^^ did you mean `Self::bah`? + | ^^^ help: try: `Self::bah` error[E0425]: cannot find value `b` in this scope --> $DIR/issue-14254.rs:78:9 @@ -86,61 +86,61 @@ error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:86:9 | 86 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:89:9 | 89 | bah; - | ^^^ did you mean `Self::bah`? + | ^^^ help: try: `Self::bah` error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:97:9 | 97 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:100:9 | 100 | bah; - | ^^^ did you mean `Self::bah`? + | ^^^ help: try: `Self::bah` error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:108:9 | 108 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:111:9 | 111 | bah; - | ^^^ did you mean `Self::bah`? + | ^^^ help: try: `Self::bah` error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:119:9 | 119 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:122:9 | 122 | bah; - | ^^^ did you mean `Self::bah`? + | ^^^ help: try: `Self::bah` error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:130:9 | 130 | baz(); - | ^^^ did you mean `self.baz(...)`? + | ^^^ help: try: `self.baz` error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:133:9 | 133 | bah; - | ^^^ did you mean `Self::bah`? + | ^^^ help: try: `Self::bah` error[E0601]: main function not found diff --git a/src/test/ui/resolve/issue-2356.stderr b/src/test/ui/resolve/issue-2356.stderr index 039887d8da65f..9c683f4418972 100644 --- a/src/test/ui/resolve/issue-2356.stderr +++ b/src/test/ui/resolve/issue-2356.stderr @@ -8,13 +8,13 @@ error[E0425]: cannot find function `clone` in this scope --> $DIR/issue-2356.rs:35:5 | 35 | clone(); - | ^^^^^ did you mean `self.clone(...)`? + | ^^^^^ help: try: `self.clone` error[E0425]: cannot find function `default` in this scope --> $DIR/issue-2356.rs:43:5 | 43 | default(); - | ^^^^^^^ did you mean `Self::default`? + | ^^^^^^^ help: try: `Self::default` error[E0425]: cannot find value `whiskers` in this scope --> $DIR/issue-2356.rs:52:5 @@ -22,14 +22,14 @@ error[E0425]: cannot find value `whiskers` in this scope 52 | whiskers -= other; | ^^^^^^^^ | | - | did you mean `self.whiskers`? + | help: try: `self.whiskers` | `self` value is only available in methods with `self` parameter error[E0425]: cannot find function `shave` in this scope --> $DIR/issue-2356.rs:57:5 | 57 | shave(4); - | ^^^^^ did you mean `Self::shave`? + | ^^^^^ help: try: `Self::shave` error[E0425]: cannot find function `purr` in this scope --> $DIR/issue-2356.rs:60:5 @@ -83,7 +83,7 @@ error[E0425]: cannot find value `whiskers` in this scope --> $DIR/issue-2356.rs:104:5 | 104 | whiskers = 0; - | ^^^^^^^^ did you mean `self.whiskers`? + | ^^^^^^^^ help: try: `self.whiskers` error[E0425]: cannot find value `whiskers` in this scope --> $DIR/issue-2356.rs:110:5 @@ -91,7 +91,7 @@ error[E0425]: cannot find value `whiskers` in this scope 110 | whiskers = 4; | ^^^^^^^^ | | - | did you mean `self.whiskers`? + | help: try: `self.whiskers` | `self` value is only available in methods with `self` parameter error[E0425]: cannot find function `purr_louder` in this scope diff --git a/src/test/ui/resolve/resolve-assoc-suggestions.stderr b/src/test/ui/resolve/resolve-assoc-suggestions.stderr index 7975c168de7d4..77aa545e2ad6b 100644 --- a/src/test/ui/resolve/resolve-assoc-suggestions.stderr +++ b/src/test/ui/resolve/resolve-assoc-suggestions.stderr @@ -14,13 +14,13 @@ error[E0425]: cannot find value `field` in this scope --> $DIR/resolve-assoc-suggestions.rs:32:9 | 32 | field; - | ^^^^^ did you mean `self.field`? + | ^^^^^ help: try: `self.field` error[E0412]: cannot find type `Type` in this scope --> $DIR/resolve-assoc-suggestions.rs:36:16 | 36 | let _: Type; - | ^^^^ did you mean `Self::Type`? + | ^^^^ help: try: `Self::Type` error[E0531]: cannot find tuple struct/variant `Type` in this scope --> $DIR/resolve-assoc-suggestions.rs:39:13 @@ -50,7 +50,7 @@ error[E0425]: cannot find value `method` in this scope --> $DIR/resolve-assoc-suggestions.rs:52:9 | 52 | method; - | ^^^^^^ did you mean `self.method(...)`? + | ^^^^^^ help: try: `self.method` error: aborting due to 9 previous errors diff --git a/src/test/ui/resolve/resolve-speculative-adjustment.stderr b/src/test/ui/resolve/resolve-speculative-adjustment.stderr index e7df8140bc577..3e1b075679a50 100644 --- a/src/test/ui/resolve/resolve-speculative-adjustment.stderr +++ b/src/test/ui/resolve/resolve-speculative-adjustment.stderr @@ -14,13 +14,13 @@ error[E0425]: cannot find value `field` in this scope --> $DIR/resolve-speculative-adjustment.rs:35:9 | 35 | field; - | ^^^^^ did you mean `self.field`? + | ^^^^^ help: try: `self.field` error[E0425]: cannot find function `method` in this scope --> $DIR/resolve-speculative-adjustment.rs:38:9 | 38 | method(); - | ^^^^^^ did you mean `self.method(...)`? + | ^^^^^^ help: try: `self.method` error: aborting due to 4 previous errors diff --git a/src/test/ui/resolve/token-error-correct-3.stderr b/src/test/ui/resolve/token-error-correct-3.stderr index bd3bdf35da609..2e8cc40dc5175 100644 --- a/src/test/ui/resolve/token-error-correct-3.stderr +++ b/src/test/ui/resolve/token-error-correct-3.stderr @@ -35,7 +35,7 @@ error[E0308]: mismatched types --> $DIR/token-error-correct-3.rs:25:13 | 25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: did you mean to add a semicolon here? `;` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: did you mean to add a semicolon here?: `;` | | | expected (), found enum `std::result::Result` | diff --git a/src/test/ui/resolve/unresolved_static_type_field.stderr b/src/test/ui/resolve/unresolved_static_type_field.stderr index 5fbaf66e014af..e598851e3628e 100644 --- a/src/test/ui/resolve/unresolved_static_type_field.stderr +++ b/src/test/ui/resolve/unresolved_static_type_field.stderr @@ -4,7 +4,7 @@ error[E0425]: cannot find value `cx` in this scope 19 | f(cx); | ^^ | | - | did you mean `self.cx`? + | help: try: `self.cx` | `self` value is only available in methods with `self` parameter error: aborting due to previous error diff --git a/src/test/ui/span/issue-39018.stderr b/src/test/ui/span/issue-39018.stderr index a0445eaee9162..d87fc122d8ee2 100644 --- a/src/test/ui/span/issue-39018.stderr +++ b/src/test/ui/span/issue-39018.stderr @@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&'static str` 12 | let x = "Hello " + "World!"; | ^^^^^^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings | -help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left. +help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | 12 | let x = "Hello ".to_owned() + "World!"; | ^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/span/suggestion-non-ascii.stderr b/src/test/ui/span/suggestion-non-ascii.stderr index c2ab7542d8a98..c67a8fe32b9dd 100644 --- a/src/test/ui/span/suggestion-non-ascii.stderr +++ b/src/test/ui/span/suggestion-non-ascii.stderr @@ -2,7 +2,7 @@ error[E0608]: cannot index into a value of type `({integer},)` --> $DIR/suggestion-non-ascii.rs:14:21 | 14 | println!("☃{}", tup[0]); - | ^^^^^^ help: to access tuple elements, use `tup.0` + | ^^^^^^ help: to access tuple elements, use: `tup.0` error: aborting due to previous error diff --git a/src/test/ui/suggestions/tuple-float-index.stderr b/src/test/ui/suggestions/tuple-float-index.stderr index 8a121b1453662..4b1be26c86b0e 100644 --- a/src/test/ui/suggestions/tuple-float-index.stderr +++ b/src/test/ui/suggestions/tuple-float-index.stderr @@ -5,7 +5,7 @@ error: unexpected token: `1.1` | ------------^^^ | | | | | unexpected token - | help: try parenthesizing the first index `((1, (2, 3)).1).1` + | help: try parenthesizing the first index: `((1, (2, 3)).1).1` error: aborting due to previous error diff --git a/src/test/ui/type-check/assignment-in-if.stderr b/src/test/ui/type-check/assignment-in-if.stderr index a077f37eae6ee..b740a1b776f75 100644 --- a/src/test/ui/type-check/assignment-in-if.stderr +++ b/src/test/ui/type-check/assignment-in-if.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types 25 | if x = x { | ^^^^^ | | - | help: did you mean to compare equality? `x == x` + | help: did you mean to compare equality?: `x == x` | expected bool, found () | = note: expected type `bool` @@ -16,7 +16,7 @@ error[E0308]: mismatched types 31 | if (x = x) { | ^^^^^^^ | | - | help: did you mean to compare equality? `x == x` + | help: did you mean to compare equality?: `x == x` | expected bool, found () | = note: expected type `bool` @@ -28,7 +28,7 @@ error[E0308]: mismatched types 37 | if y = (Foo { foo: x }) { | ^^^^^^^^^^^^^^^^^^^^ | | - | help: did you mean to compare equality? `y == (Foo { foo: x })` + | help: did you mean to compare equality?: `y == (Foo { foo: x })` | expected bool, found () | = note: expected type `bool` @@ -40,7 +40,7 @@ error[E0308]: mismatched types 43 | if 3 = x { | ^^^^^ | | - | help: did you mean to compare equality? `3 == x` + | help: did you mean to compare equality?: `3 == x` | expected bool, found () | = note: expected type `bool` From eb7f429ea54db7111b9c1570ce08c3851727d2e5 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 17 Jul 2017 10:16:08 +0200 Subject: [PATCH 3/3] Move resolve diagnostic instability to compile-fail The produced paths aren't stable between builds, since reporting paths inside resolve, before resolve is finished might produce paths resolved to type aliases instead of the concrete type. Compile-fail tests can match just parts of messages, so they don't "suffer" from this issue. This is just a workaround, the instability should be fixed in the future. --- src/test/compile-fail/issue-35675.rs | 67 ++++++++++++++++++++++++++++ src/test/ui/issue-35675.rs | 16 ------- src/test/ui/issue-35675.stderr | 24 ++-------- 3 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 src/test/compile-fail/issue-35675.rs diff --git a/src/test/compile-fail/issue-35675.rs b/src/test/compile-fail/issue-35675.rs new file mode 100644 index 0000000000000..c09e56cbc5bca --- /dev/null +++ b/src/test/compile-fail/issue-35675.rs @@ -0,0 +1,67 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// these two HELPs are actually in a new line between this line and the `enum Fruit` line +enum Fruit { //~ HELP possible candidate is found in another module, you can import it into scope + //~^ HELP possible candidate is found in another module, you can import it into scope + Apple(i64), + Orange(i64), +} + +fn should_return_fruit() -> Apple { + //~^ ERROR cannot find type `Apple` in this scope + //~| NOTE not found in this scope + //~| HELP you can try using the variant's enum + Apple(5) + //~^ ERROR cannot find function `Apple` in this scope + //~| NOTE not found in this scope +} + +fn should_return_fruit_too() -> Fruit::Apple { + //~^ ERROR expected type, found variant `Fruit::Apple` + //~| HELP you can try using the variant's enum + //~| NOTE not a type + Apple(5) + //~^ ERROR cannot find function `Apple` in this scope + //~| NOTE not found in this scope +} + +fn foo() -> Ok { + //~^ ERROR expected type, found variant `Ok` + //~| NOTE not a type + //~| HELP there is an enum variant + //~| HELP there is an enum variant + Ok(()) +} + +fn bar() -> Variant3 { + //~^ ERROR cannot find type `Variant3` in this scope + //~| HELP you can try using the variant's enum + //~| NOTE not found in this scope +} + +fn qux() -> Some { + //~^ ERROR expected type, found variant `Some` + //~| NOTE not a type + //~| HELP there is an enum variant + //~| HELP there is an enum variant + Some(1) +} + +fn main() {} + +mod x { + enum Enum { + Variant1, + Variant2(), + Variant3(usize), + Variant4 {}, + } +} diff --git a/src/test/ui/issue-35675.rs b/src/test/ui/issue-35675.rs index 001c1f2eddca1..391e1f2db5c02 100644 --- a/src/test/ui/issue-35675.rs +++ b/src/test/ui/issue-35675.rs @@ -33,27 +33,11 @@ fn should_return_fruit_too() -> Fruit::Apple { //~| NOTE not found in this scope } -fn foo() -> Ok { - //~^ ERROR expected type, found variant `Ok` - //~| NOTE not a type - //~| HELP there is an enum variant - //~| HELP there is an enum variant - Ok(()) -} - fn bar() -> Variant3 { //~^ ERROR cannot find type `Variant3` in this scope //~| NOTE not found in this scope } -fn qux() -> Some { - //~^ ERROR expected type, found variant `Some` - //~| NOTE not a type - //~| HELP there is an enum variant - //~| HELP there is an enum variant - Some(1) -} - fn main() {} mod x { diff --git a/src/test/ui/issue-35675.stderr b/src/test/ui/issue-35675.stderr index 36fdbe986262c..c2c10724646ef 100644 --- a/src/test/ui/issue-35675.stderr +++ b/src/test/ui/issue-35675.stderr @@ -38,32 +38,14 @@ help: possible candidate is found in another module, you can import it into scop 12 | use Fruit::Apple; | -error[E0573]: expected type, found variant `Ok` - --> $DIR/issue-35675.rs:36:13 - | -36 | fn foo() -> Ok { - | ^^ not a type - | - = help: there is an enum variant `std::prelude::v1::Ok`, try using `std::prelude::v1`? - = help: there is an enum variant `std::result::Result::Ok`, try using `std::result::Result`? - error[E0412]: cannot find type `Variant3` in this scope - --> $DIR/issue-35675.rs:44:13 + --> $DIR/issue-35675.rs:36:13 | -44 | fn bar() -> Variant3 { +36 | fn bar() -> Variant3 { | ^^^^^^^^ | | | not found in this scope | help: you can try using the variant's enum: `x::Enum` -error[E0573]: expected type, found variant `Some` - --> $DIR/issue-35675.rs:49:13 - | -49 | fn qux() -> Some { - | ^^^^ not a type - | - = help: there is an enum variant `std::option::Option::Some`, try using `std::option::Option`? - = help: there is an enum variant `std::prelude::v1::Some`, try using `std::prelude::v1`? - -error: aborting due to 7 previous errors +error: aborting due to 5 previous errors