-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Allow unused variables with todo! #79850
Allow unused variables with todo! #79850
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (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. |
Macros cannot expand to inner attributes at all |
…ect the panic emitted by todo and skip checking for unused variables.
I think this PR should probably have a ui test to confirm that it's working? |
You mean a unit test? Where would that go? In core/tests.rs? |
Co-authored-by: Camelid <camelidcamel@gmail.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
let begin_panic_def_id = self.tcx.lang_items().begin_panic_fn(); | ||
if begin_panic_def_id == Some(*path_def_id) { |
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 UI test is failing; I think this is the wrong lang item. Sorry about that! I think we need to change this to catch core::panicking::panic
and core::panicking::panic_fmt
, but unfortunately there doesn't appear to be a lang item for panic_fmt
. So you may need to go back to using string comparisons :/
However, I'm out of my depth here so maybe someone else knows a better way (e.g. @m-ou-se
).
If you do end up needing to use the string comparison approach, you may want to use the TyCtxt::def_path_str()
method to get a path string for path_def_id
. You would use it like:
let path_str = self.tcx.def_path_str(path_def_id);
// Allow todo! macro | ||
/* | ||
Skips checking for unused variables when the trailing expression | ||
of the body is a panic with a message that contains "not yet implemented". |
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 would still include something saying that this is a somewhat hacky way to check if it's todo!
.
// builder doesn't like this being called without panic `self.tcx.def_path_str(*path_def_id);` | ||
let path_str = format!("{:?}", path_def_id); |
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.
What does this mean? Why did self.tcx.def_path_str
not work?
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.
It errors with:
thread 'rustc' panicked at 'no warnings or errors encountered even though `delayed_good_path_bugs` issued', compiler/rustc_errors/src/lib.rs:974:13
// builder doesn't like this being called without panic `self.tcx.def_path_str(*path_def_id);` | ||
let path_str = format!("{:?}", path_def_id); | ||
if Some(*path_def_id) == panic_fn | ||
|| ((path_str.contains("std[") || path_str.contains("core[")) |
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.
By the way, why does this use [
?
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 path_str is like core[76aa]::panicking::panic
. I was concerned about matching on some arbitrary crate with a matching path, though it's a bit unlikely. I actually think it should be ~ core[" .. "]::panicking::panic" ..
just to ensure that it only triggers for std / core.
☔ The latest upstream changes (presumably #82951) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage - @charles-r-earp @rustbot label: -S-waiting-on-review +S-waiting-on-author |
I like the thought of |
Something I have often found very useful when developing: Some way to trigger a warning during development that would be a hard error during ci. I use this to "make promises" to myself -- but also to my reviewer! -- when doing a patch series. e.g., I might write something broken but include a note that I will get around to fixing it later. In rustc development, I lean on tidy -- if you write Maybe |
This doesn't seem to be true anymore. I found 1012 FIXMEs in |
IIRC clippy will allow |
@camelid yeah, my bad, this used to be true; but we do still forbid |
Triage: It's not clear what the next steps should be here. From my understanding the next steps would be convert this comment into an issue describing what's the exact language behavior we want, and closing this PR. Could someone on t-lang confirm with this? |
I am nominating this PR for @rust-lang/lang team discussion. |
We discussed this in our @rust-lang/lang meeting on 2021-05-04. There was definitely a block of us -- maybe even a consensus -- who felt that, early on in the development process, the avalanche of warnings from rustc for "WIP" code could be more annoying than helpful. However, there was generally not a lot of enthusiasm for this particular proposal. One thing we were thinking about is the proposal from RFC 2383 (tracking issue: #54503) to add a The core idea for this was to enable people to silence "expected" lints for WIP things without accidentally leaving those silences lints in production code (a theme which also arose on this PR). Based on the conversation, I'm going to go and ahead and move to close, but if folks from @rust-lang/lang feel that's the wrong decision, please speak up. In any case, I'd like to encourage people to consider work on the @rfcbot fcp close |
Team member @nikomatsakis has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I don't know where to discuss about this
The idea being that exactly one warning is bearable on the dev iteration cycle, but it's still enough of a warning to avoid accidentally releasing it on production (we could even envision an extra |
@rfcbot reviewed Another possibility that comes to mind here is somehow deemphasizing some of the less important stylistic lints when there are also bigger concerns found. I agree that while in the middle of working on something I tend not to care about, say, having accidentally put parens around my |
@danielhenrymantilla the RFC in question is old enough that I personally wouldn't object to a fresh RFC in this area. I prefer the |
I'd love to have |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
Going to close. Thanks to all. |
Fixes #78136
As stated in the issue, todo! should imply that the function will be implemented at some point but isn't yet, and therefore the user shouldn't have to either apply the #[allow(unused_variables)] themselves or prefix the arguments with underscores, since they will at some point replace the todo! with an implementation. Unlike unimplemented, todo! is a placeholder, so the suggested prefixing of the arguments with underscores does not make sense because that would imply that those arguments are not going to be used, when in fact they may be used when the function is implemented. Once the todo! is removed, the lint will return if applicable.
The lint error is emitted in rustc_passes::liveness::Liveness::report_unused. This can be traced back to the <IrMaps as Visiter>::visit_body method. Unfortunately the Body argument here has been fully expanded, so we cannot match on the todo! macro directly. Instead, the idea is to detect a trailing expression, ie the last expression without a semicolon, that is core::panicking::panic (also std). If the panic is called with "not yet implemented", which is what is emitted by todo!, then we return early and don't do any checking for unused variables.
For example: