Skip to content

emit the suspicious_auto_trait_impls for negative impls as well #108804

Closed
@lcnr

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;
}

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