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

Comments

Projects
None yet
5 participants
@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

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jan 29, 2018

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.

@Crazycolorz5

This comment has been minimized.

Copy link
Contributor

Crazycolorz5 commented May 25, 2018

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

bors added a commit that referenced this issue Jun 9, 2018

Auto merge of #51068 - Crazycolorz5:pluseqsplitting, r=petrochenkov
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

@bors bors closed this in #51068 Jun 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.