Skip to content

Commit bb2cb89

Browse files
Negative coherence test
1 parent 794cb89 commit bb2cb89

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// check-pass
2+
3+
// This test verifies that negative trait predicate cannot be satisfied from a
4+
// positive param-env candidate.
5+
6+
// Negative coherence is one of the only places where we actually construct and
7+
// evaluate negative predicates. Specifically, when verifying whether the first
8+
// and second impls below overlap, we do not want to consider them disjoint,
9+
// otherwise the second impl would be missing an associated type `type Item`
10+
// which is provided by the first impl that it is specializing.
11+
12+
#![feature(specialization)]
13+
//~^ WARN the feature `specialization` is incomplete
14+
#![feature(with_negative_coherence)]
15+
16+
trait BoxIter {
17+
type Item;
18+
19+
fn last(self) -> Option<Self::Item>;
20+
}
21+
22+
impl<I: Iterator + ?Sized> BoxIter for Box<I> {
23+
type Item = I::Item;
24+
25+
default fn last(self) -> Option<I::Item> {
26+
todo!()
27+
}
28+
}
29+
30+
// When checking that this impl does/doesn't overlap the one above, we evaluate
31+
// a negative version of all of the where-clause predicates of the impl below.
32+
// For `I: !Iterator`, we should make sure that the param-env clause `I: Iterator`
33+
// from above doesn't satisfy this predicate.
34+
impl<I: Iterator> BoxIter for Box<I> {
35+
fn last(self) -> Option<I::Item> {
36+
(*self).last()
37+
}
38+
}
39+
40+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/negative-coherence-bounds.rs:12:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
8+
= help: consider using `min_specialization` instead, which is more stable and complete
9+
= note: `#[warn(incomplete_features)]` on by default
10+
11+
warning: 1 warning emitted
12+

0 commit comments

Comments
 (0)