File tree 1 file changed +39
-0
lines changed
tests/ui/traits/new-solver
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ // revisions: old next
2
+ //[next] compile-flags: -Ztrait-solver=next
3
+ // run-pass
4
+
5
+ // A test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/45.
6
+
7
+ trait Trait {
8
+ type Assoc : Into < u32 > ;
9
+ }
10
+ impl < T : Into < u32 > > Trait for T {
11
+ type Assoc = T ;
12
+ }
13
+ fn prefer_alias_bound_projection < T : Trait > ( x : T :: Assoc ) {
14
+ // There are two possible types for `x`:
15
+ // - `u32` by using the "alias bound" of `<T as Trait>::Assoc`
16
+ // - `<T as Trait>::Assoc`, i.e. `u16`, by using `impl<T> From<T> for T`
17
+ //
18
+ // We infer the type of `x` to be `u32` here as it is highly likely
19
+ // that this is expected by the user.
20
+ let x = x. into ( ) ;
21
+ assert_eq ! ( std:: mem:: size_of_val( & x) , 4 ) ;
22
+ }
23
+
24
+ fn impl_trait ( ) -> impl Into < u32 > {
25
+ 0u16
26
+ }
27
+
28
+ fn main ( ) {
29
+ // There are two possible types for `x`:
30
+ // - `u32` by using the "alias bound" of `impl Into<u32>`
31
+ // - `impl Into<u32>`, i.e. `u16`, by using `impl<T> From<T> for T`
32
+ //
33
+ // We infer the type of `x` to be `u32` here as it is highly likely
34
+ // that this is expected by the user.
35
+ let x = impl_trait ( ) . into ( ) ;
36
+ assert_eq ! ( std:: mem:: size_of_val( & x) , 4 ) ;
37
+
38
+ prefer_alias_bound_projection :: < u16 > ( 1 ) ;
39
+ }
You can’t perform that action at this time.
0 commit comments