Skip to content

Commit f21488a

Browse files
committed
Auto merge of rust-lang#94925 - lcnr:relax-sus-auto-impls, r=estebank
relax `suspicious_auto_trait_impls` lint wrt lifetimes fixes the warning for rust-lang#93367 (comment).
2 parents 52b3455 + 82d8e84 commit f21488a

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

Diff for: compiler/rustc_typeck/src/coherence/orphan.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,11 @@ impl<'tcx> TypeVisitor<'tcx> for AreUniqueParamsVisitor {
297297
_ => ControlFlow::Break(NotUniqueParam::NotParam(t.into())),
298298
}
299299
}
300-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
301-
match *r {
302-
ty::ReEarlyBound(p) => {
303-
if self.seen.insert(p.index) {
304-
ControlFlow::CONTINUE
305-
} else {
306-
ControlFlow::Break(NotUniqueParam::DuplicateParam(r.into()))
307-
}
308-
}
309-
_ => ControlFlow::Break(NotUniqueParam::NotParam(r.into())),
310-
}
300+
fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
301+
// We don't drop candidates during candidate assembly because of region
302+
// constraints, so the behavior for impls only constrained by regions
303+
// will not change.
304+
ControlFlow::CONTINUE
311305
}
312306
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
313307
match c.val() {

Diff for: src/test/ui/auto-traits/suspicious-impls-lint.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
4141
//~^ ERROR
4242
//~| WARNING this will change its meaning
4343

44+
pub struct WithLifetime<'a, T>(&'a (), T);
45+
unsafe impl<T> Send for WithLifetime<'static, T> {} // ok
46+
unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
47+
//~^ ERROR
48+
//~| WARNING this will change its meaning
49+
4450
fn main() {}

Diff for: src/test/ui/auto-traits/suspicious-impls-lint.stderr

+16-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,20 @@ LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6464
= note: `*const T` is not a generic parameter
6565

66-
error: aborting due to 4 previous errors
66+
error: cross-crate traits with a default impl, like `Sync`, should not be specialized
67+
--> $DIR/suspicious-impls-lint.rs:46:1
68+
|
69+
LL | unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
70+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71+
|
72+
= warning: this will change its meaning in a future release!
73+
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
74+
note: try using the same sequence of generic parameters as the struct definition
75+
--> $DIR/suspicious-impls-lint.rs:44:1
76+
|
77+
LL | pub struct WithLifetime<'a, T>(&'a (), T);
78+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79+
= note: `Vec<T>` is not a generic parameter
80+
81+
error: aborting due to 5 previous errors
6782

0 commit comments

Comments
 (0)