diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 2d4d2e32f23..2b34c24b266 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -631,26 +631,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - fn suggest_valid_traits(&self, - err: &mut DiagnosticBuilder<'_>, - valid_out_of_scope_traits: Vec) -> bool { + fn suggest_valid_traits( + &self, + err: &mut DiagnosticBuilder<'_>, + valid_out_of_scope_traits: Vec, + ) -> bool { if !valid_out_of_scope_traits.is_empty() { let mut candidates = valid_out_of_scope_traits; candidates.sort(); candidates.dedup(); err.help("items from traits can only be used if the trait is in scope"); - let msg = format!("the following {traits_are} implemented but not in scope, \ - perhaps add a `use` for {one_of_them}:", - traits_are = if candidates.len() == 1 { - "trait is" - } else { - "traits are" - }, - one_of_them = if candidates.len() == 1 { - "it" - } else { - "one of them" - }); + let msg = format!( + "the following {traits_are} implemented but not in scope; \ + perhaps add a `use` for {one_of_them}:", + traits_are = if candidates.len() == 1 { + "trait is" + } else { + "traits are" + }, + one_of_them = if candidates.len() == 1 { + "it" + } else { + "one of them" + }, + ); self.suggest_use_candidates(err, msg, candidates); true diff --git a/src/test/ui/coherence/coherence_inherent.old.stderr b/src/test/ui/coherence/coherence_inherent.old.stderr index 750d2434806..e71547cb89f 100644 --- a/src/test/ui/coherence/coherence_inherent.old.stderr +++ b/src/test/ui/coherence/coherence_inherent.old.stderr @@ -5,7 +5,7 @@ LL | s.the_fn(); | ^^^^^^ method not found in `&Lib::TheStruct` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use Lib::TheTrait;` error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_inherent.re.stderr b/src/test/ui/coherence/coherence_inherent.re.stderr index 750d2434806..e71547cb89f 100644 --- a/src/test/ui/coherence/coherence_inherent.re.stderr +++ b/src/test/ui/coherence/coherence_inherent.re.stderr @@ -5,7 +5,7 @@ LL | s.the_fn(); | ^^^^^^ method not found in `&Lib::TheStruct` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use Lib::TheTrait;` error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_inherent_cc.old.stderr b/src/test/ui/coherence/coherence_inherent_cc.old.stderr index 59166a46094..3683943c5c8 100644 --- a/src/test/ui/coherence/coherence_inherent_cc.old.stderr +++ b/src/test/ui/coherence/coherence_inherent_cc.old.stderr @@ -5,7 +5,7 @@ LL | s.the_fn(); | ^^^^^^ method not found in `&coherence_inherent_cc_lib::TheStruct` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use coherence_inherent_cc_lib::TheTrait;` error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence_inherent_cc.re.stderr b/src/test/ui/coherence/coherence_inherent_cc.re.stderr index 59166a46094..3683943c5c8 100644 --- a/src/test/ui/coherence/coherence_inherent_cc.re.stderr +++ b/src/test/ui/coherence/coherence_inherent_cc.re.stderr @@ -5,7 +5,7 @@ LL | s.the_fn(); | ^^^^^^ method not found in `&coherence_inherent_cc_lib::TheStruct` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use coherence_inherent_cc_lib::TheTrait;` error: aborting due to previous error diff --git a/src/test/ui/hygiene/no_implicit_prelude.stderr b/src/test/ui/hygiene/no_implicit_prelude.stderr index bc0ce746be9..736369dab83 100644 --- a/src/test/ui/hygiene/no_implicit_prelude.stderr +++ b/src/test/ui/hygiene/no_implicit_prelude.stderr @@ -25,7 +25,7 @@ LL | ().clone() | ^^^^^ method not found in `()` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use std::clone::Clone;` error: aborting due to 3 previous errors diff --git a/src/test/ui/hygiene/trait_items.stderr b/src/test/ui/hygiene/trait_items.stderr index 39e32522c7a..c3ce484edf7 100644 --- a/src/test/ui/hygiene/trait_items.stderr +++ b/src/test/ui/hygiene/trait_items.stderr @@ -8,7 +8,7 @@ LL | pub macro m() { ().f() } | ^ method not found in `()` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use foo::T;` error: aborting due to previous error diff --git a/src/test/ui/impl-trait/no-method-suggested-traits.stderr b/src/test/ui/impl-trait/no-method-suggested-traits.stderr index be8f3ab1b72..f0a03e1be82 100644 --- a/src/test/ui/impl-trait/no-method-suggested-traits.stderr +++ b/src/test/ui/impl-trait/no-method-suggested-traits.stderr @@ -5,7 +5,7 @@ LL | 1u32.method(); | ^^^^^^ method not found in `u32` | = help: items from traits can only be used if the trait is in scope -help: the following traits are implemented but not in scope, perhaps add a `use` for one of them: +help: the following traits are implemented but not in scope; perhaps add a `use` for one of them: | LL | use foo::Bar; | @@ -23,7 +23,7 @@ LL | std::rc::Rc::new(&mut Box::new(&1u32)).method(); | ^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&u32>>` | = help: items from traits can only be used if the trait is in scope -help: the following traits are implemented but not in scope, perhaps add a `use` for one of them: +help: the following traits are implemented but not in scope; perhaps add a `use` for one of them: | LL | use foo::Bar; | @@ -41,7 +41,7 @@ LL | 'a'.method(); | ^^^^^^ method not found in `char` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use foo::Bar; | @@ -61,7 +61,7 @@ LL | std::rc::Rc::new(&mut Box::new(&'a')).method(); | ^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&char>>` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use foo::Bar; | @@ -73,7 +73,7 @@ LL | 1i32.method(); | ^^^^^^ method not found in `i32` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use no_method_suggested_traits::foo::PubPub; | @@ -85,7 +85,7 @@ LL | std::rc::Rc::new(&mut Box::new(&1i32)).method(); | ^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&i32>>` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use no_method_suggested_traits::foo::PubPub; | diff --git a/src/test/ui/issues/issue-10465.stderr b/src/test/ui/issues/issue-10465.stderr index 413daa6db67..80ca051ceff 100644 --- a/src/test/ui/issues/issue-10465.stderr +++ b/src/test/ui/issues/issue-10465.stderr @@ -5,7 +5,7 @@ LL | b.foo(); | ^^^ method not found in `&b::B` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use a::A;` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-39175.stderr b/src/test/ui/issues/issue-39175.stderr index 66680b9936e..8b173e1b50c 100644 --- a/src/test/ui/issues/issue-39175.stderr +++ b/src/test/ui/issues/issue-39175.stderr @@ -5,7 +5,7 @@ LL | Command::new("echo").arg("hello").exec(); | ^^^^ method not found in `&mut std::process::Command` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use std::os::unix::process::CommandExt; | diff --git a/src/test/ui/issues/issue-43189.stderr b/src/test/ui/issues/issue-43189.stderr index 33c3f18650a..4dae6c1cd15 100644 --- a/src/test/ui/issues/issue-43189.stderr +++ b/src/test/ui/issues/issue-43189.stderr @@ -5,7 +5,7 @@ LL | ().a(); | ^ method not found in `()` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use xcrate_issue_43189_b::xcrate_issue_43189_a::A; | diff --git a/src/test/ui/rust-2018/trait-import-suggestions.stderr b/src/test/ui/rust-2018/trait-import-suggestions.stderr index 19f758fd8da..4b1898345a3 100644 --- a/src/test/ui/rust-2018/trait-import-suggestions.stderr +++ b/src/test/ui/rust-2018/trait-import-suggestions.stderr @@ -5,7 +5,7 @@ LL | x.foobar(); | ^^^^^^ method not found in `u32` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use crate::foo::foobar::Foobar;` error[E0599]: no method named `bar` found for type `u32` in the current scope @@ -15,7 +15,7 @@ LL | x.bar(); | ^^^ method not found in `u32` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use crate::foo::Bar; | @@ -33,7 +33,7 @@ LL | let y = u32::from_str("33"); | ^^^^^^^^ function or associated item not found in `u32` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use std::str::FromStr; | diff --git a/src/test/ui/shadowed/shadowed-trait-methods.stderr b/src/test/ui/shadowed/shadowed-trait-methods.stderr index 190159ec7b8..3597cc53420 100644 --- a/src/test/ui/shadowed/shadowed-trait-methods.stderr +++ b/src/test/ui/shadowed/shadowed-trait-methods.stderr @@ -5,7 +5,7 @@ LL | ().f() | ^ method not found in `()` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use foo::T; | diff --git a/src/test/ui/traits/trait-item-privacy.stderr b/src/test/ui/traits/trait-item-privacy.stderr index 39cc66d275c..64a92c6b0b4 100644 --- a/src/test/ui/traits/trait-item-privacy.stderr +++ b/src/test/ui/traits/trait-item-privacy.stderr @@ -28,7 +28,7 @@ LL | S.b(); | ^ method not found in `S` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use method::B; | @@ -62,7 +62,7 @@ LL | S::b(&S); | ^ function or associated item not found in `S` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use method::B; | @@ -96,7 +96,7 @@ LL | S::B; | ^ associated item not found in `S` | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use assoc_const::B; | diff --git a/src/test/ui/traits/trait-method-private.stderr b/src/test/ui/traits/trait-method-private.stderr index c1dd9387ebc..10552acb348 100644 --- a/src/test/ui/traits/trait-method-private.stderr +++ b/src/test/ui/traits/trait-method-private.stderr @@ -5,7 +5,7 @@ LL | foo.method(); | ^^^^^^ | = help: items from traits can only be used if the trait is in scope -help: the following trait is implemented but not in scope, perhaps add a `use` for it: +help: the following trait is implemented but not in scope; perhaps add a `use` for it: | LL | use inner::Bar; | diff --git a/src/test/ui/underscore-imports/shadow.stderr b/src/test/ui/underscore-imports/shadow.stderr index 63262d0dc32..102c17f6f56 100644 --- a/src/test/ui/underscore-imports/shadow.stderr +++ b/src/test/ui/underscore-imports/shadow.stderr @@ -5,7 +5,7 @@ LL | x.deref(); | ^^^^^ method not found in `&()` | = help: items from traits can only be used if the trait is in scope - = note: the following trait is implemented but not in scope, perhaps add a `use` for it: + = note: the following trait is implemented but not in scope; perhaps add a `use` for it: `use std::ops::Deref;` error: aborting due to previous error