-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rust: Improve CFG for let
expressions
#18007
Conversation
Do we want to support this? Using When I was looking at CFG inconsistencies in the projects we have on DCA the Rust compiler was the only project using this syntax. |
Oh, I had no idea that this was experimental. Given the simplicity of supporting it, I think we should do it. |
The Rust compiler complains about it by default. There's an issue tracking the feature here. But yes, if it is simple then it won't hurt to support. And it should fix quite a few CFG inconsistencies on the Rust compiler. |
5478237
to
74b5ebe
Compare
false | ||
} | ||
} | ||
|
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.
Here's another example that I think results in a dead-end. As far as I recall, when I looked at the Rust code base, this pattern of starting with let
and then having some conditions was by far the most common.
fn test_and_if_let3(a: bool, b: Option<i64>, c: bool) -> bool { | |
if let Some(d) = b && c && c { | |
d > 0 | |
} else { | |
false | |
} | |
} | |
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.
Let's perhaps do that in a follow-up PR?
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 don't think there's much value in adding partial support for let
expressions without handling that (most common) case as well.
Is that change orthogonal to the one in this PR? If yes, then doing it in a follow up PR seems fine, otherwise I think I'd be easier to review the changes together.
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.
Yes, it's orthogonal to this PR; this PR merely improves CFG splitting a bit (see example in the PR description).
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.
Ok, great :)
} | ||
|
||
fn test_and_if_let2(a: bool, b: i64, c: bool) -> bool { | ||
if a && let d = b && c{ |
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 a && let d = b && c{ | |
if a && let d = b && c { |
@@ -141,6 +141,24 @@ | |||
0 | |||
} | |||
|
|||
fn test_and_if_let(a: bool, b: Option<bool>, c: bool) -> bool { | |||
if a && let Some(d) = b { |
Check notice
Code scanning / CodeQL
Unused variable Note test
} | ||
|
||
fn test_and_if_let2(a: bool, b: i64, c: bool) -> bool { | ||
if a && let d = b |
Check notice
Code scanning / CodeQL
Unused variable Note test
Example:
CFG before:
CFG after: