Skip to content
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 advantage of negative_impls in error messages #79683

Closed
scottmcm opened this issue Dec 4, 2020 · 1 comment
Closed

Take advantage of negative_impls in error messages #79683

scottmcm opened this issue Dec 4, 2020 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. F-negative_impls #![feature(negative_impls)] T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Dec 4, 2020

(Spotted in https://users.rust-lang.org/t/the-trait-clone-is-not-implemented-for-mut-t/51989?u=scottmcm)

I tried this code https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6c22f56bb7cfec1e8e04a79fc078cdd6:

#![feature(negative_impls)]

trait Foo {
    fn foo(&self) {}
}

impl Foo for u64 {}
impl !Foo for i32 {}

fn main() {
    let x = 4_i32;
    x.foo();    
}

Which of course fails to compile. And it gives the following:

error[E0599]: no method named `foo` found for type `i32` in the current scope
  --> src/main.rs:12:7
   |
12 |     x.foo();    
   |       ^^^ method not found in `i32`
   |
   = 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
  --> src/main.rs:3:1
   |
3  | trait Foo {
   | ^^^^^^^^^

It would be nice to take advantage of the negative implementation to not say "perhaps you need to implement it" and in fact to say that it explicitly is not implemented. Other good similar cases would be things like Foo::foo(&x).

(This is a follow-up issue to #79458, as the bug part was fixed, so this is the lower-priority improvement part.)

cc #68318

@scottmcm scottmcm added C-bug Category: This is a bug. F-negative_impls #![feature(negative_impls)] C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Dec 4, 2020
@LeSeulArtichaut LeSeulArtichaut self-assigned this Dec 6, 2020
@LeSeulArtichaut
Copy link
Contributor

Looking into this

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Dec 16, 2020
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?
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Dec 16, 2020
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?
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 17, 2020
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?
@LeSeulArtichaut LeSeulArtichaut removed their assignment Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. F-negative_impls #![feature(negative_impls)] T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants