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

Improve error messages for raw strings (#60762) #70522

Merged
merged 7 commits into from
Apr 1, 2020

Conversation

rcoh
Copy link
Contributor

@rcoh rcoh commented Mar 29, 2020

This diff improves error messages around raw strings in a few ways:

  • Catch extra trailing # in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test)
  • Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings
  • Detect potentially intended terminators (longest sequence of "#*" is suggested)

Fixes #60762
cc @estebank who reviewed the original (abandoned) PR for the same ticket.
r? @Centril

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 29, 2020
@rcoh rcoh closed this Mar 29, 2020
@rcoh rcoh reopened this Mar 29, 2020
This diff improves error messages around raw strings in a few ways:
- Catch extra trailing `#` in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test)
- Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings
- Detect potentially intended terminators (longest sequence of "#*" is suggested)
src/librustc_lexer/src/lib.rs Show resolved Hide resolved
src/librustc_lexer/src/lib.rs Outdated Show resolved Hide resolved
src/librustc_lexer/src/lib.rs Outdated Show resolved Hide resolved
src/librustc_lexer/src/lib.rs Outdated Show resolved Hide resolved
src/librustc_parse/lexer/mod.rs Outdated Show resolved Hide resolved
src/librustc_parse/lexer/mod.rs Outdated Show resolved Hide resolved
src/librustc_parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
src/librustc_parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
src/librustc_parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
@Centril
Copy link
Contributor

Centril commented Mar 29, 2020

I've left some initial comments, but I'm not qualified to sign off on lexer changes myself.

r? @petrochenkov @matklad

src/librustc_lexer/src/lib.rs Outdated Show resolved Hide resolved
src/librustc_parse/parser/diagnostics.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2020
@Centril Centril added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 30, 2020
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 30, 2020

📌 Commit 20e2190 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 30, 2020
…rochenkov

Improve error messages for raw strings (rust-lang#60762)

This diff improves error messages around raw strings in a few ways:
- Catch extra trailing `#` in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test)
- Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings
- Detect potentially intended terminators (longest sequence of "#*" is suggested)

Fixes rust-lang#60762
cc @estebank who reviewed the original (abandoned) PR for the same ticket.
r? @Centril
@bors
Copy link
Contributor

bors commented Mar 30, 2020

⌛ Testing commit 20e2190 with merge a2e8ca2e8ec00ba36705760e1ff649cd620c531d...

@bors
Copy link
Contributor

bors commented Mar 30, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 30, 2020
@petrochenkov
Copy link
Contributor

@bors retry
(Looks like a network failure.)

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 31, 2020
…rochenkov

Improve error messages for raw strings (rust-lang#60762)

This diff improves error messages around raw strings in a few ways:
- Catch extra trailing `#` in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test)
- Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings
- Detect potentially intended terminators (longest sequence of "#*" is suggested)

Fixes rust-lang#60762
cc @estebank who reviewed the original (abandoned) PR for the same ticket.
r? @Centril
@Centril
Copy link
Contributor

Centril commented Mar 31, 2020

Failed in #70601 (comment), @bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 31, 2020
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 31, 2020

📌 Commit 55a5eea has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 31, 2020
Centril added a commit to Centril/rust that referenced this pull request Apr 1, 2020
…rochenkov

Improve error messages for raw strings (rust-lang#60762)

This diff improves error messages around raw strings in a few ways:
- Catch extra trailing `#` in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test)
- Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings
- Detect potentially intended terminators (longest sequence of "#*" is suggested)

Fixes rust-lang#60762
cc @estebank who reviewed the original (abandoned) PR for the same ticket.
r? @Centril
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2020
Rollup of 6 pull requests

Successful merges:

 - rust-lang#70511 (Add `-Z dump-mir-dataflow` flag for dumping dataflow results visualization)
 - rust-lang#70522 (Improve error messages for raw strings (rust-lang#60762))
 - rust-lang#70547 (Add `can_unwind` field to `FnAbi`)
 - rust-lang#70591 (Ensure LLVM is in the link path for "fulldeps" tests)
 - rust-lang#70627 (Use place directly its copy)
 - rust-lang#70652 (Add git repo address to unstable book)

Failed merges:

 - rust-lang#70634 (Remove some reexports in `rustc_middle`)

r? @ghost
@bors bors merged commit c739465 into rust-lang:master Apr 1, 2020
@CAD97
Copy link
Contributor

CAD97 commented Apr 4, 2020

cc @matklad is librustc_lexer really the right place to have this step for raw strings, or should that be up a level in librustc_parser's lexer cooking? (My gut says the latter.)

@matklad
Copy link
Member

matklad commented Apr 4, 2020

This seem to fit pretty well into the rustc_lexer interface, which returns tokens as a bunch of sub-offsets. Ideally, we should dissolve lexer cooking altogether and instead lower the tokens much later, after macro expansion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error for too many trailing #s in raw string literals could be improved
7 participants