1
1
// run-pass
2
2
3
+ // Tests that the return type of trait methods is correctly normalized when
4
+ // checking that a method in an impl matches the trait definition when the
5
+ // return type involves a defaulted associated type.
6
+ // ie. the trait has a method with return type `-> Self::R`, and `type R = ()`,
7
+ // but the impl leaves out the return type (resulting in `()`).
8
+ // Note that specialization is not involved in this test; no items in
9
+ // implementations may be overridden. If they were, the normalization wouldn't
10
+ // happen.
11
+
3
12
#![ feature( associated_type_defaults) ]
4
13
5
14
macro_rules! overload {
@@ -12,20 +21,20 @@ macro_rules! overload {
12
21
}
13
22
14
23
fn main ( ) {
15
- let r = overload ! ( 42 , true ) ;
16
- println ! ( "-> {:?}" , r) ;
24
+ let r: ( ) = overload ! ( 42 , true ) ;
17
25
18
- let r = overload ! ( "Hello world" , 13.0 ) ;
19
- println ! ( "-> {:?}" , r ) ;
26
+ let r: f32 = overload ! ( "Hello world" , 13.0 ) ;
27
+ assert_eq ! ( r , 13.0 ) ;
20
28
21
- let r = overload ! ( 42 , true , 42.5 ) ;
22
- println ! ( "-> {:?}" , r) ;
29
+ let r: ( ) = overload ! ( 42 , true , 42.5 ) ;
23
30
24
- let r = overload ! ( "Hello world" , 13.0 , 42 ) ;
25
- println ! ( "-> {:?}" , r ) ;
31
+ let r: i32 = overload ! ( "Hello world" , 13.0 , 42 ) ;
32
+ assert_eq ! ( r , 42 ) ;
26
33
}
27
34
28
35
mod overload {
36
+ /// This trait has an assoc. type defaulting to `()`, and a required method returning a value
37
+ /// of that assoc. type.
29
38
pub trait Overload {
30
39
// type R;
31
40
type R = ( ) ;
@@ -35,6 +44,10 @@ mod overload {
35
44
// overloads for 2 args
36
45
impl Overload for ( i32 , bool ) {
37
46
// type R = ();
47
+
48
+ /// This function has no return type specified, and so defaults to `()`.
49
+ ///
50
+ /// This should work, but didn't, until RFC 2532 was implemented.
38
51
fn overload ( self ) /*-> Self::R*/ {
39
52
let ( a, b) = self ; // destructure args
40
53
println ! ( "i32 and bool {:?}" , ( a, b) ) ;
0 commit comments