mirror of https://github.com/rust-lang/rust.git
Tweak wording of "implemented trait isn't imported" suggestion
This commit is contained in:
parent
14277ef201
commit
caa216d245
|
@ -275,7 +275,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
.span_if_local(def_id)
|
||||
.unwrap_or_else(|| self.tcx.def_span(def_id));
|
||||
err.span_label(sp, format!("private {kind} defined here"));
|
||||
self.suggest_valid_traits(&mut err, out_of_scope_traits, true);
|
||||
self.suggest_valid_traits(&mut err, item_name, out_of_scope_traits, true);
|
||||
err.emit();
|
||||
}
|
||||
|
||||
|
@ -2890,6 +2890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
fn suggest_valid_traits(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
item_name: Ident,
|
||||
valid_out_of_scope_traits: Vec<DefId>,
|
||||
explain: bool,
|
||||
) -> bool {
|
||||
|
@ -2908,9 +2909,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
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" },
|
||||
"{this_trait_is} implemented but not in scope; perhaps you want to import \
|
||||
{one_of_them}",
|
||||
this_trait_is = if candidates.len() == 1 {
|
||||
format!(
|
||||
"trait `{}` which provides `{item_name}` is",
|
||||
self.tcx.item_name(candidates[0]),
|
||||
)
|
||||
} else {
|
||||
format!("the following traits which provide `{item_name}` are")
|
||||
},
|
||||
one_of_them = if candidates.len() == 1 { "it" } else { "one of them" },
|
||||
);
|
||||
|
||||
|
@ -3118,7 +3126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
if self.suggest_valid_traits(err, valid_out_of_scope_traits, true) {
|
||||
if self.suggest_valid_traits(err, item_name, valid_out_of_scope_traits, true) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3404,7 +3412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
[] => {}
|
||||
[trait_info] if trait_info.def_id.is_local() => {
|
||||
if impls_trait(trait_info.def_id) {
|
||||
self.suggest_valid_traits(err, vec![trait_info.def_id], false);
|
||||
self.suggest_valid_traits(err, item_name, vec![trait_info.def_id], false);
|
||||
} else {
|
||||
err.subdiagnostic(
|
||||
self.dcx(),
|
||||
|
@ -3431,7 +3439,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
));
|
||||
for (i, trait_info) in trait_infos.iter().enumerate() {
|
||||
if impls_trait(trait_info.def_id) {
|
||||
self.suggest_valid_traits(err, vec![trait_info.def_id], false);
|
||||
self.suggest_valid_traits(
|
||||
err,
|
||||
item_name,
|
||||
vec![trait_info.def_id],
|
||||
false,
|
||||
);
|
||||
}
|
||||
msg.push_str(&format!(
|
||||
"\ncandidate #{}: `{}`",
|
||||
|
|
|
@ -30,7 +30,7 @@ LL | match fut.as_mut().poll(ctx) {
|
|||
= note: the method is available for `Pin<&mut impl Future<Output = ()>>` here
|
||||
|
|
||||
= 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: trait `Future` which provides `poll` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use std::future::Future;
|
||||
|
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | s.the_fn();
|
|||
| ^^^^^^ method not found in `&TheStruct`
|
||||
|
|
||||
= 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: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use Lib::TheTrait;
|
||||
|
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | s.the_fn();
|
|||
| ^^^^^^ method not found in `&TheStruct`
|
||||
|
|
||||
= 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: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use coherence_inherent_cc_lib::TheTrait;
|
||||
|
|
||||
|
|
|
@ -26,7 +26,7 @@ LL | ().clone()
|
|||
help: there is a method `clone_from` with a similar name, but with different arguments
|
||||
--> $SRC_DIR/core/src/clone.rs:LL:COL
|
||||
= note: this error originates in the macro `::bar::m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `Clone` which provides `clone` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use std::clone::Clone;
|
||||
|
|
||||
|
|
|
@ -12,7 +12,7 @@ LL | pub macro m() { ().f() }
|
|||
|
|
||||
= help: items from traits can only be used if the trait is in scope
|
||||
= note: this error originates in the macro `::baz::m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use foo::T;
|
||||
|
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | 1u32.method();
|
|||
| ^^^^^^
|
||||
|
|
||||
= 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 which provide `method` are implemented but not in scope; perhaps you want to import one of them
|
||||
|
|
||||
LL + use foo::Bar;
|
||||
|
|
||||
|
@ -27,7 +27,7 @@ LL | std::rc::Rc::new(&mut Box::new(&1u32)).method();
|
|||
| ^^^^^^
|
||||
|
|
||||
= 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 which provide `method` are implemented but not in scope; perhaps you want to import one of them
|
||||
|
|
||||
LL + use foo::Bar;
|
||||
|
|
||||
|
@ -52,7 +52,7 @@ LL | 'a'.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: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use foo::Bar;
|
||||
|
|
||||
|
@ -68,7 +68,7 @@ LL | std::rc::Rc::new(&mut Box::new(&'a')).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: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use foo::Bar;
|
||||
|
|
||||
|
@ -89,7 +89,7 @@ LL | fn method(&self) {}
|
|||
| ------ the method is available for `i32` here
|
||||
|
|
||||
= 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: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use no_method_suggested_traits::foo::PubPub;
|
||||
|
|
||||
|
@ -105,7 +105,7 @@ LL | std::rc::Rc::new(&mut Box::new(&1i32)).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: trait `PubPub` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use no_method_suggested_traits::foo::PubPub;
|
||||
|
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* This crate declares two public paths, `m::Tr` and `prelude::_`. Make sure we prefer the former.
|
||||
*/
|
||||
extern crate overlapping_pub_trait_source;
|
||||
//~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
//~^ HELP trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
//~| SUGGESTION overlapping_pub_trait_source::m::Tr
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -10,7 +10,7 @@ LL | pub trait Tr { fn method(&self); }
|
|||
| ------ the method is available for `S` here
|
||||
|
|
||||
= 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: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use overlapping_pub_trait_source::m::Tr;
|
||||
|
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* importing it by name, and instead we suggest importing it by glob.
|
||||
*/
|
||||
extern crate unnamed_pub_trait_source;
|
||||
//~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
//~^ HELP trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
//~| SUGGESTION unnamed_pub_trait_source::prelude::*; // trait Tr
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -10,7 +10,7 @@ LL | pub trait Tr { fn method(&self); }
|
|||
| ------ the method is available for `S` here
|
||||
|
|
||||
= 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: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use unnamed_pub_trait_source::prelude::*; // trait Tr
|
||||
|
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | b.foo();
|
|||
| ^^^ method not found in `&B`
|
||||
|
|
||||
= 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: trait `A` which provides `foo` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use a::A;
|
||||
|
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | Command::new("echo").arg("hello").exec();
|
|||
= help: items from traits can only be used if the trait is in scope
|
||||
help: there is a method `pre_exec` with a similar name, but with different arguments
|
||||
--> $SRC_DIR/std/src/os/unix/process.rs:LL:COL
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `CommandExt` which provides `exec` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use std::os::unix::process::CommandExt;
|
||||
|
|
||||
|
|
|
@ -10,7 +10,7 @@ LL | fn trait_method(&self) {
|
|||
| ------------ the method is available for `FooStruct` here
|
||||
|
|
||||
= 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: trait `Trait` which provides `trait_method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use reexported_trait::Trait;
|
||||
|
|
||||
|
@ -31,7 +31,7 @@ LL | fn trait_method_b(&self) {
|
|||
| -------------- the method is available for `FooStruct` here
|
||||
|
|
||||
= 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: trait `TraitB` which provides `trait_method_b` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use reexported_trait::TraitBRename;
|
||||
|
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | x.foobar();
|
|||
| ^^^^^^
|
||||
|
|
||||
= 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: trait `Foobar` which provides `foobar` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use crate::foo::foobar::Foobar;
|
||||
|
|
||||
|
@ -27,7 +27,7 @@ LL | x.bar();
|
|||
| ^^^
|
||||
|
|
||||
= 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: trait `Bar` which provides `bar` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use crate::foo::Bar;
|
||||
|
|
||||
|
@ -54,7 +54,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: trait `FromStr` which provides `from_str` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use std::str::FromStr;
|
||||
|
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | A::deserialize();
|
|||
| ^^^^^^^^^^^ function or associated item not found in `A`
|
||||
|
|
||||
= 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: trait `Deserialize` which provides `deserialize` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use <crate::A as issue_87932_a::Deserialize>::deserialize::_a::Deserialize;
|
||||
|
|
||||
|
|
|
@ -6,7 +6,7 @@ LL | let _: u32 = 3u8.try_into().unwrap();
|
|||
|
|
||||
= help: items from traits can only be used if the trait is in scope
|
||||
= note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
|
||||
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
|
||||
help: the following traits which provide `try_into` are implemented but not in scope; perhaps you want to import one of them
|
||||
|
|
||||
LL + use crate::m::TryIntoU32;
|
||||
|
|
||||
|
|
|
@ -8,7 +8,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: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use foo::T;
|
||||
|
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod banana {
|
||||
//~^ HELP the following traits are implemented but not in scope
|
||||
//~^ HELP the following traits which provide `pick` are implemented but not in scope
|
||||
pub struct Chaenomeles;
|
||||
|
||||
pub trait Apple {
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | banana::Chaenomeles.pick()
|
|||
| ^^^^ method not found in `Chaenomeles`
|
||||
|
|
||||
= 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 which provide `pick` are implemented but not in scope; perhaps you want to import one of them
|
||||
|
|
||||
LL + use banana::Apple;
|
||||
|
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | h.finish()
|
|||
= note: the method is available for `DefaultHasher` here
|
||||
|
|
||||
= 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: trait `Hasher` which provides `finish` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use std::hash::Hasher;
|
||||
|
|
||||
|
|
|
@ -58,7 +58,7 @@ LL | let _i: i16 = 0_i32.try_into().unwrap();
|
|||
|
|
||||
= help: items from traits can only be used if the trait is in scope
|
||||
= note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `TryInto` which provides `try_into` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use std::convert::TryInto;
|
||||
|
|
||||
|
|
|
@ -11,7 +11,7 @@ LL | pub struct S;
|
|||
| ------------ method `abc` not found for this struct
|
||||
|
|
||||
= 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: trait `Foo` which provides `abc` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use m::Foo;
|
||||
|
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | S.a();
|
|||
| ^
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `A` which provides `a` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use method::A;
|
||||
|
|
||||
|
@ -30,7 +30,7 @@ LL | S.b();
|
|||
| ^
|
||||
|
|
||||
= 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: trait `B` which provides `b` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use method::B;
|
||||
|
|
||||
|
@ -63,7 +63,7 @@ help: there is an associated constant `B` with a similar name
|
|||
|
|
||||
LL | const B: u8 = 0;
|
||||
| ^^^^^^^^^^^
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `A` which provides `a` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use method::A;
|
||||
|
|
||||
|
@ -83,7 +83,7 @@ help: there is an associated constant `B` with a similar name
|
|||
|
|
||||
LL | const B: u8 = 0;
|
||||
| ^^^^^^^^^^^
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `B` which provides `b` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use method::B;
|
||||
|
|
||||
|
@ -107,7 +107,7 @@ LL | S::A;
|
|||
| ^ associated item not found in `S`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `A` which provides `A` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use assoc_const::A;
|
||||
|
|
||||
|
@ -126,7 +126,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: trait `B` which provides `B` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use assoc_const::B;
|
||||
|
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | foo.method();
|
|||
| ^^^^^^ private 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: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use inner::Bar;
|
||||
|
|
||||
|
|
|
@ -10,7 +10,7 @@ LL | fn a(&self) {}
|
|||
| - the method is available for `()` here
|
||||
|
|
||||
= 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: trait `A` which provides `a` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use xcrate_issue_43189_b::xcrate_issue_43189_a::A;
|
||||
|
|
||||
|
|
|
@ -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
|
||||
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
||||
help: trait `Deref` which provides `deref` is implemented but not in scope; perhaps you want to import it
|
||||
|
|
||||
LL + use std::ops::Deref;
|
||||
|
|
||||
|
|
Loading…
Reference in New Issue