Skip to content

Commit 9bb9fba

Browse files
bors[bot]Veykril
andauthored
Merge #6965
6965: Properly attach attributes to Param instead of parent ParamList r=matklad a=Veykril Fixes #2783, fixes #2781 The problem with `let _a = [0,#[cfg(feature = "L")]0];` has already been fixed some time ago it seems: <details> <summary>Syntax Tree for the const item</summary> ``` [email protected] [email protected] "let" [email protected] " " [email protected] [email protected] [email protected] "_a" [email protected] " " [email protected] "=" [email protected] " " [email protected] [email protected] "[" [email protected] [email protected] "0" [email protected] "," [email protected] [email protected] [email protected] "#" [email protected] "[" [email protected] [email protected] [email protected] [email protected] "cfg" [email protected] [email protected] "(" [email protected] "feature" [email protected] " " [email protected] "=" [email protected] " " [email protected] "\"L\"" [email protected] ")" [email protected] "]" [email protected] "0" [email protected] "]" [email protected] ";" ``` </details> Co-authored-by: Lukas Wirth <[email protected]>
2 parents fa75e11 + 64caa02 commit 9bb9fba

File tree

7 files changed

+199
-147
lines changed

7 files changed

+199
-147
lines changed

crates/parser/src/grammar/expressions/atom.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
156156
let mut saw_expr = false;
157157
while !p.at(EOF) && !p.at(T![')']) {
158158
saw_expr = true;
159-
if !p.at_ts(EXPR_FIRST) {
160-
p.error("expected expression");
159+
160+
// test tuple_attrs
161+
// const A: (i64, i64) = (1, #[cfg(test)] 2);
162+
if !expr_with_attrs(p) {
161163
break;
162164
}
163-
expr(p);
165+
164166
if !p.at(T![')']) {
165167
saw_comma = true;
166168
p.expect(T![,]);

crates/parser/src/grammar/params.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,23 @@ fn list_(p: &mut Parser, flavor: Flavor) {
4747
if let FnDef = flavor {
4848
// test self_param_outer_attr
4949
// fn f(#[must_use] self) {}
50+
let m = p.start();
5051
attributes::outer_attrs(p);
51-
opt_self_param(p);
52+
opt_self_param(p, m);
5253
}
5354

5455
while !p.at(EOF) && !p.at(ket) {
5556
// test param_outer_arg
5657
// fn f(#[attr1] pat: Type) {}
58+
let m = p.start();
5759
attributes::outer_attrs(p);
5860

5961
if !p.at_ts(PARAM_FIRST) {
6062
p.error("expected value parameter");
63+
m.abandon(p);
6164
break;
6265
}
63-
let param = param(p, flavor);
66+
let param = param(p, m, flavor);
6467
if !p.at(ket) {
6568
p.expect(T![,]);
6669
}
@@ -77,9 +80,8 @@ const PARAM_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYPE_FIRST);
7780

7881
struct Variadic(bool);
7982

80-
fn param(p: &mut Parser, flavor: Flavor) -> Variadic {
83+
fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic {
8184
let mut res = Variadic(false);
82-
let m = p.start();
8385
match flavor {
8486
// test param_list_vararg
8587
// extern "C" { fn printf(format: *const i8, ...) -> i32; }
@@ -151,10 +153,8 @@ fn variadic_param(p: &mut Parser) -> bool {
151153
// fn d(&'a mut self, x: i32) {}
152154
// fn e(mut self) {}
153155
// }
154-
fn opt_self_param(p: &mut Parser) {
155-
let m;
156+
fn opt_self_param(p: &mut Parser, m: Marker) {
156157
if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] {
157-
m = p.start();
158158
p.eat(T![mut]);
159159
p.eat(T![self]);
160160
// test arb_self_types
@@ -174,9 +174,8 @@ fn opt_self_param(p: &mut Parser) {
174174
(T![&], T![mut], T![self], _) => 3,
175175
(T![&], LIFETIME_IDENT, T![self], _) => 3,
176176
(T![&], LIFETIME_IDENT, T![mut], T![self]) => 4,
177-
_ => return,
177+
_ => return m.abandon(p),
178178
};
179-
m = p.start();
180179
p.bump_any();
181180
if p.at(LIFETIME_IDENT) {
182181
lifetime(p);

crates/syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ [email protected]
66
77
88
9-
ATTR@5..16
10-
POUND@5..6 "#"
11-
12-
13-
PATH_SEGMENT@7..15
14-
NAME_REF@7..15
15-
IDENT@7..15 "must_use"
16-
17-
18-
9+
SELF_PARAM@5..21
10+
ATTR@5..16
11+
12+
13+
PATH@7..15
14+
PATH_SEGMENT@7..15
15+
NAME_REF@7..15
16+
[email protected] "must_use"
17+
18+
1919
2020
2121
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const A: (i64, i64) = (1, #[cfg(test)] 2);

0 commit comments

Comments
 (0)