@@ -66,7 +66,7 @@ use rustc_middle::{
66
66
span_bug,
67
67
ty:: { ResolverAstLowering , TyCtxt } ,
68
68
} ;
69
- use rustc_session:: parse:: feature_err;
69
+ use rustc_session:: parse:: { add_feature_diagnostics , feature_err} ;
70
70
use rustc_span:: hygiene:: MacroKind ;
71
71
use rustc_span:: source_map:: DesugaringKind ;
72
72
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -987,33 +987,56 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
987
987
GenericArgs :: AngleBracketed ( data) => {
988
988
self . lower_angle_bracketed_parameter_data ( data, ParamMode :: Explicit , itctx) . 0
989
989
}
990
- GenericArgs :: Parenthesized ( data) if self . tcx . features ( ) . return_type_notation => {
991
- if !data. inputs . is_empty ( ) {
992
- self . tcx . sess . emit_err ( errors:: BadReturnTypeNotation :: Inputs {
993
- span : data. inputs_span ,
994
- } ) ;
995
- } else if let FnRetTy :: Ty ( ty) = & data. output {
996
- self . tcx . sess . emit_err ( errors:: BadReturnTypeNotation :: Output {
997
- span : data. inputs_span . shrink_to_hi ( ) . to ( ty. span ) ,
998
- } ) ;
999
- }
1000
- GenericArgsCtor {
1001
- args : Default :: default ( ) ,
1002
- bindings : & [ ] ,
1003
- parenthesized : true ,
1004
- span : data. span ,
1005
- }
1006
- }
990
+ & GenericArgs :: ReturnTypeNotation ( span) => GenericArgsCtor {
991
+ args : Default :: default ( ) ,
992
+ bindings : & [ ] ,
993
+ parenthesized : hir:: GenericArgsParentheses :: ReturnTypeNotation ,
994
+ span,
995
+ } ,
1007
996
GenericArgs :: Parenthesized ( data) => {
1008
- self . emit_bad_parenthesized_trait_in_assoc_ty ( data) ;
1009
- // FIXME(return_type_notation): we could issue a feature error
1010
- // if the parens are empty and there's no return type.
1011
- self . lower_angle_bracketed_parameter_data (
1012
- & data. as_angle_bracketed_args ( ) ,
1013
- ParamMode :: Explicit ,
1014
- itctx,
1015
- )
1016
- . 0
997
+ if let Some ( start_char) = constraint. ident . as_str ( ) . chars ( ) . next ( )
998
+ && start_char. is_ascii_lowercase ( )
999
+ {
1000
+ let mut err = if !data. inputs . is_empty ( ) {
1001
+ self . tcx . sess . create_err ( errors:: BadReturnTypeNotation :: Inputs {
1002
+ span : data. inputs_span ,
1003
+ } )
1004
+ } else if let FnRetTy :: Ty ( ty) = & data. output {
1005
+ self . tcx . sess . create_err ( errors:: BadReturnTypeNotation :: Output {
1006
+ span : data. inputs_span . shrink_to_hi ( ) . to ( ty. span ) ,
1007
+ } )
1008
+ } else {
1009
+ self . tcx . sess . create_err ( errors:: BadReturnTypeNotation :: NeedsDots {
1010
+ span : data. inputs_span ,
1011
+ } )
1012
+ } ;
1013
+ if !self . tcx . features ( ) . return_type_notation
1014
+ && self . tcx . sess . is_nightly_build ( )
1015
+ {
1016
+ add_feature_diagnostics (
1017
+ & mut err,
1018
+ & self . tcx . sess . parse_sess ,
1019
+ sym:: return_type_notation,
1020
+ ) ;
1021
+ }
1022
+ err. emit ( ) ;
1023
+ GenericArgsCtor {
1024
+ args : Default :: default ( ) ,
1025
+ bindings : & [ ] ,
1026
+ parenthesized : hir:: GenericArgsParentheses :: ReturnTypeNotation ,
1027
+ span : data. span ,
1028
+ }
1029
+ } else {
1030
+ self . emit_bad_parenthesized_trait_in_assoc_ty ( data) ;
1031
+ // FIXME(return_type_notation): we could issue a feature error
1032
+ // if the parens are empty and there's no return type.
1033
+ self . lower_angle_bracketed_parameter_data (
1034
+ & data. as_angle_bracketed_args ( ) ,
1035
+ ParamMode :: Explicit ,
1036
+ itctx,
1037
+ )
1038
+ . 0
1039
+ }
1017
1040
}
1018
1041
} ;
1019
1042
gen_args_ctor. into_generic_args ( self )
@@ -2094,7 +2117,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2094
2117
let future_args = self . arena . alloc ( hir:: GenericArgs {
2095
2118
args : & [ ] ,
2096
2119
bindings : arena_vec ! [ self ; self . output_ty_binding( span, output_ty) ] ,
2097
- parenthesized : false ,
2120
+ parenthesized : hir :: GenericArgsParentheses :: No ,
2098
2121
span_ext : DUMMY_SP ,
2099
2122
} ) ;
2100
2123
@@ -2614,13 +2637,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2614
2637
struct GenericArgsCtor < ' hir > {
2615
2638
args : SmallVec < [ hir:: GenericArg < ' hir > ; 4 ] > ,
2616
2639
bindings : & ' hir [ hir:: TypeBinding < ' hir > ] ,
2617
- parenthesized : bool ,
2640
+ parenthesized : hir :: GenericArgsParentheses ,
2618
2641
span : Span ,
2619
2642
}
2620
2643
2621
2644
impl < ' hir > GenericArgsCtor < ' hir > {
2622
2645
fn is_empty ( & self ) -> bool {
2623
- self . args . is_empty ( ) && self . bindings . is_empty ( ) && !self . parenthesized
2646
+ self . args . is_empty ( )
2647
+ && self . bindings . is_empty ( )
2648
+ && self . parenthesized == hir:: GenericArgsParentheses :: No
2624
2649
}
2625
2650
2626
2651
fn into_generic_args ( self , this : & LoweringContext < ' _ , ' hir > ) -> & ' hir hir:: GenericArgs < ' hir > {
0 commit comments