-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix Debug for Location #142373
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
Fix Debug for Location #142373
Conversation
@bors r+ rollup |
#[test] | ||
fn location_debug() { | ||
let f = format!("{:?}", Location::caller()); | ||
assert!(f.contains("location.rs")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert!(f.contains("location.rs")); | |
assert!(f.contains("location.rs")); | |
assert!(!f.contains("\0")); | |
assert!(!f.contains("\\0")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I immediately clicked 'commit suggestion', but actually: i think this might cause funny failures:
If someone works on windows in a directory that starts with a 0
, the file name might be "C:\\Users\\0abc\\Rust\\..."
, which will contain \\0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to assert!(f.contains(&format!("{:?}", file!())));
. That way, it checks the entire file name including the surrounding quotes. Then we can be sure there's no additional \0
displayed.
@bors r- |
fn location_debug() { | ||
let f = format!("{:?}", Location::caller()); | ||
assert!(f.contains("location.rs")); | ||
assert!(f.contains("35")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose (line!() - 2).to_string()
would be more robust to test changes than literal 35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. But the other tests in this file also just hardcode the number. I like putting as little logic as possible in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize the entire file hardcodes them, 🤷♂️ in that case
363e07b
to
26155d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a squash, r=me again after that
26155d1
to
5ac1cd9
Compare
…ss35 Fix Debug for Location Fixes rust-lang#142279
Rollup of 8 pull requests Successful merges: - #140809 (Reduce special casing for the panic runtime) - #142082 (Refactor `rustc_attr_data_structures` documentation) - #142125 (Stabilize "file_lock" feature) - #142373 (Fix Debug for Location) - #142414 (ignore `run-make` tests that need `std` on targets without `std`) - #142416 (Assorted bootstrap cleanups (step 2)) - #142431 (Add initial version of snapshot tests to bootstrap) - #142528 (clarify `rustc_do_not_const_check` comment) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 12 pull requests Successful merges: - #141639 (Expose discriminant values in stable_mir) - #142082 (Refactor `rustc_attr_data_structures` documentation) - #142125 (Stabilize "file_lock" feature) - #142236 (Add documentation for `PathBuf`'s `FromIterator` and `Extend` impls) - #142373 (Fix Debug for Location) - #142416 (Assorted bootstrap cleanups (step 2)) - #142431 (Add initial version of snapshot tests to bootstrap) - #142450 (Add documentation on top of `rustc_middle/src/query/mod.rs`) - #142528 (clarify `rustc_do_not_const_check` comment) - #142530 (use `if let` guards where possible) - #142561 (Remove an `njn:` comment accidentaly left behind.) - #142566 (Fix `-nopt` CI jobs) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 12 pull requests Successful merges: - rust-lang#141639 (Expose discriminant values in stable_mir) - rust-lang#142082 (Refactor `rustc_attr_data_structures` documentation) - rust-lang#142125 (Stabilize "file_lock" feature) - rust-lang#142236 (Add documentation for `PathBuf`'s `FromIterator` and `Extend` impls) - rust-lang#142373 (Fix Debug for Location) - rust-lang#142416 (Assorted bootstrap cleanups (step 2)) - rust-lang#142431 (Add initial version of snapshot tests to bootstrap) - rust-lang#142450 (Add documentation on top of `rustc_middle/src/query/mod.rs`) - rust-lang#142528 (clarify `rustc_do_not_const_check` comment) - rust-lang#142530 (use `if let` guards where possible) - rust-lang#142561 (Remove an `njn:` comment accidentaly left behind.) - rust-lang#142566 (Fix `-nopt` CI jobs) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #142279