@@ -76,21 +76,21 @@ impl<'tcx> Ty<'tcx> {
76
76
}
77
77
78
78
pub 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.
79
85
fn is_suggestable ( self , tcx : TyCtxt < ' tcx > ) -> bool ;
80
-
81
- fn is_suggestable_modulo_impl_trait ( self , tcx : TyCtxt < ' tcx > , bound_str : & str ) -> bool ;
82
86
}
83
87
84
88
impl < ' tcx , T > IsSuggestable < ' tcx > for T
85
89
where
86
90
T : TypeFoldable < ' tcx > ,
87
91
{
88
92
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 ( )
94
94
}
95
95
}
96
96
@@ -119,7 +119,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
119
119
& format ! (
120
120
"consider {} `where` clause, but there might be an alternative better way to express \
121
121
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 " } ,
123
123
) ,
124
124
format ! ( "{} {}: {}" , generics. add_where_or_trailing_comma( ) , param_name, constraint) ,
125
125
Applicability :: MaybeIncorrect ,
@@ -417,12 +417,11 @@ impl<'v> hir::intravisit::Visitor<'v> for StaticLifetimeVisitor<'v> {
417
417
}
418
418
}
419
419
420
- pub struct IsSuggestableVisitor < ' tcx , ' s > {
420
+ pub struct IsSuggestableVisitor < ' tcx > {
421
421
tcx : TyCtxt < ' tcx > ,
422
- bound_str : Option < & ' s str > ,
423
422
}
424
423
425
- impl < ' tcx > TypeVisitor < ' tcx > for IsSuggestableVisitor < ' tcx , ' _ > {
424
+ impl < ' tcx > TypeVisitor < ' tcx > for IsSuggestableVisitor < ' tcx > {
426
425
type BreakTy = ( ) ;
427
426
428
427
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
@@ -462,12 +461,13 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx, '_> {
462
461
}
463
462
464
463
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 ( ( ) ) ;
471
471
}
472
472
}
473
473
0 commit comments