-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add more context to the literal overflow message #69995
Add more context to the literal overflow message #69995
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
ecabc77
to
9b0e6bc
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/librustc_lint/types.rs
Outdated
lint.build(&format!("literal out of range for `{}`", t.name_str())).emit() | ||
let mut err = lint.build(&format!("literal out of range for `{}`", t.name_str())); | ||
err.note(&format!( | ||
"the literal `{}` does not fit into an `{}` whose maximum is {}, minimum is {}", |
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.
Did you consider "whose range is {}..={}
"? That style is less verbose and easier for me to parse.
Also, a small nit, I would not say "an u16". Is there a way to phrase the message without an indefinite article?
@ecstatic-morse I agree. This seems like an improvement, but not a fix for that issue. |
src/librustc_lint/types.rs
Outdated
let mut err = lint.build(&format!("literal out of range for `{}`", t.name_str())); | ||
err.note(&format!( | ||
"the literal `{}` does not fit into an `{}` whose maximum is {}, minimum is {}", | ||
cx.sess() | ||
.source_map() | ||
.span_to_snippet(lit.span) | ||
.ok() | ||
.expect("must get snippet from literal"), | ||
t.name_str(), | ||
max, | ||
min | ||
)); | ||
err.emit() |
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.
You can use chaining here.
8eb0095
to
796c9d2
Compare
Thanks for the suggestions. I've updated the description and pushed a new commit. |
src/librustc_lint/types.rs
Outdated
lint.build(&format!("literal out of range for `{}`", t.name_str())).emit() | ||
lint.build(&format!("literal out of range for `{}`", t.name_str())) | ||
.note(&format!( | ||
"the literal `{}` does not fit into type `{}` as it is represents infinity", |
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.
Is this a typo?
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 am not sure what is a typo. What I intended to do is adding more context for f64
overflow.
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.
The "as it is represents infinity" part does not make sense to me. Does it mean the following?
"the literal `{}` does not fit into type `{}` as it is represents infinity", | |
"the literal `{}` does not fit into type `{}` and will be converted to `std::{}::INFINITY`", |
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.
Nice catch. Your error message is much more informative. Thanks. I will update it presently.
src/librustc_lint/types.rs
Outdated
lint.build(&format!("literal out of range for `{}`", t.name_str())).emit() | ||
lint.build(&format!("literal out of range for `{}`", t.name_str())) | ||
.note(&format!( | ||
"the literal `{}` does not fit into type `{}` whose range is {}..={}", |
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.
Since the range is a valid rust expression, I would write it in backticks.
"the literal `{}` does not fit into type `{}` whose range is {}..={}", | |
"the literal `{}` does not fit into the type `{}`, whose range is `{}..={}`", |
796c9d2
to
a4ffbaa
Compare
@bors r+ rollup |
📌 Commit a4ffbaa has been approved by |
…flow, r=ecstatic-morse Add more context to the literal overflow message related to issue rust-lang#63733
Rollup of 8 pull requests Successful merges: - #69686 (Use `pprust` to print attributes in rustdoc) - #69858 (std: on Windows, use GetSystemTimePreciseAsFileTime if it is available) - #69917 (Cleanup E0412 and E0422) - #69964 (Add Node.js to PR CI image) - #69992 (Block version-specific docs from search engines) - #69995 (Add more context to the literal overflow message) - #69998 (Add long error explanation for E0634) - #70014 (Small fixes in rustdoc book) Failed merges: r? @ghost
related to issue #63733