-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustc_span: improve bounds checks in byte_pos_to_line_and_col #78423
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
rustc_span: improve bounds checks in byte_pos_to_line_and_col #78423
Conversation
The effect of this change is to consider edge-case spans that start or end at the position one past the end of a file to be valid during span hashing and encoding. This change means that these spans will be preserved across incremental compilation sessions when they are part of a serialized query result, instead of causing the dummy span to be used.
r? @oli-obk (rust_highfive has picked a reviewer for you, use r? to override) |
The primary change is to go from an end-exclusive to an end-inclusive range check (by using To demonstrate the issue: fn main() {
println!("hello");
}
^ We generate spans that end here. If the Honestly, I'm unsure if this fixes any bugs or improves incremental reuse in edge-cases, but I noticed the issue, and it seems like the correct thing to do. Apologies for the lack of hard data, but I thought I should put this out there while it is fresh in my mind. |
It would indeed be hard to write a test for this, as we'd have to commit test files without trailing newlines. One thing I noticed while reviewing your change is that the What do you think about the above idea? |
I think it's a good idea, and I've made the change for |
Great! Thanks @bors r+ |
📌 Commit 47dad31 has been approved by |
…as-schievink Rollup of 11 pull requests Successful merges: - rust-lang#75078 (Improve documentation for slice strip_* functions) - rust-lang#76138 (Explain fully qualified syntax for `Rc` and `Arc`) - rust-lang#78244 (Dogfood {exclusive,half-open} ranges in compiler (nfc)) - rust-lang#78422 (Do not ICE on invalid input) - rust-lang#78423 (rustc_span: improve bounds checks in byte_pos_to_line_and_col) - rust-lang#78431 (Prefer new associated numeric consts in float error messages) - rust-lang#78462 (Use unwrapDIPtr because the Scope may be null.) - rust-lang#78493 (Update cargo) - rust-lang#78499 (Prevent String::retain from creating non-utf8 strings when abusing panic) - rust-lang#78505 (Update Clippy - temporary_cstring_as_ptr deprecation) - rust-lang#78527 (Fix some more typos) Failed merges: r? `@ghost`
The effect of this change is to consider edge-case spans that start or
end at the position one past the end of a file to be valid during span
hashing and encoding. This change means that these spans will be
preserved across incremental compilation sessions when they are part of
a serialized query result, instead of causing the dummy span to be used.