Skip to content

Commit 8732b5a

Browse files
committed
Regression test of bug 43355
1 parent fe53d35 commit 8732b5a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/coherence/test.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,39 @@ fn overlapping_negative_impls() {
224224
}
225225
}
226226

227+
#[test]
228+
fn downstream_impl_of_fundamental_43355() {
229+
// Regression test for issue 43355 which exposed an unsoundness in the original implementation
230+
// with regards to how fundamental types were handled for potential downstream impls. This case
231+
// fails exactly the way we want it to using chalk's overlap check rules.
232+
// https://github.com/rust-lang/rust/issues/43355
233+
lowering_error! {
234+
program {
235+
#[upstream]
236+
#[fundamental]
237+
struct Box<T> { }
238+
239+
trait Trait1<X> { }
240+
trait Trait2<X> { }
241+
242+
struct A { }
243+
244+
impl<X, T> Trait1<X> for T where T: Trait2<X> { }
245+
impl<X> Trait1<Box<X>> for A { }
246+
247+
// So how do these impls overlap? Consider a downstream crate that adds this code:
248+
//
249+
// struct B;
250+
// impl Trait2<Box<B>> for A {}
251+
//
252+
// This makes the first impl now apply to A, which means that both of these impls now
253+
// overlap for A even though they didn't overlap in the original crate where A is defined.
254+
} error_msg {
255+
"overlapping impls of trait \"Trait1\""
256+
}
257+
}
258+
}
259+
227260
#[test]
228261
fn orphan_check() {
229262
// These tests are largely adapted from the compile-fail coherence-*.rs tests from rustc

0 commit comments

Comments
 (0)