Skip to content

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

Merged
bors merged 7 commits into
rust-lang:masterfrom
rcoh:60762-raw-string-errors
Apr 1, 2020
Merged

Improve error messages for raw strings (#60762)#70522
bors merged 7 commits into
rust-lang:masterfrom
rcoh:60762-raw-string-errors

Conversation

@rcoh

@rcohrcoh commented Mar 29, 2020

Copy link
Copy Markdown
Contributor

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-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 29, 2020
@rcohrcoh closed this Mar 29, 2020
@rcohrcoh 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)
@rcoh
rcohforce-pushed the 60762-raw-string-errors branch from 0fc2569 to 629e97aCompareMarch 29, 2020 04:44
Comment threadsrc/librustc_lexer/src/cursor.rs Outdated
Comment threadsrc/librustc_lexer/src/lib.rs
Comment threadsrc/librustc_lexer/src/lib.rs Outdated
Comment threadsrc/librustc_lexer/src/lib.rs
Comment threadsrc/librustc_lexer/src/lib.rs Outdated
Comment threadsrc/librustc_parse/lexer/mod.rs Outdated
Comment threadsrc/librustc_parse/lexer/mod.rs Outdated
Comment threadsrc/librustc_parse/parser/diagnostics.rs Outdated
Comment threadsrc/librustc_parse/parser/diagnostics.rs Outdated
Comment threadsrc/librustc_parse/parser/diagnostics.rs Outdated
@Centril

Copy link
Copy Markdown
Contributor

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

r? @petrochenkov@matklad

Comment threadsrc/librustc_parse/parser/diagnostics.rs Outdated
Comment threadsrc/librustc_lexer/src/lib.rs Outdated
Comment threadsrc/librustc_parse/parser/diagnostics.rs Outdated
@petrochenkovpetrochenkov 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
@CentrilCentril 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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Mar 30, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 20e2190 has been approved by petrochenkov

@borsbors 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)
Fixesrust-lang#60762
cc @estebank who reviewed the original (abandoned) PR for the same ticket.
r? @Centril
@CentrilCentril mentioned this pull request Mar 30, 2020
@bors

bors commented Mar 30, 2020

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 20e2190 with merge a2e8ca2e8ec00ba36705760e1ff649cd620c531d...

@bors

bors commented Mar 30, 2020

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-azure

@borsbors 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
Copy Markdown
Contributor

@bors retry
(Looks like a network failure.)

@borsbors 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)
Fixesrust-lang#60762
cc @estebank who reviewed the original (abandoned) PR for the same ticket.
r? @Centril
@CentrilCentril mentioned this pull request Mar 31, 2020
@Centril

Copy link
Copy Markdown
Contributor

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

@borsbors 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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Mar 31, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 55a5eea has been approved by petrochenkov

@borsbors 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)
Fixesrust-lang#60762
cc @estebank who reviewed the original (abandoned) PR for the same ticket.
r? @Centril
@CentrilCentril mentioned this pull request Apr 1, 2020
@CentrilCentril mentioned this pull request Apr 1, 2020
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:masterApr 1, 2020
@CAD97

CAD97 commented Apr 4, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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

@rcoh@Centril@petrochenkov@bors@CAD97@matklad@rust-highfive