File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed
src/tools/rust-analyzer/crates/parser Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -258,13 +258,25 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
258
258
p. expect ( T ! [ '(' ] ) ;
259
259
type_ ( p) ;
260
260
p. expect ( T ! [ , ] ) ;
261
+ // Due to our incomplete handling of macro groups, especially
262
+ // those with empty delimiters, we wrap `expr` fragments in
263
+ // parentheses sometimes. Since `offset_of` is a macro, and takes
264
+ // `expr`, the field names could be wrapped in parentheses.
265
+ let wrapped_in_parens = p. eat ( T ! [ '(' ] ) ;
266
+ // test offset_of_parens
267
+ // fn foo() {
268
+ // builtin#offset_of(Foo, (bar.baz.0));
269
+ // }
261
270
while !p. at ( EOF ) && !p. at ( T ! [ ')' ] ) {
262
271
name_ref_mod_path_or_index ( p) ;
263
272
if !p. at ( T ! [ ')' ] ) {
264
273
p. expect ( T ! [ . ] ) ;
265
274
}
266
275
}
267
276
p. expect ( T ! [ ')' ] ) ;
277
+ if wrapped_in_parens {
278
+ p. expect ( T ! [ ')' ] ) ;
279
+ }
268
280
Some ( m. complete ( p, OFFSET_OF_EXPR ) )
269
281
} else if p. at_contextual_kw ( T ! [ format_args] ) {
270
282
p. bump_remap ( T ! [ format_args] ) ;
Original file line number Diff line number Diff line change @@ -416,6 +416,10 @@ mod ok {
416
416
run_and_expect_no_errors ( "test_data/parser/inline/ok/nocontentexpr_after_item.rs" ) ;
417
417
}
418
418
#[ test]
419
+ fn offset_of_parens ( ) {
420
+ run_and_expect_no_errors ( "test_data/parser/inline/ok/offset_of_parens.rs" ) ;
421
+ }
422
+ #[ test]
419
423
fn or_pattern ( ) { run_and_expect_no_errors ( "test_data/parser/inline/ok/or_pattern.rs" ) ; }
420
424
#[ test]
421
425
fn param_list ( ) { run_and_expect_no_errors ( "test_data/parser/inline/ok/param_list.rs" ) ; }
Original file line number Diff line number Diff line change
1
+ SOURCE_FILE
2
+ FN
3
+ FN_KW "fn"
4
+ WHITESPACE " "
5
+ NAME
6
+ IDENT "foo"
7
+ PARAM_LIST
8
+ L_PAREN "("
9
+ R_PAREN ")"
10
+ WHITESPACE " "
11
+ BLOCK_EXPR
12
+ STMT_LIST
13
+ L_CURLY "{"
14
+ WHITESPACE "\n "
15
+ EXPR_STMT
16
+ OFFSET_OF_EXPR
17
+ BUILTIN_KW "builtin"
18
+ POUND "#"
19
+ OFFSET_OF_KW "offset_of"
20
+ L_PAREN "("
21
+ PATH_TYPE
22
+ PATH
23
+ PATH_SEGMENT
24
+ NAME_REF
25
+ IDENT "Foo"
26
+ COMMA ","
27
+ WHITESPACE " "
28
+ L_PAREN "("
29
+ NAME_REF
30
+ IDENT "bar"
31
+ DOT "."
32
+ NAME_REF
33
+ IDENT "baz"
34
+ DOT "."
35
+ NAME_REF
36
+ INT_NUMBER "0"
37
+ R_PAREN ")"
38
+ R_PAREN ")"
39
+ SEMICOLON ";"
40
+ WHITESPACE "\n"
41
+ R_CURLY "}"
42
+ WHITESPACE "\n"
Original file line number Diff line number Diff line change
1
+ fn foo ( ) {
2
+ builtin#offset_of ( Foo , ( bar. baz . 0 ) ) ;
3
+ }
You can’t perform that action at this time.
0 commit comments