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

relax suspicious_auto_trait_impls lint wrt lifetimes #94925

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions compiler/rustc_typeck/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,11 @@ impl<'tcx> TypeVisitor<'tcx> for AreUniqueParamsVisitor {
_ => ControlFlow::Break(NotUniqueParam::NotParam(t.into())),
}
}
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
match *r {
ty::ReEarlyBound(p) => {
if self.seen.insert(p.index) {
ControlFlow::CONTINUE
} else {
ControlFlow::Break(NotUniqueParam::DuplicateParam(r.into()))
}
}
_ => ControlFlow::Break(NotUniqueParam::NotParam(r.into())),
}
fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
// We don't drop candidates during candidate assembly because of region
// constraints, so the behavior for impls only constrained by regions
// will not change.
ControlFlow::CONTINUE
}
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
match c.val() {
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/auto-traits/suspicious-impls-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
//~^ ERROR
//~| WARNING this will change its meaning

pub struct WithLifetime<'a, T>(&'a (), T);
unsafe impl<T> Send for WithLifetime<'static, T> {} // ok
unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
//~^ ERROR
//~| WARNING this will change its meaning

fn main() {}
17 changes: 16 additions & 1 deletion src/test/ui/auto-traits/suspicious-impls-lint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,20 @@ LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `*const T` is not a generic parameter

error: aborting due to 4 previous errors
error: cross-crate traits with a default impl, like `Sync`, should not be specialized
--> $DIR/suspicious-impls-lint.rs:46:1
|
LL | unsafe impl<T> Sync for WithLifetime<'static, Vec<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>
note: try using the same sequence of generic parameters as the struct definition
--> $DIR/suspicious-impls-lint.rs:44:1
|
LL | pub struct WithLifetime<'a, T>(&'a (), T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `Vec<T>` is not a generic parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be a span_label pointing at the right place, not a note

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's somewhat difficult to get that using a type visitor 🤔 could maybe improve it by at least pointing at the self type 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's some code somewhere that does exactly that already. It'd be in one of my old PRs.


error: aborting due to 5 previous errors