@@ -535,7 +535,8 @@ pub struct GenericParamCount {
535535pub struct Generics < ' hir > {
536536 pub params : & ' hir [ GenericParam < ' hir > ] ,
537537 pub predicates : & ' hir [ WherePredicate < ' hir > ] ,
538- pub has_where_clause : bool ,
538+ pub has_where_clause_predicates : bool ,
539+ pub has_where_clause_token : bool ,
539540 pub where_clause_span : Span ,
540541 pub span : Span ,
541542}
@@ -545,7 +546,8 @@ impl<'hir> Generics<'hir> {
545546 const NOPE : Generics < ' _ > = Generics {
546547 params : & [ ] ,
547548 predicates : & [ ] ,
548- has_where_clause : false ,
549+ has_where_clause_predicates : false ,
550+ has_where_clause_token : false ,
549551 where_clause_span : DUMMY_SP ,
550552 span : DUMMY_SP ,
551553 } ;
@@ -585,17 +587,11 @@ impl<'hir> Generics<'hir> {
585587 if self . predicates . is_empty ( ) { None } else { Some ( self . where_clause_span ) }
586588 }
587589
588- /// The `where_span` under normal circumstances points at either the predicates or the empty
589- /// space where the `where` clause should be. Only of use for diagnostic suggestions.
590- pub fn span_for_predicates_or_empty_place ( & self ) -> Span {
591- self . where_clause_span
592- }
593-
594590 /// `Span` where further predicates would be suggested, accounting for trailing commas, like
595591 /// in `fn foo<T>(t: T) where T: Foo,` so we don't suggest two trailing commas.
596592 pub fn tail_span_for_predicate_suggestion ( & self ) -> Span {
597- let end = self . span_for_predicates_or_empty_place ( ) . shrink_to_hi ( ) ;
598- if self . has_where_clause {
593+ let end = self . where_clause_span . shrink_to_hi ( ) ;
594+ if self . has_where_clause_predicates {
599595 self . predicates
600596 . iter ( )
601597 . filter ( |p| p. in_where_clause ( ) )
@@ -608,6 +604,16 @@ impl<'hir> Generics<'hir> {
608604 }
609605 }
610606
607+ pub fn add_where_or_trailing_comma ( & self ) -> & ' static str {
608+ if self . has_where_clause_predicates {
609+ ","
610+ } else if self . has_where_clause_token {
611+ ""
612+ } else {
613+ " where"
614+ }
615+ }
616+
611617 pub fn bounds_for_param (
612618 & self ,
613619 param_def_id : LocalDefId ,
0 commit comments