@@ -352,18 +352,26 @@ enum GenericPosition {
352352}
353353
354354fn validate_generics_order < ' a > (
355+ sess : & Session ,
355356 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+ > ,
357365 pos : GenericPosition ,
358366 span : Span ,
359367) {
360368 let mut max_param: Option < ParamKindOrd > = None ;
361369 let mut out_of_order = FxHashMap :: default ( ) ;
362370 let mut param_idents = vec ! [ ] ;
363371
364- for ( kind, span, ident) in generics {
372+ for ( kind, bounds , span, ident) in generics {
365373 if let Some ( ident) = ident {
366- param_idents. push ( ( kind, param_idents. len ( ) , ident) ) ;
374+ param_idents. push ( ( kind, bounds , param_idents. len ( ) , ident) ) ;
367375 }
368376 let max_param = & mut max_param;
369377 match max_param {
@@ -377,13 +385,19 @@ fn validate_generics_order<'a>(
377385
378386 let mut ordered_params = "<" . to_string ( ) ;
379387 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) ) ;
381389 let mut first = true ;
382- for ( _, _, ident) in param_idents {
390+ for ( _, bounds , _, ident) in param_idents {
383391 if !first {
384392 ordered_params += ", " ;
385393 }
386394 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+ }
387401 first = false ;
388402 }
389403 }
@@ -405,7 +419,11 @@ fn validate_generics_order<'a>(
405419 if let GenericPosition :: Param = pos {
406420 err. span_suggestion (
407421 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+ ) ,
409427 ordered_params. clone ( ) ,
410428 Applicability :: MachineApplicable ,
411429 ) ;
@@ -687,13 +705,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
687705 match * generic_args {
688706 GenericArgs :: AngleBracketed ( ref data) => {
689707 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+ ) ;
697721
698722 // Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
699723 // are allowed to contain nested `impl Trait`.
@@ -726,18 +750,24 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
726750 }
727751 }
728752
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+ ) ;
741771
742772 for predicate in & generics. where_clause . predicates {
743773 if let WherePredicate :: EqPredicate ( ref predicate) = * predicate {
0 commit comments