Merge pull request #18007 from hvitved/rust/cfg/and-let

Rust: Improve CFG for `let` expressions
This commit is contained in:
Tom Hvitved
2024-11-19 10:23:32 +01:00
committed by GitHub
3 changed files with 789 additions and 701 deletions

View File

@@ -71,7 +71,13 @@ module ConditionalCompletionSplitting {
child = parent.(LogicalNotExpr).getExpr() and
childCompletion.getDual() = parentCompletion
or
childCompletion = parentCompletion and
(
childCompletion = parentCompletion
or
// needed for `let` expressions
childCompletion.(MatchCompletion).getValue() =
parentCompletion.(BooleanCompletion).getValue()
) and
(
child = parent.(BinaryLogicalOperation).getAnOperand()
or

File diff suppressed because it is too large Load Diff

View File

@@ -62,15 +62,15 @@ mod loop_expression {
}
fn test_loop_label_shadowing(b: bool) -> ! {
'loop: loop {
'label: loop {
1;
'loop: loop {
'label: loop {
if b {
continue;
} else if b {
continue 'loop;
continue 'label;
}
continue 'loop;
continue 'label;
}
}
}
@@ -141,6 +141,24 @@ mod if_expression {
0
}
fn test_and_if_let(a: bool, b: Option<bool>, c: bool) -> bool {
if a && let Some(d) = b {
d
} else {
false
}
}
fn test_and_if_let2(a: bool, b: i64, c: bool) -> bool {
if a && let d = b
&& c
{
d > 0
} else {
false
}
}
fn test_nested_if(a: i64) -> i64 {
if (if a < 0 { a < -10 } else { a > 10 }) {
1
@@ -262,6 +280,10 @@ mod logical_operators {
false
}
}
fn test_and_return(a: bool) {
a && return;
}
}
mod question_mark_operator {