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

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

Closed
8051Enthusiast opened this issue Feb 16, 2023 · 1 comment · Fixed by #14378
Closed
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.

Comments

@8051Enthusiast
Copy link

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.

@8051Enthusiast 8051Enthusiast added the C-bug Category: bug label Feb 16, 2023
@8051Enthusiast 8051Enthusiast changed the title false report of "missing match arm" matching on associated type false report of "missing match arm" when matching on nested pattern with unknown type Feb 16, 2023
@lowr lowr added the A-ty type system / type inference / traits / method resolution label Feb 16, 2023
@lowr
Copy link
Contributor

lowr commented Feb 16, 2023

A bit reduced:

trait Rec {
    type K;
    type Rebind<Tok>: Rec<K = Tok>;
}

trait Expr<K> {
    type Part: Rec<K = K>;
    fn foo(_: <Self::Part as Rec>::Rebind<i32>) {}
}

struct Head<K>(K);
impl<K> Rec for Head<K> {
    type K = K;
    type Rebind<Tok> = Head<Tok>;
}

fn test<E>()
where
    E: Expr<usize, Part = Head<usize>>,
{
    let head;
      //^^^^ {unknown}, but should be Head<i32>
    E::foo(head);
}

I've looked at chalk's debug log, and I'm like 80% sure this is chalk's bug.

@lowr lowr added the S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. label Feb 18, 2023
bors added a commit to rust-lang/chalk that referenced this issue Mar 12, 2023
Fix projection substitution order considering GATs

When an `AliasEq` goal contains another alias as its self type, we generate the following clause: `<<X as Y>::A as Z>::B == U :- <T as Z>::B == U, <X as Y>::A == T`, with `T` being a new variable. We've been building `<T as Z>::B` by swapping the first argument in the original projection's substitution with `T`, but it's not the self type when the associated type `B` has generic parameters, leading to wrong subgoals.

The added test would yield "No possible solution" in current master.

Also removes `ignore` attribute on a doctest that was added in #778 as GATs hit stable.

Spotted in rust-lang/rust-analyzer#14164.
@bors bors closed this as completed in 825833c Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants