@@ -2,7 +2,7 @@ use rustc::mir::*;
2
2
use rustc:: ty;
3
3
use rustc_errors:: { Applicability , DiagnosticBuilder } ;
4
4
use rustc_span:: source_map:: DesugaringKind ;
5
- use rustc_span:: Span ;
5
+ use rustc_span:: { Span , Symbol } ;
6
6
7
7
use crate :: borrow_check:: diagnostics:: UseSpans ;
8
8
use crate :: borrow_check:: prefixes:: PrefixSet ;
@@ -384,10 +384,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
384
384
}
385
385
}
386
386
} ;
387
- let move_ty = format ! ( "{:?}" , move_place. ty( * self . body, self . infcx. tcx) . ty, ) ;
388
387
if let Ok ( snippet) = self . infcx . tcx . sess . source_map ( ) . span_to_snippet ( span) {
389
- let is_option = move_ty. starts_with ( "std::option::Option" ) ;
390
- let is_result = move_ty. starts_with ( "std::result::Result" ) ;
388
+ let def_id = match move_place. ty ( * self . body , self . infcx . tcx ) . ty . kind {
389
+ ty:: Adt ( self_def, _) => self_def. did ,
390
+ ty:: Foreign ( def_id)
391
+ | ty:: FnDef ( def_id, _)
392
+ | ty:: Closure ( def_id, _)
393
+ | ty:: Generator ( def_id, ..)
394
+ | ty:: Opaque ( def_id, _) => def_id,
395
+ _ => return err,
396
+ } ;
397
+ let is_option =
398
+ self . infcx . tcx . is_diagnostic_item ( Symbol :: intern ( "option_type" ) , def_id) ;
399
+ let is_result =
400
+ self . infcx . tcx . is_diagnostic_item ( Symbol :: intern ( "result_type" ) , def_id) ;
391
401
if ( is_option || is_result) && use_spans. map_or ( true , |v| !v. for_closure ( ) ) {
392
402
err. span_suggestion (
393
403
span,
@@ -399,12 +409,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
399
409
Applicability :: MaybeIncorrect ,
400
410
) ;
401
411
} else if span. is_desugaring ( DesugaringKind :: ForLoop )
402
- && move_ty . starts_with ( "std::vec::Vec" )
412
+ && self . infcx . tcx . is_diagnostic_item ( Symbol :: intern ( "vec_type" ) , def_id )
403
413
{
404
414
// FIXME: suggest for anything that implements `IntoIterator`.
405
415
err. span_suggestion (
406
416
span,
407
- "consider iterating over a slice of the `Vec`'s content" ,
417
+ "consider iterating over a slice of the `Vec<_> `'s content" ,
408
418
format ! ( "&{}" , snippet) ,
409
419
Applicability :: MaybeIncorrect ,
410
420
) ;
0 commit comments