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

Negative trait impl gives wrong error message #70849

Closed
DutchGhost opened this issue Apr 6, 2020 · 2 comments · Fixed by #130311
Closed

Negative trait impl gives wrong error message #70849

DutchGhost opened this issue Apr 6, 2020 · 2 comments · Fixed by #130311
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-negative_impls #![feature(negative_impls)] T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

The following code:

#![feature(negative_impls)]

struct MyType;

impl !Clone for &mut MyType {}

fn main() {}

produces:

  Compiling playground v0.0.1 (/playground)
error[E0119]: conflicting implementations of trait `std::clone::Clone` for type `&mut MyType`:
 --> src/main.rs:5:1
  |
5 | impl !Clone for &mut MyType {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: conflicting implementation in crate `core`:
          - impl<T> std::clone::Clone for &mut T
            where T: ?Sized;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

which reads as: any &mut T where T: ?Sized implements Clone, which isn't realy true. It realy implements !Clone.

Perhaps the error message should add a ! in front of the impl to make it more obvious, like this:

= note: conflicting implementation in crate `core`:
          - impl<T> !std::clone::Clone for &mut T
            where T: ?Sized;
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. F-negative_impls #![feature(negative_impls)] T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 6, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 12, 2020
@fmease fmease added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Aug 30, 2024
@heiseish
Copy link
Contributor

Hi @fmease , I'd like to take up this issue if it has not been assigned yet. However this would be my first contribution so I just want to confirm it's a good first task. Thanks!

@fmease
Copy link
Member

fmease commented Sep 12, 2024

@heiseish Yeah, for sure! It should be as simple as updating to_pretty_impl_header (see) to account for the polarity. You can query/obtain the impl polarity with tcx.impl_polarity(impl_def_id). Feel free to reach out here or on Zulip if you have any questions.

@bors bors closed this as completed in 517e7ce Sep 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 14, 2024
Rollup merge of rust-lang#130311 - heiseish:issue-70849-fix, r=fmease

(fix) conflicting negative impl marker

## Context

This MR fixes the error message for conflicting negative trait impls by adding the corresponding the polarity marker to the trait name.

## Issues

- closes rust-lang#70849

r​? `@fmease`
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. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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

Successfully merging a pull request may close this issue.

5 participants