Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array element attribute position #2827

Merged
merged 2 commits into from
Jan 16, 2020

Conversation

edwin0cheng
Copy link
Member

@edwin0cheng edwin0cheng commented Jan 13, 2020

This PR fixed a bug which an ATTR node insert in the wrong place in array element. And introduce precede_next for allow outer attributes to insert into a parsed expr.

related #2783

@matklad
Copy link
Member

matklad commented Jan 15, 2020

I think it should be possible to achieve this without precede_next. We already handle this in some cases:

const _: &str = { #[attr] "Hello" };
CONST_DEF@[33; 69)
  CONST_KW@[33; 38) "const"
  WHITESPACE@[38; 39) " "
  UNDERSCORE@[39; 40) "_"
  COLON@[40; 41) ":"
  WHITESPACE@[41; 42) " "
  REFERENCE_TYPE@[42; 46)
    AMP@[42; 43) "&"
    PATH_TYPE@[43; 46)
      PATH@[43; 46)
        PATH_SEGMENT@[43; 46)
          NAME_REF@[43; 46)
            IDENT@[43; 46) "str"
  WHITESPACE@[46; 47) " "
  EQ@[47; 48) "="
  WHITESPACE@[48; 49) " "
  BLOCK_EXPR@[49; 68)
    BLOCK@[49; 68)
      L_CURLY@[49; 50) "{"
      WHITESPACE@[50; 51) " "
      LITERAL@[51; 66)
        ATTR@[51; 58)
          POUND@[51; 52) "#"
          L_BRACK@[52; 53) "["
          PATH@[53; 57)
            PATH_SEGMENT@[53; 57)
              NAME_REF@[53; 57)
                IDENT@[53; 57) "attr"
          R_BRACK@[57; 58) "]"
        WHITESPACE@[58; 59) " "
        STRING@[59; 66) "\"Hello\""
      WHITESPACE@[66; 67) " "
      R_CURLY@[67; 68) "}"
  SEMI@[68; 69) ";"

Seems like this can be extended to arguments as well.

The case above is handled by stmt function, it works roughly like this:

let m = p.start();
let has_attrs = p.at(T![#]);
attributes::outer_attributes(p);

let (cm, _) = expr_stmt(p);

if let Some(cm) = cm {
    let kind = cm.kind();
    cm.undo_completion(p).abandon(p);
    m.complete(p, kind);
}

@edwin0cheng
Copy link
Member Author

Fixed. 👍

@matklad
Copy link
Member

matklad commented Jan 16, 2020

bors r+

bors bot added a commit that referenced this pull request Jan 16, 2020
2827: Fix array element attribute position r=matklad a=edwin0cheng

This PR fixed a bug which an ATTR node insert in the wrong place in array element. ~~And introduce `precede_next` for allow outer attributes to insert into a parsed `expr`.~~  

related #2783

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jan 16, 2020

Build failed

  • Rust (macos-latest)
  • Rust (ubuntu-latest)

@edwin0cheng
Copy link
Member Author

bors retry

bors bot added a commit that referenced this pull request Jan 16, 2020
2827: Fix array element attribute position r=matklad a=edwin0cheng

This PR fixed a bug which an ATTR node insert in the wrong place in array element. ~~And introduce `precede_next` for allow outer attributes to insert into a parsed `expr`.~~  

related #2783

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jan 16, 2020

Build succeeded

  • Rust (macos-latest)
  • Rust (ubuntu-latest)
  • TypeScript

@bors bors bot merged commit a766883 into rust-lang:master Jan 16, 2020
@edwin0cheng edwin0cheng deleted the fix-array-element-attr branch January 16, 2020 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants