From c4b6a5932e48c489eb5510a6516185677ea39a0f Mon Sep 17 00:00:00 2001 From: surechen Date: Mon, 1 Jul 2024 12:57:10 +0800 Subject: [PATCH] Make E0599's label more clear for field which is used like a method. fixes #127178 --- .../rustc_hir_typeck/src/method/suggest.rs | 13 ++++++++--- ...project-to-specializable-projection.stderr | 2 +- tests/ui/coherence/coherence_inherent.stderr | 2 +- .../ui/coherence/coherence_inherent_cc.stderr | 2 +- .../issue-2392.stderr | 20 +++++++++++----- ...method-unsatisfied-assoc-type-predicate.rs | 1 + tests/ui/hygiene/no_implicit_prelude.stderr | 2 +- tests/ui/hygiene/trait_items.stderr | 2 +- ...all_method_without_import.no_import.stderr | 4 ++-- .../impl-trait/no-method-suggested-traits.rs | 4 ++-- .../no-method-suggested-traits.stderr | 12 +++++----- tests/ui/imports/overlapping_pub_trait.rs | 2 +- tests/ui/imports/overlapping_pub_trait.stderr | 2 +- tests/ui/imports/unnamed_pub_trait.rs | 2 +- tests/ui/imports/unnamed_pub_trait.stderr | 2 +- tests/ui/issues/issue-10465.stderr | 2 +- tests/ui/issues/issue-39175.stderr | 2 +- tests/ui/issues/issue-56175.stderr | 4 ++-- ...field-method-suggestion-using-return-ty.rs | 4 ++-- .../rust-2018/trait-import-suggestions.stderr | 6 ++--- .../uniform-paths/issue-87932.stderr | 2 +- .../future-prelude-collision-shadow.stderr | 2 +- .../ui/shadowed/shadowed-trait-methods.stderr | 2 +- .../dont-wrap-ambiguous-receivers.rs | 2 +- .../dont-wrap-ambiguous-receivers.stderr | 2 +- .../import-trait-for-method-call.stderr | 2 +- .../suggest-tryinto-edition-change.stderr | 2 +- .../suggestions/use-placement-typeck.stderr | 2 +- tests/ui/traits/item-privacy.stderr | 6 ++--- tests/ui/traits/method-private.stderr | 2 +- .../suggest-traits-to-import-issue-127178.rs | 23 +++++++++++++++++++ ...ggest-traits-to-import-issue-127178.stderr | 20 ++++++++++++++++ tests/ui/typeck/issue-43189.stderr | 2 +- tests/ui/underscore-imports/shadow.stderr | 2 +- 34 files changed, 110 insertions(+), 51 deletions(-) create mode 100644 tests/ui/traits/suggest-traits-to-import-issue-127178.rs create mode 100644 tests/ui/traits/suggest-traits-to-import-issue-127178.stderr diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 425289ce3c526..09243d4f9b0b5 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -2277,7 +2277,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let call_expr = tcx.hir().expect_expr(tcx.parent_hir_id(expr.hir_id)); if let Some(span) = call_expr.span.trim_start(item_name.span) { - err.span_suggestion( + err.span_suggestion_verbose( span, "remove the arguments", "", @@ -3266,7 +3266,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .copied(); if explain { - err.help("items from traits can only be used if the trait is in scope"); + err.help( + "items from traits can only be used if the trait is implemented and in scope", + ); } let msg = format!( @@ -3570,7 +3572,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - if self.suggest_valid_traits(err, item_name, valid_out_of_scope_traits, true) { + if self.suggest_valid_traits( + err, + item_name, + valid_out_of_scope_traits, + !trait_missing_method, + ) { return; } diff --git a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr index 3d82f572a1a69..56999a7b8cf15 100644 --- a/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr +++ b/tests/ui/async-await/in-trait/dont-project-to-specializable-projection.stderr @@ -29,7 +29,7 @@ LL | match fut.as_mut().poll(ctx) { | = note: the method is available for `Pin<&mut impl Future>` here | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `Future` which provides `poll` is implemented but not in scope; perhaps you want to import it | LL + use std::future::Future; diff --git a/tests/ui/coherence/coherence_inherent.stderr b/tests/ui/coherence/coherence_inherent.stderr index 17b49279de7b6..4a41dd7507f13 100644 --- a/tests/ui/coherence/coherence_inherent.stderr +++ b/tests/ui/coherence/coherence_inherent.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `TheTrait` which provides `the_fn` is implemented but not in scope; perhaps you want to import it | LL + use Lib::TheTrait; diff --git a/tests/ui/coherence/coherence_inherent_cc.stderr b/tests/ui/coherence/coherence_inherent_cc.stderr index b3c1125d63e38..dcfd1b33af769 100644 --- a/tests/ui/coherence/coherence_inherent_cc.stderr +++ b/tests/ui/coherence/coherence_inherent_cc.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `the_fn` found for reference `&TheStruct` in the c LL | s.the_fn(); | ^^^^^^ method not found in `&TheStruct` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope 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; diff --git a/tests/ui/confuse-field-and-method/issue-2392.stderr b/tests/ui/confuse-field-and-method/issue-2392.stderr index 440fbb27c0040..64e3521b46e07 100644 --- a/tests/ui/confuse-field-and-method/issue-2392.stderr +++ b/tests/ui/confuse-field-and-method/issue-2392.stderr @@ -19,9 +19,13 @@ LL | struct Obj where F: FnOnce() -> u32 { | ------------- method `not_closure` not found for this struct ... LL | o_closure.not_closure(); - | ^^^^^^^^^^^-- help: remove the arguments - | | - | field, not a method + | ^^^^^^^^^^^ field, not a method + | +help: remove the arguments + | +LL - o_closure.not_closure(); +LL + o_closure.not_closure; + | error[E0599]: no method named `closure` found for struct `Obj` in the current scope --> $DIR/issue-2392.rs:42:12 @@ -86,9 +90,13 @@ LL | struct Obj where F: FnOnce() -> u32 { | ------------- method `not_closure` not found for this struct ... LL | w.wrap.not_closure(); - | ^^^^^^^^^^^-- help: remove the arguments - | | - | field, not a method + | ^^^^^^^^^^^ field, not a method + | +help: remove the arguments + | +LL - w.wrap.not_closure(); +LL + w.wrap.not_closure; + | error[E0599]: no method named `closure` found for struct `Obj` in the current scope --> $DIR/issue-2392.rs:58:24 diff --git a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs index 92ce4a0970f36..e6afd81e4a74d 100644 --- a/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs +++ b/tests/ui/generic-associated-types/method-unsatisfied-assoc-type-predicate.rs @@ -26,6 +26,7 @@ fn f(a: S) { a.f(); //~^ ERROR the method `f` exists for struct `S`, but its trait bounds were not satisfied //~| NOTE method cannot be called on `S` due to unsatisfied trait bounds + //~| HELP items from traits can only be used if the trait is implemented and in scope } fn main() {} diff --git a/tests/ui/hygiene/no_implicit_prelude.stderr b/tests/ui/hygiene/no_implicit_prelude.stderr index 5de6e3db327b1..7e6c8c7142a94 100644 --- a/tests/ui/hygiene/no_implicit_prelude.stderr +++ b/tests/ui/hygiene/no_implicit_prelude.stderr @@ -22,7 +22,7 @@ LL | fn f() { ::bar::m!(); } LL | ().clone() | ^^^^^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope 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) diff --git a/tests/ui/hygiene/trait_items.stderr b/tests/ui/hygiene/trait_items.stderr index 0e276bf69d6ec..1a56e4e8cc136 100644 --- a/tests/ui/hygiene/trait_items.stderr +++ b/tests/ui/hygiene/trait_items.stderr @@ -10,7 +10,7 @@ LL | fn f() { ::baz::m!(); } LL | pub macro m() { ().f() } | ^ method not found in `()` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope = note: this error originates in the macro `::baz::m` (in Nightly builds, run with -Z macro-backtrace for more info) help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/impl-trait/call_method_without_import.no_import.stderr b/tests/ui/impl-trait/call_method_without_import.no_import.stderr index 72982b695bbb0..c4a2501dd1b71 100644 --- a/tests/ui/impl-trait/call_method_without_import.no_import.stderr +++ b/tests/ui/impl-trait/call_method_without_import.no_import.stderr @@ -7,7 +7,7 @@ LL | x.fmt(f); | = note: the method is available for `impl Debug` here | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `Debug` which provides `fmt` is implemented but not in scope; perhaps you want to import it | LL + use std::fmt::Debug; @@ -19,7 +19,7 @@ error[E0599]: no method named `fmt` found for mutable reference `&mut impl Debug LL | x.fmt(f); | ^^^ method not found in `&mut impl Debug` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: the following traits which provide `fmt` are implemented but not in scope; perhaps you want to import one of them | LL + use std::fmt::Binary; diff --git a/tests/ui/impl-trait/no-method-suggested-traits.rs b/tests/ui/impl-trait/no-method-suggested-traits.rs index 6fc96f27a671e..e838105c11623 100644 --- a/tests/ui/impl-trait/no-method-suggested-traits.rs +++ b/tests/ui/impl-trait/no-method-suggested-traits.rs @@ -22,9 +22,9 @@ fn main() { 1u32.method(); //~^ ERROR no method named - //~|items from traits can only be used if the trait is in scope + //~|items from traits can only be used if the trait is implemented and in scope std::rc::Rc::new(&mut Box::new(&1u32)).method(); - //~^items from traits can only be used if the trait is in scope + //~^items from traits can only be used if the trait is implemented and in scope //~| ERROR no method named `method` found for struct 'a'.method(); diff --git a/tests/ui/impl-trait/no-method-suggested-traits.stderr b/tests/ui/impl-trait/no-method-suggested-traits.stderr index 676247d1a423b..8b20aa1fccd45 100644 --- a/tests/ui/impl-trait/no-method-suggested-traits.stderr +++ b/tests/ui/impl-trait/no-method-suggested-traits.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `method` found for type `u32` in the current scope LL | 1u32.method(); | ^^^^^^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope 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; @@ -26,7 +26,7 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&u32>>` in 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: items from traits can only be used if the trait is implemented and in scope 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; @@ -51,7 +51,7 @@ LL | fn method(&self) {} LL | 'a'.method(); | ^^^^^^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it | LL + use foo::Bar; @@ -67,7 +67,7 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&char>>` in 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: items from traits can only be used if the trait is implemented and in scope help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it | LL + use foo::Bar; @@ -88,7 +88,7 @@ LL | 1i32.method(); 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: items from traits can only be used if the trait is implemented and in scope 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; @@ -104,7 +104,7 @@ error[E0599]: no method named `method` found for struct `Rc<&mut Box<&i32>>` in 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: items from traits can only be used if the trait is implemented and in scope 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; diff --git a/tests/ui/imports/overlapping_pub_trait.rs b/tests/ui/imports/overlapping_pub_trait.rs index 9a56b96adbfa0..c2e8a0e986ec9 100644 --- a/tests/ui/imports/overlapping_pub_trait.rs +++ b/tests/ui/imports/overlapping_pub_trait.rs @@ -11,5 +11,5 @@ fn main() { use overlapping_pub_trait_source::S; S.method(); //~^ ERROR no method named `method` found for struct `S` in the current scope [E0599] - //~| HELP items from traits can only be used if the trait is in scope + //~| HELP items from traits can only be used if the trait is implemented and in scope } diff --git a/tests/ui/imports/overlapping_pub_trait.stderr b/tests/ui/imports/overlapping_pub_trait.stderr index 51a8bec85b7d4..83f1952428d7d 100644 --- a/tests/ui/imports/overlapping_pub_trait.stderr +++ b/tests/ui/imports/overlapping_pub_trait.stderr @@ -9,7 +9,7 @@ LL | S.method(); 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: items from traits can only be used if the trait is implemented and in scope 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; diff --git a/tests/ui/imports/unnamed_pub_trait.rs b/tests/ui/imports/unnamed_pub_trait.rs index 1527dfef14763..3e654a6b73bbb 100644 --- a/tests/ui/imports/unnamed_pub_trait.rs +++ b/tests/ui/imports/unnamed_pub_trait.rs @@ -12,5 +12,5 @@ fn main() { use unnamed_pub_trait_source::S; S.method(); //~^ ERROR no method named `method` found for struct `S` in the current scope [E0599] - //~| HELP items from traits can only be used if the trait is in scope + //~| HELP items from traits can only be used if the trait is implemented and in scope } diff --git a/tests/ui/imports/unnamed_pub_trait.stderr b/tests/ui/imports/unnamed_pub_trait.stderr index 7d6b7742981ce..b3a2a72db5c27 100644 --- a/tests/ui/imports/unnamed_pub_trait.stderr +++ b/tests/ui/imports/unnamed_pub_trait.stderr @@ -9,7 +9,7 @@ LL | S.method(); 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: items from traits can only be used if the trait is implemented and in scope 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 diff --git a/tests/ui/issues/issue-10465.stderr b/tests/ui/issues/issue-10465.stderr index 0f46ebe505aa9..331564d8684dd 100644 --- a/tests/ui/issues/issue-10465.stderr +++ b/tests/ui/issues/issue-10465.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `foo` found for reference `&B` in the current scop LL | b.foo(); | ^^^ method not found in `&B` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `A` which provides `foo` is implemented but not in scope; perhaps you want to import it | LL + use a::A; diff --git a/tests/ui/issues/issue-39175.stderr b/tests/ui/issues/issue-39175.stderr index bbe8badb65231..480a75503eb78 100644 --- a/tests/ui/issues/issue-39175.stderr +++ b/tests/ui/issues/issue-39175.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `exec` found for mutable reference `&mut Command` LL | Command::new("echo").arg("hello").exec(); | ^^^^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and 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: trait `CommandExt` which provides `exec` is implemented but not in scope; perhaps you want to import it diff --git a/tests/ui/issues/issue-56175.stderr b/tests/ui/issues/issue-56175.stderr index 6ed35c3a3d3a4..f232231a8c943 100644 --- a/tests/ui/issues/issue-56175.stderr +++ b/tests/ui/issues/issue-56175.stderr @@ -9,7 +9,7 @@ LL | reexported_trait::FooStruct.trait_method(); 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: items from traits can only be used if the trait is implemented and in scope help: trait `Trait` which provides `trait_method` is implemented but not in scope; perhaps you want to import it | LL + use reexported_trait::Trait; @@ -30,7 +30,7 @@ LL | reexported_trait::FooStruct.trait_method_b(); 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: items from traits can only be used if the trait is implemented and in scope 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; diff --git a/tests/ui/methods/field-method-suggestion-using-return-ty.rs b/tests/ui/methods/field-method-suggestion-using-return-ty.rs index 07b975c44c905..0723337b384af 100644 --- a/tests/ui/methods/field-method-suggestion-using-return-ty.rs +++ b/tests/ui/methods/field-method-suggestion-using-return-ty.rs @@ -4,14 +4,14 @@ impl Wrapper> { fn inner_mut(&self) -> Option<&mut i32> { self.as_mut() //~^ ERROR no method named `as_mut` found for reference `&Wrapper>` in the current scope + //~| HELP items from traits can only be used if the trait is implemented and in scope //~| HELP one of the expressions' fields has a method of the same name - //~| HELP items from traits can only be used if } fn inner_mut_bad(&self) -> Option<&mut u32> { self.as_mut() //~^ ERROR no method named `as_mut` found for reference `&Wrapper>` in the current scope - //~| HELP items from traits can only be used if + //~| HELP items from traits can only be used if the trait is implemented and in scope } } diff --git a/tests/ui/rust-2018/trait-import-suggestions.stderr b/tests/ui/rust-2018/trait-import-suggestions.stderr index 852628885794a..8d248f6ccdb87 100644 --- a/tests/ui/rust-2018/trait-import-suggestions.stderr +++ b/tests/ui/rust-2018/trait-import-suggestions.stderr @@ -7,7 +7,7 @@ LL | fn foobar(&self) { } LL | x.foobar(); | ^^^^^^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `Foobar` which provides `foobar` is implemented but not in scope; perhaps you want to import it | LL + use crate::foo::foobar::Foobar; @@ -26,7 +26,7 @@ LL | fn bar(&self) { } LL | x.bar(); | ^^^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `Bar` which provides `bar` is implemented but not in scope; perhaps you want to import it | LL + use crate::foo::Bar; @@ -53,7 +53,7 @@ error[E0599]: no function or associated item named `from_str` found for type `u3 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: items from traits can only be used if the trait is implemented and in scope help: trait `FromStr` which provides `from_str` is implemented but not in scope; perhaps you want to import it | LL + use std::str::FromStr; diff --git a/tests/ui/rust-2018/uniform-paths/issue-87932.stderr b/tests/ui/rust-2018/uniform-paths/issue-87932.stderr index 3e6fc3ff2a562..ec55b0f6713c5 100644 --- a/tests/ui/rust-2018/uniform-paths/issue-87932.stderr +++ b/tests/ui/rust-2018/uniform-paths/issue-87932.stderr @@ -7,7 +7,7 @@ LL | pub struct A {} 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: items from traits can only be used if the trait is implemented and in scope help: trait `Deserialize` which provides `deserialize` is implemented but not in scope; perhaps you want to import it | LL + use ::deserialize::_a::Deserialize; diff --git a/tests/ui/rust-2021/future-prelude-collision-shadow.stderr b/tests/ui/rust-2021/future-prelude-collision-shadow.stderr index d9c0fa47eca02..f674a08995e7f 100644 --- a/tests/ui/rust-2021/future-prelude-collision-shadow.stderr +++ b/tests/ui/rust-2021/future-prelude-collision-shadow.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `try_into` found for type `u8` in the current scop LL | let _: u32 = 3u8.try_into().unwrap(); | ^^^^^^^^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 help: the following traits which provide `try_into` are implemented but not in scope; perhaps you want to import one of them | diff --git a/tests/ui/shadowed/shadowed-trait-methods.stderr b/tests/ui/shadowed/shadowed-trait-methods.stderr index 2c990fababf9f..1bd32c0563fa4 100644 --- a/tests/ui/shadowed/shadowed-trait-methods.stderr +++ b/tests/ui/shadowed/shadowed-trait-methods.stderr @@ -7,7 +7,7 @@ LL | pub trait T { fn f(&self) {} } LL | ().f() | ^ method not found in `()` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `T` which provides `f` is implemented but not in scope; perhaps you want to import it | LL + use foo::T; diff --git a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.rs b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.rs index 06aed9ac98f4b..28e1d1f0a2216 100644 --- a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.rs +++ b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.rs @@ -17,5 +17,5 @@ mod banana { fn main() { banana::Chaenomeles.pick() //~^ ERROR no method named - //~| HELP items from traits can only be used if the trait is in scope + //~| HELP items from traits can only be used if the trait is implemented and in scope } diff --git a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr index 41ca7d0f8ea34..2d5db44e8caeb 100644 --- a/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr +++ b/tests/ui/suggestions/dont-wrap-ambiguous-receivers.stderr @@ -7,7 +7,7 @@ LL | pub struct Chaenomeles; LL | banana::Chaenomeles.pick() | ^^^^ method not found in `Chaenomeles` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope 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; diff --git a/tests/ui/suggestions/import-trait-for-method-call.stderr b/tests/ui/suggestions/import-trait-for-method-call.stderr index 58b07fe7a42c1..8624530f253a0 100644 --- a/tests/ui/suggestions/import-trait-for-method-call.stderr +++ b/tests/ui/suggestions/import-trait-for-method-call.stderr @@ -7,7 +7,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: items from traits can only be used if the trait is implemented and in scope help: trait `Hasher` which provides `finish` is implemented but not in scope; perhaps you want to import it | LL + use std::hash::Hasher; diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr index 5be55f75cd15d..258d1734f0a23 100644 --- a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr +++ b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr @@ -47,7 +47,7 @@ LL | let _i: i16 = 0_i32.try_into().unwrap(); | = note: the method is available for `i32` here | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 help: trait `TryInto` which provides `try_into` is implemented but not in scope; perhaps you want to import it | diff --git a/tests/ui/suggestions/use-placement-typeck.stderr b/tests/ui/suggestions/use-placement-typeck.stderr index dc2bd96bb21e7..118c8f84b10ca 100644 --- a/tests/ui/suggestions/use-placement-typeck.stderr +++ b/tests/ui/suggestions/use-placement-typeck.stderr @@ -10,7 +10,7 @@ LL | } 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: items from traits can only be used if the trait is implemented and in scope help: trait `Foo` which provides `abc` is implemented but not in scope; perhaps you want to import it | LL + use m::Foo; diff --git a/tests/ui/traits/item-privacy.stderr b/tests/ui/traits/item-privacy.stderr index fd474fac15589..f67d56b8215c5 100644 --- a/tests/ui/traits/item-privacy.stderr +++ b/tests/ui/traits/item-privacy.stderr @@ -26,7 +26,7 @@ LL | fn b(&self) { } LL | S.b(); | ^ | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `B` which provides `b` is implemented but not in scope; perhaps you want to import it | LL + use method::B; @@ -71,7 +71,7 @@ LL | struct S; 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: items from traits can only be used if the trait is implemented and in scope help: there is an associated constant `B` with a similar name --> $DIR/item-privacy.rs:29:9 | @@ -116,7 +116,7 @@ LL | struct S; LL | S::B; | ^ associated item not found in `S` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: there is a method `b` with a similar name --> $DIR/item-privacy.rs:11:9 | diff --git a/tests/ui/traits/method-private.stderr b/tests/ui/traits/method-private.stderr index 274767331bd9e..a7ec9bdd529d6 100644 --- a/tests/ui/traits/method-private.stderr +++ b/tests/ui/traits/method-private.stderr @@ -7,7 +7,7 @@ LL | fn method(&self) {} LL | foo.method(); | ^^^^^^ private method | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `Bar` which provides `method` is implemented but not in scope; perhaps you want to import it | LL + use inner::Bar; diff --git a/tests/ui/traits/suggest-traits-to-import-issue-127178.rs b/tests/ui/traits/suggest-traits-to-import-issue-127178.rs new file mode 100644 index 0000000000000..f728efeb6aa40 --- /dev/null +++ b/tests/ui/traits/suggest-traits-to-import-issue-127178.rs @@ -0,0 +1,23 @@ +struct S { + x: u8, +} + +mod m { + trait GetX { + fn x(&self) -> u8; + } + + impl GetX for super::S { + fn x(&self) -> u8 { + self.x + } + } +} + +pub fn show_x(st: S) { + println!("{}", st.x()) + //~^ ERROR no method named `x` found for struct `S` in the current scope [E0599] + +} + +fn main() {} diff --git a/tests/ui/traits/suggest-traits-to-import-issue-127178.stderr b/tests/ui/traits/suggest-traits-to-import-issue-127178.stderr new file mode 100644 index 0000000000000..40d9bdee2544c --- /dev/null +++ b/tests/ui/traits/suggest-traits-to-import-issue-127178.stderr @@ -0,0 +1,20 @@ +error[E0599]: no method named `x` found for struct `S` in the current scope + --> $DIR/suggest-traits-to-import-issue-127178.rs:18:23 + | +LL | struct S { + | -------- method `x` not found for this struct +... +LL | println!("{}", st.x()) + | ^ field, not a method + | + = help: items from traits can only be used if the trait is implemented and in scope + = help: trait `m::GetX` which provides `x` is implemented but not reachable +help: remove the arguments + | +LL - println!("{}", st.x()) +LL + println!("{}", st.x) + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-43189.stderr b/tests/ui/typeck/issue-43189.stderr index 8432cbeca2a4b..5916a5f264bcb 100644 --- a/tests/ui/typeck/issue-43189.stderr +++ b/tests/ui/typeck/issue-43189.stderr @@ -9,7 +9,7 @@ LL | ().a(); 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: items from traits can only be used if the trait is implemented and in scope 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; diff --git a/tests/ui/underscore-imports/shadow.stderr b/tests/ui/underscore-imports/shadow.stderr index 4743d14dfb9e6..84ed2cedcb6d9 100644 --- a/tests/ui/underscore-imports/shadow.stderr +++ b/tests/ui/underscore-imports/shadow.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `deref` found for reference `&()` in the current s LL | x.deref(); | ^^^^^ method not found in `&()` | - = help: items from traits can only be used if the trait is in scope + = help: items from traits can only be used if the trait is implemented and in scope help: trait `Deref` which provides `deref` is implemented but not in scope; perhaps you want to import it | LL + use std::ops::Deref;