Skip to content

false report of "missing match arm" when matching on nested pattern with unknown type #14164

@8051Enthusiast

Description

@8051Enthusiast

rust-analyzer version: 0.3.1402
rustc version: 1.69.0-nightly (2d14db321 2023-02-15), rustc 1.67.1 (d5a82bbd2 2023-02-07)
relevant settings: uses vs code with fairly standard settings

somewhat minimized example
pub trait ExpressionPart: Sized {
    type K: ExpressionKind;
    type TransExpr<ToK: ExpressionKind>: ExpressionPart<K = ToK>;
}

pub struct ExpressionHead<K: ExpressionKind>(K::MonadicOp);

impl<K: ExpressionKind> ExpressionPart for ExpressionHead<K> {
    type K = K;
    type TransExpr<ToK: ExpressionKind> = ExpressionHead<ToK>;
}

pub trait ExpressionKind {
    type MonadicOp;
}

pub trait Expression<K: ExpressionKind>: Sized {
    type Part: ExpressionPart<K = K>;
    fn fold(self, _: impl FnMut(<Self::Part as ExpressionPart>::TransExpr<K>)) {
        todo!()
    }
}

pub struct IdxExpression<K: ExpressionKind> {
    pub heads: Vec<ExpressionHead<K>>,
}

impl<K: ExpressionKind> Expression<K> for IdxExpression<K> {
    type Part = ExpressionHead<K>;
}

pub enum UnOp {
    Neg,
}

pub fn as_string<K>(expr: IdxExpression<K>)
where
    K: ExpressionKind<MonadicOp = UnOp>,
{
    expr.fold(|head| match head {
        ExpressionHead(UnOp::Neg) => {} // <- missing match arm: `ExpressionHead(_)` not covered
    });
}

rust-analyzer reports missing match arm: ExpressionHead(_) not covered on the match in line 41 even though it is covered.

writing

    expr.fold(|head| match head.0 {
        UnOp::Neg => {}
    });

instead makes the error disappear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bugS-blockedStatus: marked as blocked ❌ on something else such as an RFC or other implementation work.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions