]> git.lizzy.rs Git - rust.git/blob - tests/ui/traits/object/with-self-in-projection-output-repeated-supertrait.rs
Auto merge of #105716 - chriswailes:ndk-update-redux, r=pietroalbini
[rust.git] / tests / ui / traits / object / with-self-in-projection-output-repeated-supertrait.rs
1 // build-pass (FIXME(62277): could be check-pass?)
2
3 // FIXME(eddyb) shorten the name so windows doesn't choke on it.
4 #![crate_name = "trait_test"]
5
6 // Regression test related to #56288. Check that a supertrait projection (of
7 // `Output`) that references `Self` is ok if there is another occurrence of
8 // the same supertrait that specifies the projection explicitly, even if
9 // the projection's associated type is not explicitly specified in the object type.
10 //
11 // Note that in order for this to compile, we need the `Self`-referencing projection
12 // to normalize fairly directly to a concrete type, otherwise the trait resolver
13 // will hate us.
14 //
15 // There is a test in `trait-object-with-self-in-projection-output-bad.rs` that
16 // having a normalizing, but `Self`-containing projection does not *by itself*
17 // allow you to avoid writing the projected type (`Output`, in this example)
18 // explicitly.
19
20 trait ConstI32 {
21     type Out;
22 }
23
24 impl<T: ?Sized> ConstI32 for T {
25     type Out = i32;
26 }
27
28 trait Base {
29     type Output;
30 }
31
32 trait NormalizingHelper: Base<Output=<Self as ConstI32>::Out> + Base<Output=i32> {
33     type Target;
34 }
35
36 impl Base for u32
37 {
38     type Output = i32;
39 }
40
41 impl NormalizingHelper for u32
42 {
43     type Target = i32;
44 }
45
46 fn main() {
47     // Make sure this works both with and without the associated type
48     // being specified.
49     let _x: Box<dyn NormalizingHelper<Target=i32>> = Box::new(2u32);
50     let _y: Box<dyn NormalizingHelper<Target=i32, Output=i32>> = Box::new(2u32);
51 }