File tree 4 files changed +46
-8
lines changed
4 files changed +46
-8
lines changed Original file line number Diff line number Diff line change @@ -810,16 +810,16 @@ pub(crate) enum WrapInParentheses {
810
810
811
811
#[ derive( Diagnostic ) ]
812
812
#[ diag( parse_array_brackets_instead_of_braces) ]
813
- pub ( crate ) struct ArrayBracketsInsteadOfSpaces {
813
+ pub ( crate ) struct ArrayBracketsInsteadOfBraces {
814
814
#[ primary_span]
815
815
pub span : Span ,
816
816
#[ subdiagnostic]
817
- pub sub : ArrayBracketsInsteadOfSpacesSugg ,
817
+ pub sub : ArrayBracketsInsteadOfBracesSugg ,
818
818
}
819
819
820
820
#[ derive( Subdiagnostic ) ]
821
821
#[ multipart_suggestion( parse_suggestion, applicability = "maybe-incorrect" ) ]
822
- pub ( crate ) struct ArrayBracketsInsteadOfSpacesSugg {
822
+ pub ( crate ) struct ArrayBracketsInsteadOfBracesSugg {
823
823
#[ suggestion_part( code = "[" ) ]
824
824
pub left : Span ,
825
825
#[ suggestion_part( code = "]" ) ]
Original file line number Diff line number Diff line change @@ -2190,7 +2190,9 @@ impl<'a> Parser<'a> {
2190
2190
}
2191
2191
2192
2192
fn is_array_like_block ( & mut self ) -> bool {
2193
- self . look_ahead ( 1 , |t| matches ! ( t. kind, TokenKind :: Ident ( ..) | TokenKind :: Literal ( _) ) )
2193
+ matches ! ( self . token. kind, TokenKind :: OpenDelim ( Delimiter :: Brace ) )
2194
+ && self
2195
+ . look_ahead ( 1 , |t| matches ! ( t. kind, TokenKind :: Ident ( ..) | TokenKind :: Literal ( _) ) )
2194
2196
&& self . look_ahead ( 2 , |t| t == & token:: Comma )
2195
2197
&& self . look_ahead ( 3 , |t| t. can_begin_expr ( ) )
2196
2198
}
@@ -2202,9 +2204,9 @@ impl<'a> Parser<'a> {
2202
2204
let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
2203
2205
match snapshot. parse_expr_array_or_repeat ( exp ! ( CloseBrace ) ) {
2204
2206
Ok ( arr) => {
2205
- let guar = self . dcx ( ) . emit_err ( errors:: ArrayBracketsInsteadOfSpaces {
2207
+ let guar = self . dcx ( ) . emit_err ( errors:: ArrayBracketsInsteadOfBraces {
2206
2208
span : arr. span ,
2207
- sub : errors:: ArrayBracketsInsteadOfSpacesSugg {
2209
+ sub : errors:: ArrayBracketsInsteadOfBracesSugg {
2208
2210
left : lo,
2209
2211
right : snapshot. prev_token . span ,
2210
2212
} ,
Original file line number Diff line number Diff line change 1
1
// Test that we cannot parse a closure with an explicit return type
2
2
// unless it uses braces.
3
3
4
- fn main ( ) {
4
+ fn needs_braces_1 ( ) {
5
5
let x = || -> i32 22 ;
6
6
//~^ ERROR expected `{`, found `22`
7
7
}
8
+
9
+ // Check other delimiters too.
10
+
11
+ fn needs_braces_2( ) {
12
+ let x = || -> ( i32 , i32 ) ( 1 , 2 ) ;
13
+ //~^ ERROR expected `{`, found `(`
14
+ }
15
+
16
+ fn needs_braces_3 ( ) {
17
+ let c = || -> [ i32 ; 2 ] [ 1 , 2 ] ;
18
+ //~^ ERROR expected `{`, found `[`
19
+ }
20
+
21
+ fn main ( ) { }
Original file line number Diff line number Diff line change @@ -9,5 +9,27 @@ help: you might have meant to write this as part of a block
9
9
LL | let x = || -> i32 { 22 };
10
10
| + +
11
11
12
- error: aborting due to 1 previous error
12
+ error: expected `{`, found `(`
13
+ --> $DIR/closure-return-syntax.rs:12:34
14
+ |
15
+ LL | let x = || -> (i32, i32) (1, 2);
16
+ | ^ expected `{`
17
+ |
18
+ help: you might have meant to write this as part of a block
19
+ |
20
+ LL | let x = || -> (i32, i32) { (1, 2) };
21
+ | + +
22
+
23
+ error: expected `{`, found `[`
24
+ --> $DIR/closure-return-syntax.rs:17:32
25
+ |
26
+ LL | let c = || -> [i32; 2] [1, 2];
27
+ | ^ expected `{`
28
+ |
29
+ help: you might have meant to write this as part of a block
30
+ |
31
+ LL | let c = || -> [i32; 2] { [1, 2] };
32
+ | + +
33
+
34
+ error: aborting due to 3 previous errors
13
35
You can’t perform that action at this time.
0 commit comments