Skip to content

Commit f0e41ce

Browse files
authored
Rollup merge of #79514 - Julian-Wollersberger:order-dependent-bounds, r=Mark-Simulacrum
Add test for issue #54121: order dependent trait bounds This adds a test for #54121, which has already been fixed by #73905. Now that issue can be closed. I tested the test [on the playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6cb061d3b81518f268649551eb67769f) where it indeed fails on stable 1.48, but compiles successfully on beta and nightly. fixes #54121
2 parents 6eb5245 + 1fa4325 commit f0e41ce

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// check-pass
2+
3+
// From https://github.com/rust-lang/rust/issues/54121/
4+
//
5+
// Whether the code compiled depended on the order of the trait bounds in
6+
// `type T: Tr<u8, u8> + Tr<u16, u16>`
7+
// But both should compile as order shouldn't matter.
8+
9+
trait Tr<A, B> {
10+
fn exec(a: A, b: B);
11+
}
12+
13+
trait P {
14+
// This compiled successfully
15+
type T: Tr<u16, u16> + Tr<u8, u8>;
16+
}
17+
18+
trait Q {
19+
// This didn't compile
20+
type T: Tr<u8, u8> + Tr<u16, u16>;
21+
}
22+
23+
#[allow(dead_code)]
24+
fn f<S: P>() {
25+
<S as P>::T::exec(0u8, 0u8)
26+
}
27+
28+
#[allow(dead_code)]
29+
fn g<S: Q>() {
30+
// A mismatched types error was emitted on this line.
31+
<S as Q>::T::exec(0u8, 0u8)
32+
}
33+
34+
// Another reproduction of the same issue
35+
trait Trait {
36+
type Type: Into<Self::Type1> + Into<Self::Type2> + Copy;
37+
type Type1;
38+
type Type2;
39+
}
40+
41+
#[allow(dead_code)]
42+
fn foo<T: Trait>(x: T::Type) {
43+
let _1: T::Type1 = x.into();
44+
let _2: T::Type2 = x.into();
45+
}
46+
47+
fn main() { }

0 commit comments

Comments
 (0)