Skip to content

Commit

Permalink
backport rust-lang#94925
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Mar 30, 2022
1 parent 7bccde1 commit f81aea9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
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 @@ -300,17 +300,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

error: aborting due to 5 previous errors

0 comments on commit f81aea9

Please sign in to comment.