From 1fa43257ebb2ad0e5681b2cdcfc4d7d79ede770f Mon Sep 17 00:00:00 2001 From: Julian Wollersberger Date: Sat, 28 Nov 2020 19:44:31 +0100 Subject: [PATCH] Add test for issue #54121: "simple type inference fails depending on order of trait bounds" --- .../order-dependent-bounds-issue-54121.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs diff --git a/src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs b/src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs new file mode 100644 index 00000000000..77e4bd4d6f5 --- /dev/null +++ b/src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs @@ -0,0 +1,47 @@ +// check-pass + +// From https://github.com/rust-lang/rust/issues/54121/ +// +// Whether the code compiled depended on the order of the trait bounds in +// `type T: Tr + Tr` +// But both should compile as order shouldn't matter. + +trait Tr { + fn exec(a: A, b: B); +} + +trait P { + // This compiled successfully + type T: Tr + Tr; +} + +trait Q { + // This didn't compile + type T: Tr + Tr; +} + +#[allow(dead_code)] +fn f() { + ::T::exec(0u8, 0u8) +} + +#[allow(dead_code)] +fn g() { + // A mismatched types error was emitted on this line. + ::T::exec(0u8, 0u8) +} + +// Another reproduction of the same issue +trait Trait { + type Type: Into + Into + Copy; + type Type1; + type Type2; +} + +#[allow(dead_code)] +fn foo(x: T::Type) { + let _1: T::Type1 = x.into(); + let _2: T::Type2 = x.into(); +} + +fn main() { }