-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use multiline note for trait suggestion #42383
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
src/test/ui/impl-trait/issue-21659-show-relevant-trait-impls-3.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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; the following trait defines an item `foo`, perhaps you need to implement it: | ||
candidate #1: `Foo` | ||
|
||
error: aborting due to previous error(s) | ||
|
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
src/test/ui/impl-trait/method-suggestion-no-duplication.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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; 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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should rephrase this to something more like this: