@@ -849,8 +849,9 @@ impl<'a> Parser<'a> {
849
849
850
850
fn parse_precise_capturing_args (
851
851
& mut self ,
852
- ) -> PResult < ' a , ( ThinVec < PreciseCapturingArg > , Span ) > {
853
- let lo = self . token . span ;
852
+ lo : Span ,
853
+ parens : ast:: Parens ,
854
+ ) -> PResult < ' a , GenericBound > {
854
855
self . expect_lt ( ) ?;
855
856
let ( args, _, _) = self . parse_seq_to_before_tokens (
856
857
& [ exp ! ( Gt ) ] ,
@@ -876,7 +877,22 @@ impl<'a> Parser<'a> {
876
877
} ,
877
878
) ?;
878
879
self . expect_gt ( ) ?;
879
- Ok ( ( args, lo. to ( self . prev_token . span ) ) )
880
+
881
+ if let ast:: Parens :: Yes = parens {
882
+ self . expect ( exp ! ( CloseParen ) ) ?;
883
+ let hi = self . prev_token . span ;
884
+ let mut diag = self
885
+ . dcx ( )
886
+ . struct_span_err ( lo. to ( hi) , "precise capturing lists may not be parenthesized" ) ;
887
+ diag. multipart_suggestion (
888
+ "remove the parentheses" ,
889
+ vec ! [ ( lo, String :: new( ) ) , ( hi, String :: new( ) ) ] ,
890
+ Applicability :: MachineApplicable ,
891
+ ) ;
892
+ diag. emit ( ) ;
893
+ }
894
+
895
+ Ok ( GenericBound :: Use ( args, lo. to ( self . prev_token . span ) ) )
880
896
}
881
897
882
898
/// Is a `dyn B0 + ... + Bn` type allowed here?
@@ -987,24 +1003,18 @@ impl<'a> Parser<'a> {
987
1003
/// BOUND = TY_BOUND | LT_BOUND
988
1004
/// ```
989
1005
fn parse_generic_bound ( & mut self ) -> PResult < ' a , GenericBound > {
990
- let lo = self . token . span ;
991
1006
let leading_token = self . prev_token ;
1007
+ let lo = self . token . span ;
1008
+
992
1009
let parens = if self . eat ( exp ! ( OpenParen ) ) { ast:: Parens :: Yes } else { ast:: Parens :: No } ;
993
1010
994
- let bound = if self . token . is_lifetime ( ) {
995
- self . parse_generic_lt_bound ( lo, parens) ?
1011
+ if self . token . is_lifetime ( ) {
1012
+ self . parse_generic_lt_bound ( lo, parens)
996
1013
} else if self . eat_keyword ( exp ! ( Use ) ) {
997
- // parse precise captures, if any. This is `use<'lt, 'lt, P, P>`; a list of
998
- // lifetimes and ident params (including SelfUpper). These are validated later
999
- // for order, duplication, and whether they actually reference params.
1000
- let use_span = self . prev_token . span ;
1001
- let ( args, args_span) = self . parse_precise_capturing_args ( ) ?;
1002
- GenericBound :: Use ( args, use_span. to ( args_span) )
1014
+ self . parse_precise_capturing_args ( lo, parens)
1003
1015
} else {
1004
- self . parse_generic_ty_bound ( lo, parens, & leading_token) ?
1005
- } ;
1006
-
1007
- Ok ( bound)
1016
+ self . parse_generic_ty_bound ( lo, parens, & leading_token)
1017
+ }
1008
1018
}
1009
1019
1010
1020
/// Parses a lifetime ("outlives") bound, e.g. `'a`, according to:
0 commit comments