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
INSP: Implement unreachable code detection #6829
Conversation
src/main/kotlin/org/rust/ide/inspections/lints/RsUnreachableCodeInspection.kt
Show resolved
Hide resolved
src/test/kotlin/org/rust/ide/inspections/lints/RsUnreachableCodeInspectionTest.kt
Outdated
Show resolved
Hide resolved
9206e64
to
0b7bb51
Compare
0b7bb51
to
9e13818
Compare
9e13818
to
01c1bb7
Compare
Note, although no regressions are found with CI (because the regression tests only search for error annotations, not warnings), there are some false positive warnings in real projects, mostly due to #6749, as I mentioned in the PR description. Here is what I found:
As we just briefly investigated with @vlad20012, However, I think we can merge this inspection because the number of false positives is not so much. @Undin WDYT? |
As we've discussed in person - let's try to fix type inference first not to introduce new false positive annotations for users. Looks like we can come up with at least some hack to make type inference work in described cases. |
@ortem BTW tests fail |
01c1bb7
to
b17e2d9
Compare
@Undin I'd like not to merge this PR right now because some false-positive warnings remained, with #6749 fixed:
So the most interesting case is macro_rules! break_macro {
() => { break };
}
fn main() {
loop {
break_macro!();
}
1; // false-positive "unreachable"
} I'm investigating the problem. If I don't find a solution soon then I'll disable the inspection by default and merge this PR. |
b17e2d9
to
8164858
Compare
I opened an issue for this case: #7016. |
8164858
to
4979b5d
Compare
bors r=dima74 |
6829: INSP: Implement unreachable code detection r=dima74 a=ortem This PR introduces `Unreachable code` inspection to detect and remove unreachable code. ![unreachable_code](https://user-images.githubusercontent.com/4854600/107639621-2ce9cc00-6c82-11eb-8a06-114953a733ab.gif) Note that now it might produce some false-positive warnings due to #6749 and #6797, so probably it's better to try fixing these issues before merging this. Some implementation details: * Based on the control-flow graph which is already used for several inspections (move analysis, liveness analysis) * Found unreachable elements are cached by `org.rust.lang.core.types.ExtensionsKt#CONTROL_FLOW_KEY` as well as the graph itself * Does not highlight each unreachable element separately, but merges their text ranges instead in order to highlight the widest range Part of #1612. changelog: Add `Unreachable code` inspection and quick-fix 6969: COMP: Improve dependency completion when using crates local index r=ortem a=avrong <img width="400" src="https://user-images.githubusercontent.com/6342851/111127949-6c5b4f00-8585-11eb-8a1f-e1284d32009d.gif"> changelog: Improve performance of dependencies completion in `Cargo.toml` using crates local index. This feature is disabled by default for now. To use it, enable `org.rust.crates.local.index` experimental feature Co-authored-by: ortem <ortem00@gmail.com> Co-authored-by: Aleksei Trifonov <avrong@avrong.me>
This PR was included in a batch that timed out, it will be automatically retried |
Build succeeded: |
This PR introduces
Unreachable code
inspection to detect and remove unreachable code.Note that now it might produce some false-positive warnings due to #6749 and #6797, so probably it's better to try fixing these issues before merging this.
Some implementation details:
org.rust.lang.core.types.ExtensionsKt#CONTROL_FLOW_KEY
as well as the graph itselfPart of #1612.
changelog: Add
Unreachable code
inspection and quick-fix