mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 05:13:35 +00:00
Fix array element attribute position
This commit is contained in:
parent
b2ed130ffd
commit
ed8d5c86e3
5 changed files with 60 additions and 36 deletions
|
|
@ -8,6 +8,28 @@ pub(super) fn inner_attributes(p: &mut Parser) {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn with_outer_attributes(
|
||||
p: &mut Parser,
|
||||
f: impl Fn(&mut Parser) -> Option<CompletedMarker>,
|
||||
) -> bool {
|
||||
let am = p.start();
|
||||
let has_attrs = p.at(T![#]);
|
||||
attributes::outer_attributes(p);
|
||||
let cm = f(p);
|
||||
let success = cm.is_some();
|
||||
|
||||
match (has_attrs, cm) {
|
||||
(true, Some(cm)) => {
|
||||
let kind = cm.kind();
|
||||
cm.undo_completion(p).abandon(p);
|
||||
am.complete(p, kind);
|
||||
}
|
||||
_ => am.abandon(p),
|
||||
}
|
||||
|
||||
success
|
||||
}
|
||||
|
||||
pub(super) fn outer_attributes(p: &mut Parser) {
|
||||
while p.at(T![#]) {
|
||||
attribute(p, false)
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ pub(super) enum StmtWithSemi {
|
|||
|
||||
const EXPR_FIRST: TokenSet = LHS_FIRST;
|
||||
|
||||
pub(super) fn expr(p: &mut Parser) -> BlockLike {
|
||||
pub(super) fn expr(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
|
||||
let r = Restrictions { forbid_structs: false, prefer_stmt: false };
|
||||
expr_bp(p, r, 1).1
|
||||
expr_bp(p, r, 1)
|
||||
}
|
||||
|
||||
pub(super) fn expr_stmt(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
|
||||
|
|
|
|||
|
|
@ -192,9 +192,8 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
|
|||
// 1,
|
||||
// 2,
|
||||
// ];
|
||||
attributes::outer_attributes(p);
|
||||
attributes::with_outer_attributes(p, |p| expr(p).0);
|
||||
|
||||
expr(p);
|
||||
if p.eat(T![;]) {
|
||||
expr(p);
|
||||
p.expect(T![']']);
|
||||
|
|
@ -212,12 +211,15 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
|
|||
// #[cfg(test)]
|
||||
// 2,
|
||||
// ];
|
||||
attributes::outer_attributes(p);
|
||||
if !p.at_ts(EXPR_FIRST) {
|
||||
p.error("expected expression");
|
||||
if !attributes::with_outer_attributes(p, |p| {
|
||||
if !p.at_ts(EXPR_FIRST) {
|
||||
p.error("expected expression");
|
||||
return None;
|
||||
}
|
||||
expr(p).0
|
||||
}) {
|
||||
break;
|
||||
}
|
||||
expr(p);
|
||||
}
|
||||
p.expect(T![']']);
|
||||
m.complete(p, ARRAY_EXPR)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue