Skip to content
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

Allow Or patterns in IfLet guard #103194

Closed
wants to merge 1 commit into from
Closed

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Oct 18, 2022

As mentioned in #88015 each subpattern creates a new local for 'x' which confuses the borrow checker about its initialization.

Fixes #88015

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 18, 2022
@rust-highfive
Copy link
Collaborator

r? @fee1-dead

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 18, 2022
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
failures:

---- [ui] src/test/ui/rfc-2294-if-let-guard/run-pass.rs stdout ----
normalized stderr:
warning: irrefutable `if let` guard pattern
   |
   |
LL |         () | () if let x = 0 => {
   |
   |
   = note: this pattern will always match, so the guard is useless
   = help: consider removing the guard and adding a `let` inside the match arm
   = note: `#[warn(irrefutable_let_patterns)]` on by default
warning: path statement with no effect
  --> $DIR/run-pass.rs:35:13
   |
LL |             x;
---
To only update this specific test, also pass `--test-args rfc-2294-if-let-guard/run-pass.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/rfc-2294-if-let-guard/run-pass.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rfc-2294-if-let-guard/run-pass/a" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/rfc-2294-if-let-guard/run-pass/auxiliary"
stdout: none
--- stderr -------------------------------
warning: irrefutable `if let` guard pattern
   |
   |
LL |         () | () if let x = 0 => {
   |
   |
   = note: this pattern will always match, so the guard is useless
   = help: consider removing the guard and adding a `let` inside the match arm
   = note: `#[warn(irrefutable_let_patterns)]` on by default
warning: path statement with no effect
  --> /checkout/src/test/ui/rfc-2294-if-let-guard/run-pass.rs:35:13
   |
LL |             x;

// This makes it so we only use last 'pat' in 'Or' pattern.
// See issue #88015 for more info.
if let PatKind::Or(pats) = &arm.pat.kind && self.is_guard_if_let(arm){
pat = self.lower_pat(pats.last().unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this lost parts of the patters in the or pattern? Doesn't this change the meaning of the program?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is indeed the wrong way to approach this problem, going to close it as I look for a new solution.

@ouz-a ouz-a closed this Oct 19, 2022
@ouz-a ouz-a deleted the issue-88015 branch July 26, 2023 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Locals aren't introduced properly in if-let guards on or-patterns
6 participants