Skip to content

Commit 1eb187c

Browse files
committed
Auto merge of rust-lang#88139 - lcnr:marker-trait-attr, r=nikomatsakis
marker_traits: require `EvaluatedToOk` during winnowing closes rust-lang#84955, while it doesn't really fix it in a way that makes me happy it should prevent the issue for now and this test can't be reproduced anyways, so it doesn't make much sense to keep it open. fixes rust-lang#84917 as only one of the impls depends on regions, so we now drop the ambiguous one instead of the correct one. cc https://rust-lang.zulipchat.com/#narrow/stream/144729-wg-traits/topic/winnowing.20soundly/near/247899832 r? `@nikomatsakis`
2 parents 80dad64 + 3329f67 commit 1eb187c

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1586,12 +1586,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15861586
// See if we can toss out `victim` based on specialization.
15871587
// This requires us to know *for sure* that the `other` impl applies
15881588
// i.e., `EvaluatedToOk`.
1589+
//
1590+
// FIXME(@lcnr): Using `modulo_regions` here seems kind of scary
1591+
// to me but is required for `std` to compile, so I didn't change it
1592+
// for now.
1593+
let tcx = self.tcx();
15891594
if other.evaluation.must_apply_modulo_regions() {
1590-
let tcx = self.tcx();
15911595
if tcx.specializes((other_def, victim_def)) {
15921596
return true;
15931597
}
1594-
return match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
1598+
}
1599+
1600+
if other.evaluation.must_apply_considering_regions() {
1601+
match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
15951602
Some(ty::ImplOverlapKind::Permitted { marker: true }) => {
15961603
// Subtle: If the predicate we are evaluating has inference
15971604
// variables, do *not* allow discarding candidates due to
@@ -1636,7 +1643,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16361643
}
16371644
Some(_) => true,
16381645
None => false,
1639-
};
1646+
}
16401647
} else {
16411648
false
16421649
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
#![feature(marker_trait_attr)]
3+
4+
#[marker]
5+
pub trait F {}
6+
impl<T> F for T where T: Copy {}
7+
impl<T> F for T where T: 'static {}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(marker_trait_attr)]
2+
3+
#[marker]
4+
trait A {}
5+
impl<'a> A for (&'static (), &'a ()) {} //~ ERROR type annotations needed
6+
impl<'a> A for (&'a (), &'static ()) {} //~ ERROR type annotations needed
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/region-overlap.rs:5:10
3+
|
4+
LL | impl<'a> A for (&'static (), &'a ()) {}
5+
| ^ cannot infer type for tuple `(&'static (), &'a ())`
6+
|
7+
= note: cannot satisfy `(&'static (), &'a ()): A`
8+
note: required by a bound in `A`
9+
--> $DIR/region-overlap.rs:4:1
10+
|
11+
LL | trait A {}
12+
| ^^^^^^^ required by this bound in `A`
13+
14+
error[E0283]: type annotations needed
15+
--> $DIR/region-overlap.rs:6:10
16+
|
17+
LL | impl<'a> A for (&'a (), &'static ()) {}
18+
| ^ cannot infer type for tuple `(&'a (), &'static ())`
19+
|
20+
= note: cannot satisfy `(&'a (), &'static ()): A`
21+
note: required by a bound in `A`
22+
--> $DIR/region-overlap.rs:4:1
23+
|
24+
LL | trait A {}
25+
| ^^^^^^^ required by this bound in `A`
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0283`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(marker_trait_attr)]
2+
3+
#[marker]
4+
trait A {}
5+
6+
trait B {}
7+
8+
impl<T: A> B for T {}
9+
impl<T: B> A for T {}
10+
impl A for &str {}
11+
impl<T: A + B> A for (T,) {}
12+
trait TraitWithAssoc {
13+
type Assoc;
14+
}
15+
16+
impl<T: A> TraitWithAssoc for T {
17+
type Assoc = T;
18+
}
19+
20+
impl TraitWithAssoc for ((&str,),) {
21+
//~^ ERROR conflicting implementations
22+
type Assoc = ((&'static str,),);
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0119]: conflicting implementations of trait `TraitWithAssoc` for type `((&str,),)`
2+
--> $DIR/unsound-overlap.rs:20:1
3+
|
4+
LL | impl<T: A> TraitWithAssoc for T {
5+
| ------------------------------- first implementation here
6+
...
7+
LL | impl TraitWithAssoc for ((&str,),) {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `((&str,),)`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)