Skip to content

ICE: Pattern mutability cap violated! #136223

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn main() {
    if let &Some(Some(x)) = &Some(&mut Some(0)) {}
}

original:

fn main(e: &mut &&mut Foo) {
    if let &Some(Some(x)) = &Some(&mut Some(0)) {
        let _: &u32 = x;
    }
    if let Some(&x) = Some(&mut 0) {
        let _: u32 = x;
    }
}

Version information

rustc 1.86.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.86.0-dev
LLVM version: 19.1.7

Possibly related line of code:

def_br: ByRef,
adjust_mode: AdjustMode,
max_ref_mutbl: MutblCap,
) -> (Ty<'tcx>, ByRef, MutblCap) {
#[cfg(debug_assertions)]
if def_br == ByRef::Yes(Mutability::Mut) && max_ref_mutbl != MutblCap::Mut {
span_bug!(pat.span, "Pattern mutability cap violated!");
}
match adjust_mode {
AdjustMode::Pass => (expected, def_br, max_ref_mutbl),
AdjustMode::Reset => (expected, ByRef::No, MutblCap::Mut),
AdjustMode::Peel => self.peel_off_references(pat, expected, def_br, max_ref_mutbl),
}

Metadata

Metadata

Assignees

Labels

A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-debug-assertionsThis issue requires a build of rustc or tooling with debug-assertions in some way

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions