@@ -76,21 +76,21 @@ impl<'tcx> Ty<'tcx> {
7676}
7777
7878pub trait IsSuggestable < ' tcx > {
79+ /// Whether this makes sense to suggest in a diagnostic.
80+ ///
81+ /// We filter out certain types and constants since they don't provide
82+ /// meaningful rendered suggestions when pretty-printed. We leave some
83+ /// nonsense, such as region vars, since those render as `'_` and are
84+ /// usually okay to reinterpret as elided lifetimes.
7985 fn is_suggestable ( self , tcx : TyCtxt < ' tcx > ) -> bool ;
80-
81- fn is_suggestable_modulo_impl_trait ( self , tcx : TyCtxt < ' tcx > , bound_str : & str ) -> bool ;
8286}
8387
8488impl < ' tcx , T > IsSuggestable < ' tcx > for T
8589where
8690 T : TypeFoldable < ' tcx > ,
8791{
8892 fn is_suggestable ( self , tcx : TyCtxt < ' tcx > ) -> bool {
89- self . visit_with ( & mut IsSuggestableVisitor { tcx, bound_str : None } ) . is_continue ( )
90- }
91-
92- fn is_suggestable_modulo_impl_trait ( self , tcx : TyCtxt < ' tcx > , bound_str : & str ) -> bool {
93- self . visit_with ( & mut IsSuggestableVisitor { tcx, bound_str : Some ( bound_str) } ) . is_continue ( )
93+ self . visit_with ( & mut IsSuggestableVisitor { tcx } ) . is_continue ( )
9494 }
9595}
9696
@@ -119,7 +119,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
119119 & format ! (
120120 "consider {} `where` clause, but there might be an alternative better way to express \
121121 this requirement",
122- if generics. has_where_clause_token { "extending the " } else { "introducing a " } ,
122+ if generics. where_clause_span . is_empty ( ) { "introducing a " } else { "extending the " } ,
123123 ) ,
124124 format ! ( "{} {}: {}" , generics. add_where_or_trailing_comma( ) , param_name, constraint) ,
125125 Applicability :: MaybeIncorrect ,
@@ -417,12 +417,11 @@ impl<'v> hir::intravisit::Visitor<'v> for StaticLifetimeVisitor<'v> {
417417 }
418418}
419419
420- pub struct IsSuggestableVisitor < ' tcx , ' s > {
420+ pub struct IsSuggestableVisitor < ' tcx > {
421421 tcx : TyCtxt < ' tcx > ,
422- bound_str : Option < & ' s str > ,
423422}
424423
425- impl < ' tcx > TypeVisitor < ' tcx > for IsSuggestableVisitor < ' tcx , ' _ > {
424+ impl < ' tcx > TypeVisitor < ' tcx > for IsSuggestableVisitor < ' tcx > {
426425 type BreakTy = ( ) ;
427426
428427 fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
@@ -462,12 +461,13 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx, '_> {
462461 }
463462
464463 Param ( param) => {
465- if let Some ( found_bound_str) =
466- param. name . as_str ( ) . strip_prefix ( "impl " ) . map ( |s| s. trim_start ( ) )
467- {
468- if self . bound_str . map_or ( true , |bound_str| bound_str != found_bound_str) {
469- return ControlFlow :: Break ( ( ) ) ;
470- }
464+ // FIXME: It would be nice to make this not use string manipulation,
465+ // but it's pretty hard to do this, since `ty::ParamTy` is missing
466+ // sufficient info to determine if it is synthetic, and we don't
467+ // always have a convenient way of getting `ty::Generics` at the call
468+ // sites we invoke `IsSuggestable::is_suggestable`.
469+ if param. name . as_str ( ) . starts_with ( "impl " ) {
470+ return ControlFlow :: Break ( ( ) ) ;
471471 }
472472 }
473473
0 commit comments