-
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
Take into account negative impls in "trait item not found" suggestions #79790
Conversation
let (potential_candidates, explicitly_negative) = if param_type.is_some() { | ||
// Negative bounds are not supported | ||
(candidates, Vec::new()) |
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.
This is actually sort of a shortcut, consider the following code:
#![feature(negative_impls)]
trait Foo {
fn foo(&self);
}
trait Bar {}
impl<T: Foo> !Bar for T {}
fn foo<T: Bar>(x: T) {
x.foo()
}
Which gives the following error:
error[E0599]: no method named `foo` found for type parameter `T` in the current scope
--> main.rs:12:7
|
12 | x.foo()
| ^^^ method not found in `T`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `foo`, perhaps you need to restrict type parameter `T` with it:
|
11 | fn foo<T: Foo + Bar>(x: T) {
| ^^^^^^^^
error: aborting due to previous error
So I think this could be improved but I think it's reasonable to do it in a follow-up PR since this PR does not change the current diagnostic.
c0f37db
to
1d7e6ce
Compare
My PR also doesn't work in: #![feature(negative_impls)]
trait Bar {
fn bar(&self);
}
impl<T: Copy> !Bar for T {}
fn foo(x: ()) {
x.bar()
}
fn main() {}
|
r? @lcnr |
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.
lgtm
one additional small nit would be to use
match explicitly_negative/potential_candidates {
[] => {},
[trait_info] => ...
slice => ...
}
instead of the current if not_empty { if let ... { ... } }
1d7e6ce
to
92f3a72
Compare
This comment has been minimized.
This comment has been minimized.
92f3a72
to
9dacc69
Compare
This comment has been minimized.
This comment has been minimized.
9dacc69
to
2a6865a
Compare
2a6865a
to
3105579
Compare
r=me @bors delegate+ |
✌️ @LeSeulArtichaut can now approve this pull request |
3105579
to
cfc38d2
Compare
📌 Commit cfc38d2 has been approved by |
Take into account negative impls in "trait item not found" suggestions This removes the suggestion to implement a trait for a type when that type already has a negative implementation for the trait, and replaces it with a note to point out that the trait is explicitely unimplemented, as suggested by `@scottmcm.` Helps with rust-lang#79683. r? `@scottmcm` do you want to review this?
⌛ Testing commit cfc38d2 with merge 0d7c7ea307a01cf5e08d93bca34e168d5e122e9e... |
failed in rollup log @bors r- |
@Dylan-DPC How is this PR causing that "could not parse code block as Rust code" error? |
☀️ Try build successful - checks-actions |
I don't know where this try build comes from, but based on this I will take the liberty of accepting this again. |
📌 Commit cfc38d2 has been approved by |
I don't know but the error was tough to debug and this looked like t he closest PR :D |
I'd guess the failure comes from #79816 which IIUC creates this new lint? |
yeah the test failure now on that PR, confirms it. sorry about the mess :P |
Take into account negative impls in "trait item not found" suggestions This removes the suggestion to implement a trait for a type when that type already has a negative implementation for the trait, and replaces it with a note to point out that the trait is explicitely unimplemented, as suggested by `@scottmcm.` Helps with rust-lang#79683. r? `@scottmcm` do you want to review this?
☀️ Test successful - checks-actions |
This removes the suggestion to implement a trait for a type when that type already has a negative implementation for the trait, and replaces it with a note to point out that the trait is explicitely unimplemented, as suggested by @scottmcm.
Helps with #79683.
r? @scottmcm do you want to review this?