-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
reduce unreachable-code churn after todo!()
#149543
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
base: main
Are you sure you want to change the base?
Conversation
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
|
Could you please also add a link to the Zulip discussion? It would help provide context. Also, could you please add a test to demonstrate that it works? |
| && self.expr_guaranteed_to_constitute_read_for_never(expr) | ||
| { | ||
| self.diverges.set(self.diverges.get() | Diverges::always(expr.span)); | ||
| let diverges = if self.is_todo_macro(expr.span) { |
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.
If we find that this is too heavy on perf (which it would only be in macro-heavy crates where macros produce a lot of exprs of type !), we could first check that the expression has ExprKind::Call(path, [txt]) where path refers to core::panic::panic.
|
Here is the zulip thread. |
I added some code to the respective UI test. E.g. current rustc warns on |
|
r? @estebank |
310c17e to
af403c6
Compare
|
Open question: Should I add some docs to the |
|
I'd personally be happy to read a line about it in the docs, although I would understand that someone steps forward and explains whether/why it'd be off-topic? |
|
I'm unsure whether this is too cross-cutting a concern, which is why I'm asking. OTOH, creating another PR just for one line of docs seems wasteful. |
|
Perhaps something like: /// The `unreachable_code` lint will ignore code after a `todo!()`. The code will
/// however still be marked as unreachable, which may
/// have effects on type and lifetime checks.
This implies that |
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.
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's a bit hard to discover, but the right directory for the test is tests/ui/reachable
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'll move the test under a todo.rs there.
|
|
||
|
|
||
| fn foo() { | ||
| todo!(); |
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.
Can you also add a test for when another macro expands to todo!?
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! 👍
|
Reminder, once the PR becomes ready for a review, use |
|
I think having different lints for debug/release is a bad idea, but mentioning this change in todo's docs is good. Either way, this needs T-lang approval, as this is a lint change. Please write a comment explaining the proposal to the language team and nominate this PR for them. |
af403c6 to
a79858c
Compare
T-lang nominationThis PR makes the The downside is that a developer won't get any warning on a |
|
@rustbot ready |
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.
code changes look good me, marking as waiting on T-lang decision
|
This seems like a tradeoff, which varies depending on how you want to use On the one hand, I can understand that people might not want to be inundated by a whole pile of warnings about code in progress. On the other hand, sometimes people (myself included) use those warnings about unused parameters and similar to guide the writing of the code that's in progress. For instance, warnings about unused parameters tell me "the code needs to use that parameter, or you need to delete that parameter". That can lead to a form of incremental, compiler-warning-driven development. |
|
Could folks who have the workflow where they don't want those warnings elaborate somewhat on that workflow, to make it easier to understand? I'm wondering if it might make sense to have a new macro for code-in-progress that specifically suppresses warnings about it, so that people who want the "don't warn me" workflow can use that macro. Given that we already have |
In particular, it's very common for me to write a function that returns a struct, where one of the fields is harder to compute than the rest (or to experimentally add a field to an existing struct). I’d like to be able to I want to do “warning driven development”, as you put it, but the warnings aren’t cooperating with my request for “I want to do this part last” which I spell I don’t see it as a big deal to not get warnings for P.S. That workflow can be set up by the combination of this PR and |
This was prompted by a rant by /u/matthieum on /r/rust. The idea here is that while writing the code, either rust-analyzer or ourselves may insert
todo!()at places we intend to implement later. Unfortunately, that marks all following code as unreachable, which will prompt some lint churn.So to combat that, I modify the lint to check whether the unreachability stems from a
todo!()macro and in this case omit the lint (by settingdivergestoDiverges::WarnedAlwaysinstead ofAlways(..)). Hopefully that makes the unreachable code lint less churn-y during development and improve the developer experience.I inserted the check after when we already found some unreachable code, so perf shouldn't suffer too badly.