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

Leading pipes in patterns need to be preserved in the AST #76182

Closed
Aaron1011 opened this issue Aug 31, 2020 · 2 comments · Fixed by #76585
Closed

Leading pipes in patterns need to be preserved in the AST #76182

Aaron1011 opened this issue Aug 31, 2020 · 2 comments · Fixed by #76585
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-pretty Area: Pretty printing. A-proc-macros Area: Procedural macros C-bug Category: This is a bug.

Comments

@Aaron1011
Copy link
Member

The following code:

fn main() {
     match () { | () => () }
}

is currently pretty-printed as:

fn main() { match () { () => (), } }

If this occurs in a macro invocation, it leads to an instance of #43081

@Aaron1011 Aaron1011 added A-pretty Area: Pretty printing. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. A-proc-macros Area: Procedural macros labels Aug 31, 2020
@danielhenrymantilla
Copy link
Contributor

Extra info (but it boils down to what @Aaron1011 said):

Using

fn main ()
{
    match () { | () => () }
    let () = 42; // I was interested in seeing the error message being correctly spanned
}

I get the following log:

[INFO  rustc_parse] cached tokens found, but they're not "probably equal", going with stringified version
[INFO  rustc_parse] cached tokens: TokenStream([(Token(Token { kind: Ident("fn", false), span: examples/main.rs:4:1: 4:3 (#0) }), NonJoint), (Token(Token { kind: Ident("main", false), span: examples/main.rs:4:4: 4:8 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:4:9: 4:10 (#0), close: examples/main.rs:4:10: 4:11 (#0) }, Paren, TokenStream([])), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:5:1: 5:2 (#0), close: examples/main.rs:8:1: 8:2 (#0) }, Brace, TokenStream([(Token(Token { kind: Ident("match", false), span: examples/main.rs:6:5: 6:10 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:6:11: 6:12 (#0), close: examples/main.rs:6:12: 6:13 (#0) }, Paren, TokenStream([])), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:6:14: 6:15 (#0), close: examples/main.rs:6:27: 6:28 (#0) }, Brace, TokenStream([(Token(Token { kind: BinOp(Or), span: examples/main.rs:6:16: 6:17 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:6:18: 6:19 (#0), close: examples/main.rs:6:19: 6:20 (#0) }, Paren, TokenStream([])), NonJoint), (Token(Token { kind: FatArrow, span: examples/main.rs:6:21: 6:23 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:6:24: 6:25 (#0), close: examples/main.rs:6:25: 6:26 (#0) }, Paren, TokenStream([])), NonJoint)])), NonJoint), (Token(Token { kind: Ident("let", false), span: examples/main.rs:7:5: 7:8 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:7:9: 7:10 (#0), close: examples/main.rs:7:10: 7:11 (#0) }, Paren, TokenStream([])), NonJoint), (Token(Token { kind: Eq, span: examples/main.rs:7:12: 7:13 (#0) }), NonJoint), (Token(Token { kind: Literal(Lit { kind: Integer, symbol: "42", suffix: None }), span: examples/main.rs:7:14: 7:16 (#0) }), Joint), (Token(Token { kind: Semi, span: examples/main.rs:7:16: 7:17 (#0) }), NonJoint)])), NonJoint)])
[INFO  rustc_parse] reparsed tokens: TokenStream([(Token(Token { kind: Ident("fn", false), span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint), (Token(Token { kind: Ident("main", false), span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:1:1: 1:1 (#0), close: examples/main.rs:1:1: 1:1 (#0) }, Paren, TokenStream([])), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:1:1: 1:1 (#0), close: examples/main.rs:1:1: 1:1 (#0) }, Brace, TokenStream([(Token(Token { kind: Ident("match", false), span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:1:1: 1:1 (#0), close: examples/main.rs:1:1: 1:1 (#0) }, Paren, TokenStream([])), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:1:1: 1:1 (#0), close: examples/main.rs:1:1: 1:1 (#0) }, Brace, TokenStream([(Delimited(DelimSpan { open: examples/main.rs:1:1: 1:1 (#0), close: examples/main.rs:1:1: 1:1 (#0) }, Paren, TokenStream([])), NonJoint), (Token(Token { kind: FatArrow, span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:1:1: 1:1 (#0), close: examples/main.rs:1:1: 1:1 (#0) }, Paren, TokenStream([])), NonJoint), (Token(Token { kind: Comma, span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint)])), NonJoint), (Token(Token { kind: Ident("let", false), span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint), (Delimited(DelimSpan { open: examples/main.rs:1:1: 1:1 (#0), close: examples/main.rs:1:1: 1:1 (#0) }, Paren, TokenStream([])), NonJoint), (Token(Token { kind: Eq, span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint), (Token(Token { kind: Literal(Lit { kind: Integer, symbol: "42", suffix: None }), span: examples/main.rs:1:1: 1:1 (#0) }), Joint), (Token(Token { kind: Semi, span: examples/main.rs:1:1: 1:1 (#0) }), NonJoint)])), NonJoint)])

Rendered diff: https://www.textcompare.org/index.html?id=5f4d8b98086a55001745f791

@petrochenkov
Copy link
Contributor

This applies to all trailing separators in theory (except that the separator is leading rather than trailing in this case), but in other cases the difference is fixed up by fuzzy comparison in tokenstream_probably_equal_for_proc_macro.

Aaron1011 added a commit to Aaron1011/rust that referenced this issue Sep 1, 2020
Fixes rust-lang#76182

Previously, we did not preserve the precense of a leading vert ('|')
when parsing a pattern. This lead to an instance of rust-lang#43081 when invoking
a proc-macro, since the pretty-printed tokens would be missing the '|'
present in the captured tokens.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 12, 2020
…chenkov

Ignore `|` and `+` tokens during proc-macro pretty-print check

Fixes rust-lang#76182

This is an alternative to PR rust-lang#76188

These tokens are not preserved in the AST in certain cases
(e.g. a leading `|` in a pattern or a trailing `+` in a trait bound).

This PR ignores them entirely during the pretty-print/reparse check
to avoid spuriously using the re-parsed tokenstream.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 12, 2020
…chenkov

Ignore `|` and `+` tokens during proc-macro pretty-print check

Fixes rust-lang#76182

This is an alternative to PR rust-lang#76188

These tokens are not preserved in the AST in certain cases
(e.g. a leading `|` in a pattern or a trailing `+` in a trait bound).

This PR ignores them entirely during the pretty-print/reparse check
to avoid spuriously using the re-parsed tokenstream.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 12, 2020
…chenkov

Ignore `|` and `+` tokens during proc-macro pretty-print check

Fixes rust-lang#76182

This is an alternative to PR rust-lang#76188

These tokens are not preserved in the AST in certain cases
(e.g. a leading `|` in a pattern or a trailing `+` in a trait bound).

This PR ignores them entirely during the pretty-print/reparse check
to avoid spuriously using the re-parsed tokenstream.
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 13, 2020
…enkov

Ignore `|` and `+` tokens during proc-macro pretty-print check

Fixes rust-lang#76182

This is an alternative to PR rust-lang#76188

These tokens are not preserved in the AST in certain cases
(e.g. a leading `|` in a pattern or a trailing `+` in a trait bound).

This PR ignores them entirely during the pretty-print/reparse check
to avoid spuriously using the re-parsed tokenstream.
@bors bors closed this as completed in 283d4c4 Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-pretty Area: Pretty printing. A-proc-macros Area: Procedural macros C-bug Category: This is a bug.
Projects
None yet
3 participants