Reduce unreachable-code churn after todo!()#149543
Reduce unreachable-code churn after todo!()#149543llogiq wants to merge 1 commit 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 |
|
@rfcbot concern please-rename-lint (Filing this just to ensure the rename to |
|
Please also update the PR description, it seems to be quite outdated at the moment. |
5e3d4b0 to
19dc6dc
Compare
|
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in cc @BoxyUwU Some changes occurred to the CTFE machinery This PR changes a file inside This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_sanitizers cc @rcvalle Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
|
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. |
|
I think I fixed most errors in the tests and dogfooding of the lint. I have yet to rename it though. |
This comment has been minimized.
This comment has been minimized.
19dc6dc to
4c2b4fa
Compare
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
4c2b4fa to
9e26eae
Compare
This comment has been minimized.
This comment has been minimized.
9e26eae to
2ebfbca
Compare
This comment has been minimized.
This comment has been minimized.
2ebfbca to
ee994f8
Compare
This comment has been minimized.
This comment has been minimized.
ee994f8 to
d626981
Compare
|
Some changes occurred in compiler/rustc_codegen_gcc |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
I'm adding a boatload of allow annotations here, including on subprojects. At this point I wonder whether we should allow the lint in bootstrap somehow... |
|
☔ The latest upstream changes (presumably #154773) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I'm a bit unsure about the lint being warn by default. I think I would prefer it allow by default and I'd maybe turn it on for CI builds. (And I generally expect dev tools to favor the local development experience by default.) The mere presence of the macro in my code/diff, and the panicking behavior, is signal enough for me. But seeing the warning on every check build can be noisy when I'm working on something else in the moment. Turning the lint on by default makes the compiler more loud by default since IIUC most todo uses don't have unreachable code following it. On the other hand, allow by default makes the compiler less loud, but I think the delta is smaller. |
|
Yeah, I believe we settled on warn by default to avoid people running into unwanted panics. But I agree that it probably should be allow by default (I wish we had an option of making "allow in debug, warn on release" standard behavior). |
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.In lieu of the
unreachable_codelint, this PR also adds atodo_macro_useslint.I inserted the check after when we already found some unreachable code, so perf shouldn't suffer too badly.