-
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
Clearer error message for dead assign #56439
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
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 |
To further clarify what's being linted, the warning should also highlight the value it's talking about, not the variable the value is assigned to |
@jonas-schievink makes sense - I'm not sure I'd know how to do that though (without making a lot of changes to this file) |
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 |
Perhaps the "overwritten" message can be reported only if the value is actually overwritten, not simply unread? If there's no necessary infra, then the wording change seems okay. |
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/middle/liveness.rs
Outdated
} else { | ||
self.ir.tcx.lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp, | ||
&format!("value assigned to `{}` is never read", name)); | ||
&format!("value assigned to `{}` is never read | ||
(maybe it is overwritten before being read)", name)); |
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.
Hmm, it's a nice idea to make a suggestion like this. It'd be nicer if we could find the overwriting assignment. But i'm reluctant to suggest trying to implement that, since this liveness code is ripe to be rewritten completely.
Still, I think that including the suggestion in a parenthetical makes it less likely to be noticed, and more likely to wrap around on the terminal.
A middle option would be to create a "help". You could change this code from self.ir.tcx.lint_hir(..)
to:
let msg = self.ir.tcx.self.struct_span_lint_hir(...)
.help("maybe it is overwritten before being read?")
.emit();
and I think things would look better.
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.
Sounds good to me.
I could try rewriting the liveness code, but I don't think I know enough about how it works...
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'd love to talk you through it =) but it'd obviously be a rather bigger endeavor :)
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'm happy to try :)
@bors r+ rollup |
📌 Commit c0e3f4b has been approved by |
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Clearer error message for dead assign I'm not that this is the right place for this (if it needs an RFC or not). I had the problem where I misunderstood the compiler lint message rust-lang#56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/. I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons. I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change. If this is the wrong place for this sort of thing I'll happily delete/move it.
Rollup of 20 pull requests Successful merges: - #53506 (Documentation for impl From for AtomicBool and other Atomic types) - #56343 (Remove not used mod) - #56439 (Clearer error message for dead assign) - #56640 (Add FreeBSD unsigned char platforms to std::os::raw) - #56648 (Fix BTreeMap UB) - #56672 (Document time of back operations of a Linked List) - #56706 (Make `const unsafe fn` bodies `unsafe`) - #56742 (infer: remove Box from a returned Iterator) - #56761 (Suggest using `.display()` when trying to print a `Path`) - #56781 (Update LLVM submodule) - #56789 (rustc: Add an unstable `simd_select_bitmask` intrinsic) - #56790 (Make RValue::Discriminant a normal Shallow read) - #56793 (rustdoc: look for comments when scraping attributes/crates from doctests) - #56826 (rustc: Add the `cmpxchg16b` target feature on x86/x86_64) - #56832 (std: Use `rustc_demangle` from crates.io) - #56844 (Improve CSS rule) - #56850 (Fixed issue with using `Self` ctor in typedefs) - #56855 (Remove u8 cttz hack) - #56857 (Fix a small mistake regarding NaNs in a deprecation message) - #56858 (Fix doc of `std::fs::canonicalize`) Failed merges: - #56741 (treat ref-to-raw cast like a reborrow: do a special kind of retag) r? @ghost
I'm not that this is the right place for this (if it needs an RFC or not).
I had the problem where I misunderstood the compiler lint message #56436 and other people seem to have had the same problem https://www.reddit.com/r/rust/comments/8cy9p4/value_assigned_to_is_never_read/.
I think this new wording might be slightly clearer (and help out beginners like me). I'm very new though, so there might be some nuance I'm missing that would make this more confusing or a bad idea for other reasons.
I thought I would create a PR to make it easy to change the code if the consensus was that it would make sense to make a change.
If this is the wrong place for this sort of thing I'll happily delete/move it.