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

Handle Spans for byte and raw strings and add more detail #81307

Merged
merged 1 commit into from
Feb 5, 2021

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jan 23, 2021

CC #81208.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 23, 2021
@estebank estebank added beta-nominated Nominated for backporting to the compiler in the beta channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 23, 2021
@estebank
Copy link
Contributor Author

cc @wesleywiser

@petrochenkov
Copy link
Contributor

r? @petrochenkov

@petrochenkov
Copy link
Contributor

I knew something was wrong here, the ICE doesn't happen because #s are counted incorrectly, the ICE happens because emit_unescape_error performs arithmetic on the overridden span (StringReader::override_span) which may be entirely arbitrary, but happens to point to the full byte string literal in this case.
So this change fixing the issue is a pure accident, and for other override_spans (e.g. from proc macros) it will still ICE.

@petrochenkov
Copy link
Contributor

The linked issue is fixed in #81337 by avoiding reparsing values in key-value attributes for the second time (that's where the overridden span is used).

The issue with emit_unescape_error doing arithmetic on arbitrary spans still remain.

@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. beta-nominated Nominated for backporting to the compiler in the beta channel. labels Jan 24, 2021
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 25, 2021
@estebank
Copy link
Contributor Author

@petrochenkov addressed your comments and see that you fixed the underlying issue. While I was in this file I updated the diagnostics to bring the up to our current standard of quality.

@estebank estebank force-pushed the invalid-byte-str-span branch 2 times, most recently from adbcd26 to 234e55c Compare January 26, 2021 18:23
} else {
diag.help(
"for more information, visit \
<https://static.rust-lang.org/doc/master/reference.html#literals>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which cases we link to the reference from error messages?
In theory, there's a reference page for every error, but in practice the diagnostics are already too noisy, so perhaps it's not a good idea to add such links just in case, without a strong specific reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case where this one triggers when using a "fake" escape, like \y. We could enumerate all the possible ones that are valid, but feared that would be too verbose. Every other case handled in this document provides enough information inline. I'm more worried about the link being stale. The reason I'm adding it is because these escapes are hard to search for.

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs Outdated Show resolved Hide resolved
compiler/rustc_parse/src/lexer/mod.rs Outdated Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

The PR name and description need an update.

@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 Jan 27, 2021
@bors

This comment has been minimized.

@estebank estebank changed the title Properly handle Spans for byte and raw strings Handle Spans for byte and raw strings and add more detail Feb 3, 2021
@petrochenkov petrochenkov 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 Feb 4, 2021
@petrochenkov
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Feb 4, 2021

📌 Commit 3b5d018 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 Feb 4, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Feb 5, 2021
…etrochenkov

Handle `Span`s for byte and raw strings and add more detail

CC rust-lang#81208.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2021
Rollup of 15 pull requests

Successful merges:

 - rust-lang#79554 (Generic associated types in trait paths)
 - rust-lang#80726 (relax adt unsizing requirements)
 - rust-lang#81307 (Handle `Span`s for byte and raw strings and add more detail )
 - rust-lang#81318 (rustdoc-json: Fix has_body)
 - rust-lang#81456 (Make remote-test-server easier to use with new targets)
 - rust-lang#81497 (rustdoc: Move `display_fn` struct inside `display_fn`)
 - rust-lang#81500 (Remove struct_type from union output)
 - rust-lang#81542 (Expose correct symlink API on WASI)
 - rust-lang#81676 (Add more information to the error code for 'crate not found')
 - rust-lang#81682 (Add additional bitset benchmarks)
 - rust-lang#81730 (Make `Allocator` object-safe)
 - rust-lang#81763 (Cleanup rustdoc pass descriptions a bit)
 - rust-lang#81767 (Update LayoutError/LayoutErr stability attributes)
 - rust-lang#81771 (Indicate change in RSS from start to end of pass in time-passes output)
 - rust-lang#81781 (Fix `install-awscli.sh` error in CI)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8d49ca1 into rust-lang:master Feb 5, 2021
@rustbot rustbot added this to the 1.51.0 milestone Feb 5, 2021
@estebank estebank deleted the invalid-byte-str-span branch November 9, 2023 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

8 participants