diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 3ac5994cd1ac3..f8dd5774793a3 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -242,7 +242,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { macro_rules! report_function { ($span:expr, $name:expr) => { err.note(&format!("{} is a function, perhaps you wish to call it", - $name)); + $name)); } } @@ -329,9 +329,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let mut candidates = valid_out_of_scope_traits; candidates.sort(); candidates.dedup(); - let msg = format!("items from traits can only be used if the trait is in scope; the \ - following {traits_are} implemented but not in scope, perhaps add \ - a `use` for {one_of_them}:", + err.help("items from traits can only be used if the trait is in scope"); + let mut 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 { @@ -343,17 +343,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { "one of them" }); - err.help(&msg[..]); - let limit = if candidates.len() == 5 { 5 } else { 4 }; for (i, trait_did) in candidates.iter().take(limit).enumerate() { - err.help(&format!("candidate #{}: `use {};`", - i + 1, - self.tcx.item_path_str(*trait_did))); + msg.push_str(&format!("\ncandidate #{}: `use {};`", + i + 1, + self.tcx.item_path_str(*trait_did))); } if candidates.len() > limit { - err.note(&format!("and {} others", candidates.len() - limit)); + msg.push_str(&format!("\nand {} others", candidates.len() - limit)); } + err.note(&msg[..]); + return; } @@ -383,28 +383,27 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // FIXME #21673 this help message could be tuned to the case // of a type parameter: suggest adding a trait bound rather // than implementing. - let msg = format!("items from traits can only be used if the trait is implemented \ - and in scope; the following {traits_define} an item `{name}`, \ - perhaps you need to implement {one_of_them}:", - traits_define = if candidates.len() == 1 { - "trait defines" - } else { - "traits define" - }, - one_of_them = if candidates.len() == 1 { - "it" - } else { - "one of them" - }, - name = item_name); - - err.help(&msg[..]); + err.help("items from traits can only be used if the trait is implemented and in scope"); + let mut msg = format!("the following {traits_define} an item `{name}`, \ + perhaps you need to implement {one_of_them}:", + traits_define = if candidates.len() == 1 { + "trait defines" + } else { + "traits define" + }, + one_of_them = if candidates.len() == 1 { + "it" + } else { + "one of them" + }, + name = item_name); for (i, trait_info) in candidates.iter().enumerate() { - err.help(&format!("candidate #{}: `{}`", - i + 1, - self.tcx.item_path_str(trait_info.def_id))); + msg.push_str(&format!("\ncandidate #{}: `{}`", + i + 1, + self.tcx.item_path_str(trait_info.def_id))); } + err.note(&msg[..]); } } diff --git a/src/test/compile-fail/method-call-err-msg.rs b/src/test/compile-fail/method-call-err-msg.rs index b8eb8434b3506..14fa74d1f32e5 100644 --- a/src/test/compile-fail/method-call-err-msg.rs +++ b/src/test/compile-fail/method-call-err-msg.rs @@ -33,5 +33,6 @@ fn main() { y.zero() .take() //~ ERROR no method named `take` found for type `Foo` in the current scope //~^ NOTE the method `take` exists but the following trait bounds were not satisfied + //~| NOTE the following traits define an item `take`, perhaps you need to implement one of them .one(0); } diff --git a/src/test/compile-fail/no-method-suggested-traits.rs b/src/test/compile-fail/no-method-suggested-traits.rs deleted file mode 100644 index a8d97d4674cbb..0000000000000 --- a/src/test/compile-fail/no-method-suggested-traits.rs +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2015 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. - -// aux-build:no_method_suggested_traits.rs - -extern crate no_method_suggested_traits; - -struct Foo; -enum Bar { X } - -mod foo { - pub trait Bar { - fn method(&self) {} - - fn method2(&self) {} - } - - impl Bar for u32 {} - - impl Bar for char {} -} - -fn main() { - // test the values themselves, and autoderef. - - - 1u32.method(); - //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them - //~^^ ERROR no method named - //~^^^ HELP `use foo::Bar;` - //~^^^^ HELP `use no_method_suggested_traits::foo::PubPub;` - std::rc::Rc::new(&mut Box::new(&1u32)).method(); - //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them - //~^^ ERROR no method named - //~^^^ HELP `use foo::Bar;` - //~^^^^ HELP `use no_method_suggested_traits::foo::PubPub;` - - 'a'.method(); - //~^ ERROR no method named - //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `use foo::Bar;` - std::rc::Rc::new(&mut Box::new(&'a')).method(); - //~^ ERROR no method named - //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `use foo::Bar;` - - 1i32.method(); - //~^ ERROR no method named - //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `use no_method_suggested_traits::foo::PubPub;` - std::rc::Rc::new(&mut Box::new(&1i32)).method(); - //~^ ERROR no method named - //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `use no_method_suggested_traits::foo::PubPub;` - - Foo.method(); - //~^ ERROR no method named - //~^^ HELP following traits define an item `method`, perhaps you need to implement one of them - //~^^^ HELP `foo::Bar` - //~^^^^ HELP `no_method_suggested_traits::foo::PubPub` - //~^^^^^ HELP `no_method_suggested_traits::Reexported` - //~^^^^^^ HELP `no_method_suggested_traits::bar::PubPriv` - //~^^^^^^^ HELP `no_method_suggested_traits::qux::PrivPub` - //~^^^^^^^^ HELP `no_method_suggested_traits::quz::PrivPriv` - std::rc::Rc::new(&mut Box::new(&Foo)).method(); - //~^ ERROR no method named - //~^^ HELP following traits define an item `method`, perhaps you need to implement one of them - //~^^^ HELP `foo::Bar` - //~^^^^ HELP `no_method_suggested_traits::foo::PubPub` - //~^^^^^ HELP `no_method_suggested_traits::Reexported` - //~^^^^^^ HELP `no_method_suggested_traits::bar::PubPriv` - //~^^^^^^^ HELP `no_method_suggested_traits::qux::PrivPub` - //~^^^^^^^^ HELP `no_method_suggested_traits::quz::PrivPriv` - - 1u64.method2(); - //~^ ERROR no method named - //~^^ HELP the following trait defines an item `method2`, perhaps you need to implement it - //~^^^ HELP `foo::Bar` - std::rc::Rc::new(&mut Box::new(&1u64)).method2(); - //~^ ERROR no method named - //~^^ HELP the following trait defines an item `method2`, perhaps you need to implement it - //~^^^ HELP `foo::Bar` - - no_method_suggested_traits::Foo.method2(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it - //~^^^ HELP `foo::Bar` - std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it - //~^^^ HELP `foo::Bar` - no_method_suggested_traits::Bar::X.method2(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it - //~^^^ HELP `foo::Bar` - std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it - //~^^^ HELP `foo::Bar` - - Foo.method3(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it - //~^^^ HELP `no_method_suggested_traits::foo::PubPub` - std::rc::Rc::new(&mut Box::new(&Foo)).method3(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it - //~^^^ HELP `no_method_suggested_traits::foo::PubPub` - Bar::X.method3(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it - //~^^^ HELP `no_method_suggested_traits::foo::PubPub` - std::rc::Rc::new(&mut Box::new(&Bar::X)).method3(); - //~^ ERROR no method named - //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it - //~^^^ HELP `no_method_suggested_traits::foo::PubPub` - - // should have no help: - 1_usize.method3(); //~ ERROR no method named - std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR no method named - no_method_suggested_traits::Foo.method3(); //~ ERROR no method named - std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3(); - //~^ ERROR no method named - no_method_suggested_traits::Bar::X.method3(); //~ ERROR no method named - std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3(); - //~^ ERROR no method named -} diff --git a/src/test/compile-fail/auxiliary/no_method_suggested_traits.rs b/src/test/ui/impl-trait/auxiliary/no_method_suggested_traits.rs similarity index 100% rename from src/test/compile-fail/auxiliary/no_method_suggested_traits.rs rename to src/test/ui/impl-trait/auxiliary/no_method_suggested_traits.rs diff --git a/src/test/compile-fail/issue-21659-show-relevant-trait-impls-3.rs b/src/test/ui/impl-trait/issue-21659-show-relevant-trait-impls-3.rs similarity index 100% rename from src/test/compile-fail/issue-21659-show-relevant-trait-impls-3.rs rename to src/test/ui/impl-trait/issue-21659-show-relevant-trait-impls-3.rs diff --git a/src/test/ui/impl-trait/issue-21659-show-relevant-trait-impls-3.stderr b/src/test/ui/impl-trait/issue-21659-show-relevant-trait-impls-3.stderr new file mode 100644 index 0000000000000..1b1e0eaf2039a --- /dev/null +++ b/src/test/ui/impl-trait/issue-21659-show-relevant-trait-impls-3.stderr @@ -0,0 +1,12 @@ +error[E0599]: no method named `foo` found for type `Bar` in the current scope + --> $DIR/issue-21659-show-relevant-trait-impls-3.rs:30:8 + | +30 | f1.foo(1usize); + | ^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `foo`, perhaps you need to implement it: + candidate #1: `Foo` + +error: aborting due to previous error(s) + diff --git a/src/test/compile-fail/method-suggestion-no-duplication.rs b/src/test/ui/impl-trait/method-suggestion-no-duplication.rs similarity index 100% rename from src/test/compile-fail/method-suggestion-no-duplication.rs rename to src/test/ui/impl-trait/method-suggestion-no-duplication.rs diff --git a/src/test/ui/impl-trait/method-suggestion-no-duplication.stderr b/src/test/ui/impl-trait/method-suggestion-no-duplication.stderr new file mode 100644 index 0000000000000..fa08c3bee9cf3 --- /dev/null +++ b/src/test/ui/impl-trait/method-suggestion-no-duplication.stderr @@ -0,0 +1,14 @@ +error[E0599]: no method named `is_empty` found for type `Foo` in the current scope + --> $DIR/method-suggestion-no-duplication.rs:19:15 + | +19 | foo(|s| s.is_empty()); + | ^^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following traits define an item `is_empty`, perhaps you need to implement one of them: + candidate #1: `std::iter::ExactSizeIterator` + candidate #2: `core::slice::SliceExt` + candidate #3: `core::str::StrExt` + +error: aborting due to previous error(s) + diff --git a/src/test/ui/impl-trait/no-method-suggested-traits.rs b/src/test/ui/impl-trait/no-method-suggested-traits.rs new file mode 100644 index 0000000000000..15891b00028dc --- /dev/null +++ b/src/test/ui/impl-trait/no-method-suggested-traits.rs @@ -0,0 +1,133 @@ +// Copyright 2015 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. + +// aux-build:no_method_suggested_traits.rs +extern crate no_method_suggested_traits; + +struct Foo; +enum Bar { X } + +mod foo { + pub trait Bar { + fn method(&self) {} + + fn method2(&self) {} + } + + impl Bar for u32 {} + + impl Bar for char {} +} + +fn main() { + // test the values themselves, and autoderef. + + + 1u32.method(); + //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them + //~| ERROR no method named + //~| HELP `use foo::Bar;` + //~| HELP `use no_method_suggested_traits::foo::PubPub;` + std::rc::Rc::new(&mut Box::new(&1u32)).method(); + //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them + //~| ERROR no method named + //~| HELP `use foo::Bar;` + //~| HELP `use no_method_suggested_traits::foo::PubPub;` + + 'a'.method(); + //~^ ERROR no method named + //~| HELP the following trait is implemented but not in scope, perhaps add a `use` for it: + //~| HELP `use foo::Bar;` + std::rc::Rc::new(&mut Box::new(&'a')).method(); + //~^ ERROR no method named + //~| HELP the following trait is implemented but not in scope, perhaps add a `use` for it: + //~| HELP `use foo::Bar;` + + 1i32.method(); + //~^ ERROR no method named + //~| HELP the following trait is implemented but not in scope, perhaps add a `use` for it: + //~| HELP `use no_method_suggested_traits::foo::PubPub;` + std::rc::Rc::new(&mut Box::new(&1i32)).method(); + //~^ ERROR no method named + //~| HELP the following trait is implemented but not in scope, perhaps add a `use` for it: + //~| HELP `use no_method_suggested_traits::foo::PubPub;` + + Foo.method(); + //~^ ERROR no method named + //~| HELP following traits define an item `method`, perhaps you need to implement one of them + //~| HELP `foo::Bar` + //~| HELP `no_method_suggested_traits::foo::PubPub` + //~| HELP `no_method_suggested_traits::Reexported` + //~| HELP `no_method_suggested_traits::bar::PubPriv` + //~| HELP `no_method_suggested_traits::qux::PrivPub` + //~| HELP `no_method_suggested_traits::quz::PrivPriv` + std::rc::Rc::new(&mut Box::new(&Foo)).method(); + //~^ ERROR no method named + //~| HELP following traits define an item `method`, perhaps you need to implement one of them + //~| HELP `foo::Bar` + //~| HELP `no_method_suggested_traits::foo::PubPub` + //~| HELP `no_method_suggested_traits::Reexported` + //~| HELP `no_method_suggested_traits::bar::PubPriv` + //~| HELP `no_method_suggested_traits::qux::PrivPub` + //~| HELP `no_method_suggested_traits::quz::PrivPriv` + + 1u64.method2(); + //~^ ERROR no method named + //~| HELP the following trait defines an item `method2`, perhaps you need to implement it + //~| HELP `foo::Bar` + std::rc::Rc::new(&mut Box::new(&1u64)).method2(); + //~^ ERROR no method named + //~| HELP the following trait defines an item `method2`, perhaps you need to implement it + //~| HELP `foo::Bar` + + no_method_suggested_traits::Foo.method2(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method2`, perhaps you need to implement it + //~| HELP `foo::Bar` + std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method2`, perhaps you need to implement it + //~| HELP `foo::Bar` + no_method_suggested_traits::Bar::X.method2(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method2`, perhaps you need to implement it + //~| HELP `foo::Bar` + std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method2`, perhaps you need to implement it + //~| HELP `foo::Bar` + + Foo.method3(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method3`, perhaps you need to implement it + //~| HELP `no_method_suggested_traits::foo::PubPub` + std::rc::Rc::new(&mut Box::new(&Foo)).method3(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method3`, perhaps you need to implement it + //~| HELP `no_method_suggested_traits::foo::PubPub` + Bar::X.method3(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method3`, perhaps you need to implement it + //~| HELP `no_method_suggested_traits::foo::PubPub` + std::rc::Rc::new(&mut Box::new(&Bar::X)).method3(); + //~^ ERROR no method named + //~| HELP following trait defines an item `method3`, perhaps you need to implement it + //~| HELP `no_method_suggested_traits::foo::PubPub` + + // should have no help: + 1_usize.method3(); //~ ERROR no method named + std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR no method named + no_method_suggested_traits::Foo.method3(); //~ ERROR no method named + std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3(); + //~^ ERROR no method named + no_method_suggested_traits::Bar::X.method3(); //~ ERROR no method named + std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3(); + //~^ ERROR no method named +} diff --git a/src/test/ui/impl-trait/no-method-suggested-traits.stderr b/src/test/ui/impl-trait/no-method-suggested-traits.stderr new file mode 100644 index 0000000000000..95d3007a4fb21 --- /dev/null +++ b/src/test/ui/impl-trait/no-method-suggested-traits.stderr @@ -0,0 +1,230 @@ +error[E0599]: no method named `method` found for type `u32` in the current scope + --> $DIR/no-method-suggested-traits.rs:33:10 + | +33 | 1u32.method(); + | ^^^^^^ + | + = help: items from traits can only be used if the trait is in scope + = note: the following traits are implemented but not in scope, perhaps add a `use` for one of them: + candidate #1: `use foo::Bar;` + candidate #2: `use no_method_suggested_traits::foo::PubPub;` + +error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&u32>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:38:44 + | +38 | std::rc::Rc::new(&mut Box::new(&1u32)).method(); + | ^^^^^^ + | + = help: items from traits can only be used if the trait is in scope + = note: the following traits are implemented but not in scope, perhaps add a `use` for one of them: + candidate #1: `use foo::Bar;` + candidate #2: `use no_method_suggested_traits::foo::PubPub;` + +error[E0599]: no method named `method` found for type `char` in the current scope + --> $DIR/no-method-suggested-traits.rs:44:9 + | +44 | 'a'.method(); + | ^^^^^^ + | + = 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: + candidate #1: `use foo::Bar;` + +error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&char>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:48:43 + | +48 | std::rc::Rc::new(&mut Box::new(&'a')).method(); + | ^^^^^^ + | + = 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: + candidate #1: `use foo::Bar;` + +error[E0599]: no method named `method` found for type `i32` in the current scope + --> $DIR/no-method-suggested-traits.rs:53:10 + | +53 | 1i32.method(); + | ^^^^^^ + | + = 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: + candidate #1: `use no_method_suggested_traits::foo::PubPub;` + +error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&i32>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:57:44 + | +57 | std::rc::Rc::new(&mut Box::new(&1i32)).method(); + | ^^^^^^ + | + = 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: + candidate #1: `use no_method_suggested_traits::foo::PubPub;` + +error[E0599]: no method named `method` found for type `Foo` in the current scope + --> $DIR/no-method-suggested-traits.rs:62:9 + | +62 | Foo.method(); + | ^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following traits define an item `method`, perhaps you need to implement one of them: + candidate #1: `foo::Bar` + candidate #2: `no_method_suggested_traits::foo::PubPub` + candidate #3: `no_method_suggested_traits::bar::PubPriv` + candidate #4: `no_method_suggested_traits::qux::PrivPub` + candidate #5: `no_method_suggested_traits::quz::PrivPriv` + candidate #6: `no_method_suggested_traits::Reexported` + +error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&Foo>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:71:43 + | +71 | std::rc::Rc::new(&mut Box::new(&Foo)).method(); + | ^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following traits define an item `method`, perhaps you need to implement one of them: + candidate #1: `foo::Bar` + candidate #2: `no_method_suggested_traits::foo::PubPub` + candidate #3: `no_method_suggested_traits::bar::PubPriv` + candidate #4: `no_method_suggested_traits::qux::PrivPub` + candidate #5: `no_method_suggested_traits::quz::PrivPriv` + candidate #6: `no_method_suggested_traits::Reexported` + +error[E0599]: no method named `method2` found for type `u64` in the current scope + --> $DIR/no-method-suggested-traits.rs:81:10 + | +81 | 1u64.method2(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method2`, perhaps you need to implement it: + candidate #1: `foo::Bar` + +error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::boxed::Box<&u64>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:85:44 + | +85 | std::rc::Rc::new(&mut Box::new(&1u64)).method2(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method2`, perhaps you need to implement it: + candidate #1: `foo::Bar` + +error[E0599]: no method named `method2` found for type `no_method_suggested_traits::Foo` in the current scope + --> $DIR/no-method-suggested-traits.rs:90:37 + | +90 | no_method_suggested_traits::Foo.method2(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method2`, perhaps you need to implement it: + candidate #1: `foo::Bar` + +error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:94:71 + | +94 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method2`, perhaps you need to implement it: + candidate #1: `foo::Bar` + +error[E0599]: no method named `method2` found for type `no_method_suggested_traits::Bar` in the current scope + --> $DIR/no-method-suggested-traits.rs:98:40 + | +98 | no_method_suggested_traits::Bar::X.method2(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method2`, perhaps you need to implement it: + candidate #1: `foo::Bar` + +error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:102:74 + | +102 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method2`, perhaps you need to implement it: + candidate #1: `foo::Bar` + +error[E0599]: no method named `method3` found for type `Foo` in the current scope + --> $DIR/no-method-suggested-traits.rs:107:9 + | +107 | Foo.method3(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method3`, perhaps you need to implement it: + candidate #1: `no_method_suggested_traits::foo::PubPub` + +error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&Foo>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:111:43 + | +111 | std::rc::Rc::new(&mut Box::new(&Foo)).method3(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method3`, perhaps you need to implement it: + candidate #1: `no_method_suggested_traits::foo::PubPub` + +error[E0599]: no method named `method3` found for type `Bar` in the current scope + --> $DIR/no-method-suggested-traits.rs:115:12 + | +115 | Bar::X.method3(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method3`, perhaps you need to implement it: + candidate #1: `no_method_suggested_traits::foo::PubPub` + +error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&Bar>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:119:46 + | +119 | std::rc::Rc::new(&mut Box::new(&Bar::X)).method3(); + | ^^^^^^^ + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `method3`, perhaps you need to implement it: + candidate #1: `no_method_suggested_traits::foo::PubPub` + +error[E0599]: no method named `method3` found for type `usize` in the current scope + --> $DIR/no-method-suggested-traits.rs:125:13 + | +125 | 1_usize.method3(); //~ ERROR no method named + | ^^^^^^^ + +error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&usize>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:126:47 + | +126 | std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR no method named + | ^^^^^^^ + +error[E0599]: no method named `method3` found for type `no_method_suggested_traits::Foo` in the current scope + --> $DIR/no-method-suggested-traits.rs:127:37 + | +127 | no_method_suggested_traits::Foo.method3(); //~ ERROR no method named + | ^^^^^^^ + +error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:128:71 + | +128 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3(); + | ^^^^^^^ + +error[E0599]: no method named `method3` found for type `no_method_suggested_traits::Bar` in the current scope + --> $DIR/no-method-suggested-traits.rs:130:40 + | +130 | no_method_suggested_traits::Bar::X.method3(); //~ ERROR no method named + | ^^^^^^^ + +error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>` in the current scope + --> $DIR/no-method-suggested-traits.rs:131:74 + | +131 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3(); + | ^^^^^^^ + +error: aborting due to previous error(s) + diff --git a/src/test/ui/span/issue-7575.stderr b/src/test/ui/span/issue-7575.stderr index 9f368f0de9661..9bf00b1b5749a 100644 --- a/src/test/ui/span/issue-7575.stderr +++ b/src/test/ui/span/issue-7575.stderr @@ -23,10 +23,11 @@ note: candidate #3 is defined in the trait `UnusedTrait` 29 | fn f9(usize) -> usize; //~ NOTE candidate | ^^^^^^^^^^^^^^^^^^^^^^ = help: to disambiguate the method call, write `UnusedTrait::f9(u, 342)` instead - = help: items from traits can only be used if the trait is implemented and in scope; the following traits define an item `f9`, perhaps you need to implement one of them: - = help: candidate #1: `CtxtFn` - = help: candidate #2: `OtherTrait` - = help: candidate #3: `UnusedTrait` + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following traits define an item `f9`, perhaps you need to implement one of them: + candidate #1: `CtxtFn` + candidate #2: `OtherTrait` + candidate #3: `UnusedTrait` error[E0599]: no method named `fff` found for type `Myisize` in the current scope --> $DIR/issue-7575.rs:74:30 @@ -58,8 +59,9 @@ note: candidate #1 is defined in the trait `ManyImplTrait` 59 | | } | |_____^ = help: to disambiguate the method call, write `ManyImplTrait::is_str(t)` instead - = help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `is_str`, perhaps you need to implement it: - = help: candidate #1: `ManyImplTrait` + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `is_str`, perhaps you need to implement it: + candidate #1: `ManyImplTrait` error: aborting due to previous error(s)