about summary refs log tree commit diff
path: root/tests/ui/rfcs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-01 10:54:56 +0000
committerbors <bors@rust-lang.org>2023-09-01 10:54:56 +0000
commitf4555ef5e14e8f0630fc5ad4e8efaef56d4acd4b (patch)
treeeffb3c6b2888a0468816146264748f65c46d9407 /tests/ui/rfcs
parentd6b4d35d5e94f6a1577e0e645fb23afc84615a6c (diff)
parent67553e8a11837c4b18657eedfcc272057e532bad (diff)
downloadrust-f4555ef5e14e8f0630fc5ad4e8efaef56d4acd4b.tar.gz
rust-f4555ef5e14e8f0630fc5ad4e8efaef56d4acd4b.zip
Auto merge of #111752 - dingxiangfei2009:lower-or-pattern, r=cjgillot
Lower `Or` pattern without allocating place

cc `@azizghuloum` `@cjgillot`

Related to #111583 and #111644

While reviewing #111644, it occurs to me that while we directly lower conjunctive predicates, which are connected with `&&`, into the desirable control flow, today we don't directly lower the disjunctive predicates, which are connected with `||`, in the similar fashion. Instead, we allocate a place for the boolean temporary to hold the result of evaluating the `||` expression.

Usually I would expect optimization at later stages to "inline" the evaluation of boolean predicates into simple CFG, but #111583 is an example where `&&` is failing to be optimized away and the assembly shows that both the expensive operands are evaluated. Therefore, I would like to make a small change to make the CFG a bit more straight-forward without invoking the `as_temp` machinery, and plus avoid allocating the place to hold the boolean result as well.
Diffstat (limited to 'tests/ui/rfcs')
-rw-r--r--tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs5
-rw-r--r--tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr33
2 files changed, 2 insertions, 36 deletions
diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs
index e0dded15217..2c0571a7bdd 100644
--- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs
+++ b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs
@@ -1,19 +1,18 @@
+// check-pass
+
 fn and_chain() {
     let z;
     if true && { z = 3; true} && z == 3 {}
-    //~^ ERROR E0381
 }
 
 fn and_chain_2() {
     let z;
     true && { z = 3; true} && z == 3;
-    //~^ ERROR E0381
 }
 
 fn or_chain() {
     let z;
     if false || { z = 3; false} || z == 3 {}
-    //~^ ERROR E0381
 }
 
 fn main() {
diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr
deleted file mode 100644
index 30d5a6779fc..00000000000
--- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr
+++ /dev/null
@@ -1,33 +0,0 @@
-error[E0381]: used binding `z` is possibly-uninitialized
-  --> $DIR/chains-without-let.rs:3:34
-   |
-LL |     let z;
-   |         - binding declared here but left uninitialized
-LL |     if true && { z = 3; true} && z == 3 {}
-   |                  -----           ^ `z` used here but it is possibly-uninitialized
-   |                  |
-   |                  binding initialized here in some conditions
-
-error[E0381]: used binding `z` is possibly-uninitialized
-  --> $DIR/chains-without-let.rs:9:31
-   |
-LL |     let z;
-   |         - binding declared here but left uninitialized
-LL |     true && { z = 3; true} && z == 3;
-   |               -----           ^ `z` used here but it is possibly-uninitialized
-   |               |
-   |               binding initialized here in some conditions
-
-error[E0381]: used binding `z` is possibly-uninitialized
-  --> $DIR/chains-without-let.rs:15:36
-   |
-LL |     let z;
-   |         - binding declared here but left uninitialized
-LL |     if false || { z = 3; false} || z == 3 {}
-   |                   -----            ^ `z` used here but it is possibly-uninitialized
-   |                   |
-   |                   binding initialized here in some conditions
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0381`.