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

Surprising whitespace sensitivity in type parameters #47856

Closed
matklad opened this issue Jan 29, 2018 · 2 comments
Closed

Surprising whitespace sensitivity in type parameters #47856

matklad opened this issue Jan 29, 2018 · 2 comments
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug.

Comments

@matklad
Copy link
Member

matklad commented Jan 29, 2018

Consider this code:

struct Ok <T: Clone + = ()> { t: T }

struct Err<T: Clone +=  ()> { t: T }

The Ok struct compiles just right, but the Err one fails with

error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `+=`
 --> main.rs:2:21
  |
2 | struct Err<T: Clone +=  ()> { t: T }
  |                     ^^ expected one of 7 possible tokens here

error: aborting due to previous error

I think this behavior is wrong: for tokens like >> or || use use "context sensitive" lexing.

@petrochenkov
Copy link
Contributor

Yeah, "token splitting" (&& -> & & or += -> + =) is done very inconsistently.
It's not done automatically, but manually if the code author expects the split version to result in valid code sometimes. It looks like nobody expected + = to be a fragment of valid code in this position.

@TimNN TimNN added A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. labels Jan 30, 2018
@Crazycolorz5
Copy link
Contributor

I assume no one would mind if I took a look at this.

bors added a commit that referenced this issue Jun 9, 2018
parser: Split `+=` into `+` and `=` where `+` is explicitly requested (such as generics)

Added functions in tokens to check whether a token leads with `+`. Used them when parsing to allow for token splitting of `+=` into `+` and `=`.
Fixes #47856
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants