Skip to content

emit the suspicious_auto_trait_impls for negative impls as well #108804

Closed

Description

@lcnr
#![feature(negative_impls)]

struct Foo<T, U>(T, U);
impl<T> !Send for Foo<T, T> {}

struct Bar<T, U>(T, U);
unsafe impl<T> Send for Bar<T, T> {}

results in the following:

warning: cross-crate traits with a default impl, like `Send`, should not be specialized
 --> src/lib.rs:7:1
  |
7 | unsafe impl<T> Send for Bar<T, T> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = warning: this will change its meaning in a future release!
  = note: for more information, [see issue #93367 <https://github.com/rust-lang/rust/issues/93367>](https://github.com/rust-lang/rust/issues/93367)
  = note: `T` is mentioned multiple times
note: try using the same sequence of generic parameters as the struct definition
 --> src/lib.rs:6:1
  |
6 | struct Bar<T, U>(T, U);
  | ^^^^^^^^^^^^^^^^
  = note: `#[warn(suspicious_auto_trait_impls)]` on by default

the lint should also be emitted for the negative impl. The lint was implemented in #93267. To fix that remove the following line and add a test:

if tcx.impl_polarity(impl_def_id) != ImplPolarity::Positive {
return;
}

Activity

  1. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Mar 6, 2023
  2. mu001999 commented on Mar 6, 2023

    @mu001999
    Member

    @rustbot claim

  3. added 2 commits that reference this issue on Mar 6, 2023
    0f95961
    3279f7e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions