Skip to content

Commit 3329f67

Browse files
committed
marker_traits: require EvaluatedToOk
1 parent 896f058 commit 3329f67

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
@@ -1566,12 +1566,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15661566
// See if we can toss out `victim` based on specialization.
15671567
// This requires us to know *for sure* that the `other` impl applies
15681568
// i.e., `EvaluatedToOk`.
1569+
//
1570+
// FIXME(@lcnr): Using `modulo_regions` here seems kind of scary
1571+
// to me but is required for `std` to compile, so I didn't change it
1572+
// for now.
1573+
let tcx = self.tcx();
15691574
if other.evaluation.must_apply_modulo_regions() {
1570-
let tcx = self.tcx();
15711575
if tcx.specializes((other_def, victim_def)) {
15721576
return true;
15731577
}
1574-
return match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
1578+
}
1579+
1580+
if other.evaluation.must_apply_considering_regions() {
1581+
match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
15751582
Some(ty::ImplOverlapKind::Permitted { marker: true }) => {
15761583
// Subtle: If the predicate we are evaluating has inference
15771584
// variables, do *not* allow discarding candidates due to
@@ -1616,7 +1623,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16161623
}
16171624
Some(_) => true,
16181625
None => false,
1619-
};
1626+
}
16201627
} else {
16211628
false
16221629
}
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)