Skip to content

Spurious irrefutable_let_patterns warning #141365

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

Closed
obsgolem opened this issue May 21, 2025 · 2 comments
Closed

Spurious irrefutable_let_patterns warning #141365

obsgolem opened this issue May 21, 2025 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@obsgolem
Copy link
Contributor

obsgolem commented May 21, 2025

Code

use pubgrub::{OfflineDependencyProvider, PubGrubError, Range};

fn f() -> PubGrubError<OfflineDependencyProvider<String, Range<u32>>> {
    todo!();
}

fn main() {
    if let pubgrub::PubGrubError::NoSolution(der) = f() {
    } else {
    }
}

requires

pubgrub = { git = "https://github.com/pubgrub-rs/pubgrub.git" }

Current output

Compiling equivalent v1.0.2
   Compiling hashbrown v0.15.3
   Compiling smallvec v1.15.0
   Compiling rustc-hash v2.1.1
   Compiling log v0.4.27
   Compiling thiserror v2.0.12
   Compiling version-ranges v0.1.1 (https://github.com/pubgrub-rs/pubgrub.git#b90cd72e)
   Compiling indexmap v2.9.0
   Compiling priority-queue v2.3.1
   Compiling pubgrub v0.3.0 (https://github.com/pubgrub-rs/pubgrub.git#b90cd72e)
   Compiling tmp v0.1.0 (C:\Users\jbills\Document\Code\tmp)
warning: irrefutable `if let` pattern
 --> src\main.rs:8:8
  |
8 |     if let pubgrub::PubGrubError::NoSolution(der) = f() {
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this pattern will always match, so the `if let` is useless
  = help: consider replacing the `if let` with a `let`
  = note: `#[warn(irrefutable_let_patterns)]` on by default

warning: unused variable: `der`
 --> src\main.rs:8:46
  |
8 |     if let pubgrub::PubGrubError::NoSolution(der) = f() {
  |                                              ^^^ help: if this is intentional, prefix it with an underscore: `_der`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `tmp` (bin "tmp") generated 2 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.63s

Desired output

No warning

Rationale and extra context

Distinct from #139369. No let chains in sight. The relevant enum has multiple cases, and the compiler correctly diagnoses an error if I remove the if.

Other cases

Rust Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-pc-windows-msvc
release: 1.87.0
LLVM version: 20.1.1

Also tested on 
rustc 1.89.0-nightly (bc8215286 2025-05-20)
binary: rustc
commit-hash: bc821528634632b4ff8dee5ac1ea4ad90d1b3eb5
commit-date: 2025-05-20
host: x86_64-pc-windows-msvc
release: 1.89.0-nightly
LLVM version: 20.1.5

Anything else?

No response

@obsgolem obsgolem added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 21, 2025
@compiler-errors
Copy link
Member

The relevant enum has multiple cases, and the compiler correctly diagnoses an error if I remove the if.

This code works fine for me?

use pubgrub::{OfflineDependencyProvider, PubGrubError, Range};

fn f() -> PubGrubError<OfflineDependencyProvider<String, Range<u32>>> {
    todo!();
}

fn main() {
    let pubgrub::PubGrubError::NoSolution(der) = f();
}

The pattern is really irrefutable, since <OfflineDependencyProvider<..> as DependencyProvider>::Error = Infallible, so all the other variants of PubGrubError are impossible to construct.

@obsgolem
Copy link
Contributor Author

Ah, I see, I am getting an error from RA, not from the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants