File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed
librustc/middle/typeck/check Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -2168,12 +2168,13 @@ fn lookup_method_for_for_loop(fcx: &FnCtxt,
2168
2168
}
2169
2169
} ;
2170
2170
2171
+ let expr_type = fcx. expr_ty( & * iterator_expr) ;
2171
2172
let method = method:: lookup_in_trait( fcx,
2172
2173
iterator_expr. span,
2173
2174
Some ( & * iterator_expr) ,
2174
2175
token:: intern( "next" ) ,
2175
2176
trait_did,
2176
- fcx . expr_ty ( & * iterator_expr ) ,
2177
+ expr_type ,
2177
2178
[ ] ,
2178
2179
DontAutoderefReceiver ,
2179
2180
IgnoreStaticMethods ) ;
@@ -2184,8 +2185,9 @@ fn lookup_method_for_for_loop(fcx: &FnCtxt,
2184
2185
Some ( ref method) => method. ty,
2185
2186
None => {
2186
2187
fcx. tcx( ) . sess. span_err( iterator_expr. span,
2187
- "`for` loop expression does not \
2188
- implement the `Iterator` trait") ;
2188
+ format ! ( "`for` loop expression has type `{}` which does \
2189
+ not implement the `Iterator` trait",
2190
+ fcx. infcx( ) . ty_to_string( expr_type) ) . as_slice( ) ) ;
2189
2191
ty:: mk_err( )
2190
2192
}
2191
2193
} ;
Original file line number Diff line number Diff line change @@ -24,8 +24,7 @@ pub fn main() {
24
24
x : 1 ,
25
25
y : 2 ,
26
26
} ;
27
- for x in bogus { //~ ERROR does not implement the `Iterator` trait
27
+ for x in bogus { //~ ERROR has type `MyStruct` which does not implement the `Iterator` trait
28
28
drop ( x) ;
29
29
}
30
30
}
31
-
You can’t perform that action at this time.
0 commit comments