@@ -352,18 +352,26 @@ enum GenericPosition {
352
352
}
353
353
354
354
fn validate_generics_order < ' a > (
355
+ sess : & Session ,
355
356
handler : & errors:: Handler ,
356
- generics : impl Iterator < Item = ( ParamKindOrd , Span , Option < String > ) > ,
357
+ generics : impl Iterator <
358
+ Item = (
359
+ ParamKindOrd ,
360
+ Option < & ' a [ GenericBound ] > ,
361
+ Span ,
362
+ Option < String >
363
+ ) ,
364
+ > ,
357
365
pos : GenericPosition ,
358
366
span : Span ,
359
367
) {
360
368
let mut max_param: Option < ParamKindOrd > = None ;
361
369
let mut out_of_order = FxHashMap :: default ( ) ;
362
370
let mut param_idents = vec ! [ ] ;
363
371
364
- for ( kind, span, ident) in generics {
372
+ for ( kind, bounds , span, ident) in generics {
365
373
if let Some ( ident) = ident {
366
- param_idents. push ( ( kind, param_idents. len ( ) , ident) ) ;
374
+ param_idents. push ( ( kind, bounds , param_idents. len ( ) , ident) ) ;
367
375
}
368
376
let max_param = & mut max_param;
369
377
match max_param {
@@ -377,13 +385,19 @@ fn validate_generics_order<'a>(
377
385
378
386
let mut ordered_params = "<" . to_string ( ) ;
379
387
if !out_of_order. is_empty ( ) {
380
- param_idents. sort_by_key ( |& ( po, i, _) | ( po, i) ) ;
388
+ param_idents. sort_by_key ( |& ( po, _ , i, _) | ( po, i) ) ;
381
389
let mut first = true ;
382
- for ( _, _, ident) in param_idents {
390
+ for ( _, bounds , _, ident) in param_idents {
383
391
if !first {
384
392
ordered_params += ", " ;
385
393
}
386
394
ordered_params += & ident;
395
+ if let Some ( bounds) = bounds {
396
+ if !bounds. is_empty ( ) {
397
+ ordered_params += ": " ;
398
+ ordered_params += & pprust:: bounds_to_string ( & bounds) ;
399
+ }
400
+ }
387
401
first = false ;
388
402
}
389
403
}
@@ -405,7 +419,11 @@ fn validate_generics_order<'a>(
405
419
if let GenericPosition :: Param = pos {
406
420
err. span_suggestion (
407
421
span,
408
- & format ! ( "reorder the {}s: lifetimes, then types, then consts" , pos_str) ,
422
+ & format ! (
423
+ "reorder the {}s: lifetimes, then types{}" ,
424
+ pos_str,
425
+ if sess. features_untracked( ) . const_generics { ", then consts" } else { "" } ,
426
+ ) ,
409
427
ordered_params. clone ( ) ,
410
428
Applicability :: MachineApplicable ,
411
429
) ;
@@ -687,13 +705,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
687
705
match * generic_args {
688
706
GenericArgs :: AngleBracketed ( ref data) => {
689
707
walk_list ! ( self , visit_generic_arg, & data. args) ;
690
- validate_generics_order ( self . err_handler ( ) , data. args . iter ( ) . map ( |arg| {
691
- ( match arg {
692
- GenericArg :: Lifetime ( ..) => ParamKindOrd :: Lifetime ,
693
- GenericArg :: Type ( ..) => ParamKindOrd :: Type ,
694
- GenericArg :: Const ( ..) => ParamKindOrd :: Const ,
695
- } , arg. span ( ) , None )
696
- } ) , GenericPosition :: Arg , generic_args. span ( ) ) ;
708
+ validate_generics_order (
709
+ self . session ,
710
+ self . err_handler ( ) ,
711
+ data. args . iter ( ) . map ( |arg| {
712
+ ( match arg {
713
+ GenericArg :: Lifetime ( ..) => ParamKindOrd :: Lifetime ,
714
+ GenericArg :: Type ( ..) => ParamKindOrd :: Type ,
715
+ GenericArg :: Const ( ..) => ParamKindOrd :: Const ,
716
+ } , None , arg. span ( ) , None )
717
+ } ) ,
718
+ GenericPosition :: Arg ,
719
+ generic_args. span ( ) ,
720
+ ) ;
697
721
698
722
// Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
699
723
// are allowed to contain nested `impl Trait`.
@@ -726,18 +750,24 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
726
750
}
727
751
}
728
752
729
- validate_generics_order ( self . err_handler ( ) , generics. params . iter ( ) . map ( |param| {
730
- let span = param. ident . span ;
731
- let ident = Some ( param. ident . to_string ( ) ) ;
732
- match & param. kind {
733
- GenericParamKind :: Lifetime { .. } => ( ParamKindOrd :: Lifetime , span, ident) ,
734
- GenericParamKind :: Type { .. } => ( ParamKindOrd :: Type , span, ident) ,
735
- GenericParamKind :: Const { ref ty } => {
736
- let ty = pprust:: ty_to_string ( ty) ;
737
- ( ParamKindOrd :: Const , span, Some ( format ! ( "const {}: {}" , param. ident, ty) ) )
738
- }
739
- }
740
- } ) , GenericPosition :: Param , generics. span ) ;
753
+ validate_generics_order (
754
+ self . session ,
755
+ self . err_handler ( ) ,
756
+ generics. params . iter ( ) . map ( |param| {
757
+ let ident = Some ( param. ident . to_string ( ) ) ;
758
+ let ( kind, ident) = match & param. kind {
759
+ GenericParamKind :: Lifetime { .. } => ( ParamKindOrd :: Lifetime , ident) ,
760
+ GenericParamKind :: Type { .. } => ( ParamKindOrd :: Type , ident) ,
761
+ GenericParamKind :: Const { ref ty } => {
762
+ let ty = pprust:: ty_to_string ( ty) ;
763
+ ( ParamKindOrd :: Const , Some ( format ! ( "const {}: {}" , param. ident, ty) ) )
764
+ }
765
+ } ;
766
+ ( kind, Some ( & * param. bounds ) , param. ident . span , ident)
767
+ } ) ,
768
+ GenericPosition :: Param ,
769
+ generics. span ,
770
+ ) ;
741
771
742
772
for predicate in & generics. where_clause . predicates {
743
773
if let WherePredicate :: EqPredicate ( ref predicate) = * predicate {
0 commit comments