8
8
9
9
use rustc_ast_pretty:: pprust;
10
10
use 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 } ;
12
12
use rustc_parse:: validate_attr;
13
13
use rustc_session:: lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ;
14
14
use rustc_session:: lint:: LintBuffer ;
@@ -596,23 +596,15 @@ impl<'a> AstValidator<'a> {
596
596
}
597
597
}
598
598
599
- enum GenericPosition {
600
- Param ,
601
- Arg ,
602
- }
603
-
604
- fn validate_generics_order < ' a > (
599
+ fn validate_generic_param_order < ' a > (
605
600
sess : & Session ,
606
601
handler : & rustc_errors:: Handler ,
607
602
generics : impl Iterator < Item = ( ParamKindOrd , Option < & ' a [ GenericBound ] > , Span , Option < String > ) > ,
608
- pos : GenericPosition ,
609
603
span : Span ,
610
604
) {
611
605
let mut max_param: Option < ParamKindOrd > = None ;
612
606
let mut out_of_order = FxHashMap :: default ( ) ;
613
607
let mut param_idents = vec ! [ ] ;
614
- let mut found_type = false ;
615
- let mut found_const = false ;
616
608
617
609
for ( kind, bounds, span, ident) in generics {
618
610
if let Some ( ident) = ident {
@@ -626,11 +618,6 @@ fn validate_generics_order<'a>(
626
618
}
627
619
Some ( _) | None => * max_param = Some ( kind) ,
628
620
} ;
629
- match kind {
630
- ParamKindOrd :: Type => found_type = true ,
631
- ParamKindOrd :: Const => found_const = true ,
632
- _ => { }
633
- }
634
621
}
635
622
636
623
let mut ordered_params = "<" . to_string ( ) ;
@@ -653,42 +640,26 @@ fn validate_generics_order<'a>(
653
640
}
654
641
ordered_params += ">" ;
655
642
656
- let pos_str = match pos {
657
- GenericPosition :: Param => "parameter" ,
658
- GenericPosition :: Arg => "argument" ,
659
- } ;
660
-
661
643
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 ( ) ,
674
647
& 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,
678
650
) ,
679
- ordered_params. clone ( ) ,
680
- Applicability :: MachineApplicable ,
681
651
) ;
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
+ ) ;
683
661
err. emit ( ) ;
684
662
}
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
- }
692
663
}
693
664
694
665
impl < ' a > Visitor < ' a > for AstValidator < ' a > {
@@ -1016,24 +987,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1016
987
match * generic_args {
1017
988
GenericArgs :: AngleBracketed ( ref data) => {
1018
989
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
- ) ;
1037
990
1038
991
// Type bindings such as `Item = impl Debug` in `Iterator<Item = Debug>`
1039
992
// are allowed to contain nested `impl Trait`.
@@ -1070,7 +1023,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1070
1023
}
1071
1024
}
1072
1025
1073
- validate_generics_order (
1026
+ validate_generic_param_order (
1074
1027
self . session ,
1075
1028
self . err_handler ( ) ,
1076
1029
generics. params . iter ( ) . map ( |param| {
@@ -1085,7 +1038,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1085
1038
} ;
1086
1039
( kind, Some ( & * param. bounds ) , param. ident . span , ident)
1087
1040
} ) ,
1088
- GenericPosition :: Param ,
1089
1041
generics. span ,
1090
1042
) ;
1091
1043
0 commit comments