File: order-dependent-bounds-issue-54121.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (47 lines) | stat: -rw-r--r-- 937 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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<u8, u8> + Tr<u16, u16>`
// But both should compile as order shouldn't matter.

trait Tr<A, B> {
    fn exec(a: A, b: B);
}

trait P {
    // This compiled successfully
    type T: Tr<u16, u16> + Tr<u8, u8>;
}

trait Q {
    // This didn't compile
    type T: Tr<u8, u8> + Tr<u16, u16>;
}

#[allow(dead_code)]
fn f<S: P>() {
    <S as P>::T::exec(0u8, 0u8)
}

#[allow(dead_code)]
fn g<S: Q>() {
    // A mismatched types error was emitted on this line.
    <S as Q>::T::exec(0u8, 0u8)
}

// Another reproduction of the same issue
trait Trait {
    type Type: Into<Self::Type1> + Into<Self::Type2> + Copy;
    type Type1;
    type Type2;
}

#[allow(dead_code)]
fn foo<T: Trait>(x: T::Type) {
    let _1: T::Type1 = x.into();
    let _2: T::Type2 = x.into();
}

fn main() { }