Reduce unreachable-code churn after todo!()#149543
Reduce unreachable-code churn after todo!()#149543llogiq wants to merge 4 commits intorust-lang:mainfrom
unreachable-code churn after todo!()#149543Conversation
|
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.
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.
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.
I'll move the test under a todo.rs there.
|
|
||
|
|
||
| fn foo() { | ||
| todo!(); |
There was a problem hiding this comment.
Can you also add a test for when another macro expands to todo!?
|
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 |
One reason we ultimately settled on
I think what should happen there, assuming it's trivial, is that we lint at the point where That said, we can refine it further in the future.
We weren't clear on what you were asking here. |
I was asking about the check to suppress the I'm totally on board with the I'll see if I find the time to write up an RFC, too. |
unreachable-code churn after todo!()unreachable-code churn after todo!()
That's an interesting question. E.g., should someone be able to write and publish a wrapper macro and expect for users of it to get the same behavior? #[macro_export]
macro_rules! dbg_todo {
($x:expr) => {
dbg!($x);
todo!()
};
}Maybe there are plausible use cases. If we didn't do it by default, I could imagine wanting to give macro authors some way to opt-in to it. In any case, this would be a good topic for an RFC on this to discuss in some detail. |
|
I think that while this may be an option to give macro authors, I feel like this is besides the goal I followed with this PR, that is reducing lint churn while working on code, under the assumption that |
|
Yes, makes sense. |
b0aa510 to
a871b50
Compare
This comment has been minimized.
This comment has been minimized.
|
I seem to have a problem getting the |
This comment has been minimized.
This comment has been minimized.
a871b50 to
5161e83
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
So now I got the lint to do what I want, however the @traviscross is that OK? Do you require further changes? |
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
|
Lang RFC: rust-lang/rfcs#3928 |
This comment has been minimized.
This comment has been minimized.
949b7e4 to
5e3d4b0
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@llogiq I don't understand most of the |
|
@samueltardieu thanks, I didn't know that. |
View all comments
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.