@@ -2,7 +2,7 @@ use rustc::mir::*;
22use rustc:: ty;
33use rustc_errors:: { Applicability , DiagnosticBuilder } ;
44use rustc_span:: source_map:: DesugaringKind ;
5- use rustc_span:: Span ;
5+ use rustc_span:: { Span , Symbol } ;
66
77use crate :: borrow_check:: diagnostics:: UseSpans ;
88use crate :: borrow_check:: prefixes:: PrefixSet ;
@@ -384,10 +384,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
384384 }
385385 }
386386 } ;
387- let move_ty = format ! ( "{:?}" , move_place. ty( * self . body, self . infcx. tcx) . ty, ) ;
388387 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) ;
391401 if ( is_option || is_result) && use_spans. map_or ( true , |v| !v. for_closure ( ) ) {
392402 err. span_suggestion (
393403 span,
@@ -399,12 +409,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
399409 Applicability :: MaybeIncorrect ,
400410 ) ;
401411 } 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 )
403413 {
404414 // FIXME: suggest for anything that implements `IntoIterator`.
405415 err. span_suggestion (
406416 span,
407- "consider iterating over a slice of the `Vec`'s content" ,
417+ "consider iterating over a slice of the `Vec<_> `'s content" ,
408418 format ! ( "&{}" , snippet) ,
409419 Applicability :: MaybeIncorrect ,
410420 ) ;
0 commit comments