@@ -535,7 +535,8 @@ pub struct GenericParamCount {
535
535
pub struct Generics < ' hir > {
536
536
pub params : & ' hir [ GenericParam < ' hir > ] ,
537
537
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 ,
539
540
pub where_clause_span : Span ,
540
541
pub span : Span ,
541
542
}
@@ -545,7 +546,8 @@ impl<'hir> Generics<'hir> {
545
546
const NOPE : Generics < ' _ > = Generics {
546
547
params : & [ ] ,
547
548
predicates : & [ ] ,
548
- has_where_clause : false ,
549
+ has_where_clause_predicates : false ,
550
+ has_where_clause_token : false ,
549
551
where_clause_span : DUMMY_SP ,
550
552
span : DUMMY_SP ,
551
553
} ;
@@ -585,17 +587,11 @@ impl<'hir> Generics<'hir> {
585
587
if self . predicates . is_empty ( ) { None } else { Some ( self . where_clause_span ) }
586
588
}
587
589
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
-
594
590
/// `Span` where further predicates would be suggested, accounting for trailing commas, like
595
591
/// in `fn foo<T>(t: T) where T: Foo,` so we don't suggest two trailing commas.
596
592
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 {
599
595
self . predicates
600
596
. iter ( )
601
597
. filter ( |p| p. in_where_clause ( ) )
@@ -608,6 +604,16 @@ impl<'hir> Generics<'hir> {
608
604
}
609
605
}
610
606
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
+
611
617
pub fn bounds_for_param (
612
618
& self ,
613
619
param_def_id : LocalDefId ,
0 commit comments