forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#79790 - LeSeulArtichaut:issue-79683, r=lcnr
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?
- Loading branch information
Showing
3 changed files
with
193 additions
and
28 deletions.
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
53 changes: 53 additions & 0 deletions
53
src/test/ui/traits/negative-impls/explicitly-unimplemented-error-message.rs
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,53 @@ | ||
// This tests issue #79683: note in the error message that the trait is | ||
// explicitely unimplemented instead of suggesting to implement it. | ||
|
||
#![feature(negative_impls)] | ||
|
||
struct Qux; | ||
//~^ NOTE method `clone` not found for this | ||
//~^^ NOTE method `foo` not found for this | ||
|
||
impl !Clone for Qux {} | ||
|
||
trait Bar { | ||
fn bar(&self); | ||
} | ||
|
||
impl !Bar for u32 {} | ||
|
||
trait Foo { | ||
fn foo(&self); | ||
} | ||
//~^^^ NOTE `Foo` defines an item `foo`, perhaps you need to implement it | ||
|
||
trait FooBar { | ||
fn foo(&self); | ||
} | ||
|
||
impl !Foo for Qux {} | ||
|
||
impl !FooBar for Qux {} | ||
|
||
impl !FooBar for u32 {} | ||
|
||
fn main() { | ||
Qux.clone(); | ||
//~^ ERROR no method named `clone` found for struct `Qux` | ||
//~| NOTE method not found in `Qux` | ||
//~| NOTE `Clone` defines an item `clone`, but is explicitely unimplemented | ||
|
||
0_u32.bar(); | ||
//~^ ERROR no method named `bar` found for type `u32` | ||
//~| NOTE method not found in `u32` | ||
//~| NOTE `Bar` defines an item `bar`, but is explicitely unimplemented | ||
|
||
Qux.foo(); | ||
//~^ ERROR no method named `foo` found for struct `Qux` | ||
//~| NOTE method not found in `Qux` | ||
//~| NOTE the following traits define an item `foo`, but are explicitely unimplemented | ||
|
||
0_u32.foo(); | ||
//~^ ERROR no method named `foo` found for type `u32` | ||
//~| NOTE method not found in `u32` | ||
//~| NOTE `FooBar` defines an item `foo`, but is explicitely unimplemented | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/ui/traits/negative-impls/explicitly-unimplemented-error-message.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,60 @@ | ||
error[E0599]: no method named `clone` found for struct `Qux` in the current scope | ||
--> $DIR/explicitly-unimplemented-error-message.rs:34:9 | ||
| | ||
LL | struct Qux; | ||
| ----------- method `clone` not found for this | ||
... | ||
LL | Qux.clone(); | ||
| ^^^^^ method not found in `Qux` | ||
| | ||
::: $SRC_DIR/core/src/clone.rs:LL:COL | ||
| | ||
LL | fn clone(&self) -> Self; | ||
| ----- | ||
| | | ||
| the method is available for `Arc<Qux>` here | ||
| the method is available for `Rc<Qux>` here | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
= note: the trait `Clone` defines an item `clone`, but is explicitely unimplemented | ||
|
||
error[E0599]: no method named `bar` found for type `u32` in the current scope | ||
--> $DIR/explicitly-unimplemented-error-message.rs:39:11 | ||
| | ||
LL | 0_u32.bar(); | ||
| ^^^ method not found in `u32` | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
= note: the trait `Bar` defines an item `bar`, but is explicitely unimplemented | ||
|
||
error[E0599]: no method named `foo` found for struct `Qux` in the current scope | ||
--> $DIR/explicitly-unimplemented-error-message.rs:44:9 | ||
| | ||
LL | struct Qux; | ||
| ----------- method `foo` not found for this | ||
... | ||
LL | Qux.foo(); | ||
| ^^^ method not found in `Qux` | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
= note: the following traits define an item `foo`, but are explicitely unimplemented: | ||
Foo | ||
FooBar | ||
|
||
error[E0599]: no method named `foo` found for type `u32` in the current scope | ||
--> $DIR/explicitly-unimplemented-error-message.rs:49:11 | ||
| | ||
LL | 0_u32.foo(); | ||
| ^^^ method not found in `u32` | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
note: `Foo` defines an item `foo`, perhaps you need to implement it | ||
--> $DIR/explicitly-unimplemented-error-message.rs:18:1 | ||
| | ||
LL | trait Foo { | ||
| ^^^^^^^^^ | ||
= note: the trait `FooBar` defines an item `foo`, but is explicitely unimplemented | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |