88
99use rustc_ast_pretty:: pprust;
1010use rustc_data_structures:: fx:: FxHashMap ;
11- use rustc_errors:: { error_code, struct_span_err, Applicability , FatalError } ;
11+ use rustc_errors:: { error_code, struct_span_err, Applicability } ;
1212use rustc_parse:: validate_attr;
1313use rustc_session:: lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ;
1414use rustc_session:: lint:: LintBuffer ;
@@ -596,23 +596,15 @@ impl<'a> AstValidator<'a> {
596596 }
597597}
598598
599- enum GenericPosition {
600- Param ,
601- Arg ,
602- }
603-
604- fn validate_generics_order < ' a > (
599+ fn validate_generic_param_order < ' a > (
605600 sess : & Session ,
606601 handler : & rustc_errors:: Handler ,
607602 generics : impl Iterator < Item = ( ParamKindOrd , Option < & ' a [ GenericBound ] > , Span , Option < String > ) > ,
608- pos : GenericPosition ,
609603 span : Span ,
610604) {
611605 let mut max_param: Option < ParamKindOrd > = None ;
612606 let mut out_of_order = FxHashMap :: default ( ) ;
613607 let mut param_idents = vec ! [ ] ;
614- let mut found_type = false ;
615- let mut found_const = false ;
616608
617609 for ( kind, bounds, span, ident) in generics {
618610 if let Some ( ident) = ident {
@@ -626,11 +618,6 @@ fn validate_generics_order<'a>(
626618 }
627619 Some ( _) | None => * max_param = Some ( kind) ,
628620 } ;
629- match kind {
630- ParamKindOrd :: Type => found_type = true ,
631- ParamKindOrd :: Const => found_const = true ,
632- _ => { }
633- }
634621 }
635622
636623 let mut ordered_params = "<" . to_string ( ) ;
@@ -653,42 +640,26 @@ fn validate_generics_order<'a>(
653640 }
654641 ordered_params += ">" ;
655642
656- let pos_str = match pos {
657- GenericPosition :: Param => "parameter" ,
658- GenericPosition :: Arg => "argument" ,
659- } ;
660-
661643 for ( param_ord, ( max_param, spans) ) in & out_of_order {
662- let mut err = handler. struct_span_err (
663- spans. clone ( ) ,
664- & format ! (
665- "{} {pos}s must be declared prior to {} {pos}s" ,
666- param_ord,
667- max_param,
668- pos = pos_str,
669- ) ,
670- ) ;
671- if let GenericPosition :: Param = pos {
672- err. span_suggestion (
673- span,
644+ let mut err =
645+ handler. struct_span_err (
646+ spans. clone ( ) ,
674647 & format ! (
675- "reorder the {}s: lifetimes, then types{}" ,
676- pos_str,
677- if sess. features_untracked( ) . const_generics { ", then consts" } else { "" } ,
648+ "{} parameters must be declared prior to {} parameters" ,
649+ param_ord, max_param,
678650 ) ,
679- ordered_params. clone ( ) ,
680- Applicability :: MachineApplicable ,
681651 ) ;
682- }
652+ err. span_suggestion (
653+ span,
654+ & format ! (
655+ "reorder the parameters: lifetimes, then types{}" ,
656+ if sess. features_untracked( ) . const_generics { ", then consts" } else { "" } ,
657+ ) ,
658+ ordered_params. clone ( ) ,
659+ Applicability :: MachineApplicable ,
660+ ) ;
683661 err. emit ( ) ;
684662 }
685-
686- // FIXME(const_generics): we shouldn't have to abort here at all, but we currently get ICEs
687- // if we don't. Const parameters and type parameters can currently conflict if they
688- // are out-of-order.
689- if !out_of_order. is_empty ( ) && found_type && found_const {
690- FatalError . raise ( ) ;
691- }
692663}
693664
694665impl < ' a > Visitor < ' a > for AstValidator < ' a > {
@@ -1016,24 +987,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1016987 match * generic_args {
1017988 GenericArgs :: AngleBracketed ( ref data) => {
1018989 walk_list ! ( self , visit_generic_arg, & data. args) ;
1019- validate_generics_order (
1020- self . session ,
1021- self . err_handler ( ) ,
1022- data. args . iter ( ) . map ( |arg| {
1023- (
1024- match arg {
1025- GenericArg :: Lifetime ( ..) => ParamKindOrd :: Lifetime ,
1026- GenericArg :: Type ( ..) => ParamKindOrd :: Type ,
1027- GenericArg :: Const ( ..) => ParamKindOrd :: Const ,
1028- } ,
1029- None ,
1030- arg. span ( ) ,
1031- None ,
1032- )
1033- } ) ,
1034- GenericPosition :: Arg ,
1035- generic_args. span ( ) ,
1036- ) ;
1037990
1038991 // Type bindings such as `Item = impl Debug` in `Iterator<Item = Debug>`
1039992 // are allowed to contain nested `impl Trait`.
@@ -1070,7 +1023,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10701023 }
10711024 }
10721025
1073- validate_generics_order (
1026+ validate_generic_param_order (
10741027 self . session ,
10751028 self . err_handler ( ) ,
10761029 generics. params . iter ( ) . map ( |param| {
@@ -1085,7 +1038,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10851038 } ;
10861039 ( kind, Some ( & * param. bounds ) , param. ident . span , ident)
10871040 } ) ,
1088- GenericPosition :: Param ,
10891041 generics. span ,
10901042 ) ;
10911043
0 commit comments