Skip to content

Commit 21b9f5c

Browse files
committed
add known-bug test for unsound issue 74629
1 parent a87359d commit 21b9f5c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// check-pass
2+
// known-bug: #74629
3+
4+
// Should fail. The `0` and `1` impls overlap, violating coherence. Eg, with
5+
// `T = Test, F = ()`, all bounds are true, making both impls applicable.
6+
// `Test: Fold<Nil>`, `Test: Fold<()>` are true because of `2`.
7+
// `Is<Test>: NotNil` is true because of `auto trait` and lack of negative impl.
8+
9+
#![feature(negative_impls)]
10+
#![feature(auto_traits)]
11+
12+
struct Nil;
13+
struct Cons<H>(H);
14+
struct Test;
15+
16+
trait Fold<F> {}
17+
18+
impl<T, F> Fold<F> for Cons<T> // 0
19+
where
20+
T: Fold<Nil>,
21+
{}
22+
23+
impl<T, F> Fold<F> for Cons<T> // 1
24+
where
25+
T: Fold<F>,
26+
private::Is<T>: private::NotNil,
27+
{}
28+
29+
impl<F> Fold<F> for Test {} // 2
30+
31+
mod private {
32+
use crate::Nil;
33+
34+
pub struct Is<T>(T);
35+
pub auto trait NotNil {}
36+
37+
#[allow(suspicious_auto_trait_impls)]
38+
impl !NotNil for Is<Nil> {}
39+
}
40+
41+
fn main() {}

0 commit comments

Comments
 (0)