@@ -66,7 +66,7 @@ use rustc_middle::{
6666 span_bug,
6767 ty:: { ResolverAstLowering , TyCtxt } ,
6868} ;
69- use rustc_session:: parse:: feature_err;
69+ use rustc_session:: parse:: { add_feature_diagnostics , feature_err} ;
7070use rustc_span:: hygiene:: MacroKind ;
7171use rustc_span:: source_map:: DesugaringKind ;
7272use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -987,33 +987,56 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
987987 GenericArgs :: AngleBracketed ( data) => {
988988 self . lower_angle_bracketed_parameter_data ( data, ParamMode :: Explicit , itctx) . 0
989989 }
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+ } ,
1007996 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+ }
10171040 }
10181041 } ;
10191042 gen_args_ctor. into_generic_args ( self )
@@ -2094,7 +2117,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20942117 let future_args = self . arena . alloc ( hir:: GenericArgs {
20952118 args : & [ ] ,
20962119 bindings : arena_vec ! [ self ; self . output_ty_binding( span, output_ty) ] ,
2097- parenthesized : false ,
2120+ parenthesized : hir :: GenericArgsParentheses :: No ,
20982121 span_ext : DUMMY_SP ,
20992122 } ) ;
21002123
@@ -2614,13 +2637,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26142637struct GenericArgsCtor < ' hir > {
26152638 args : SmallVec < [ hir:: GenericArg < ' hir > ; 4 ] > ,
26162639 bindings : & ' hir [ hir:: TypeBinding < ' hir > ] ,
2617- parenthesized : bool ,
2640+ parenthesized : hir :: GenericArgsParentheses ,
26182641 span : Span ,
26192642}
26202643
26212644impl < ' hir > GenericArgsCtor < ' hir > {
26222645 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
26242649 }
26252650
26262651 fn into_generic_args ( self , this : & LoweringContext < ' _ , ' hir > ) -> & ' hir hir:: GenericArgs < ' hir > {
0 commit comments