Skip to content

Merge match arms fails to take type of pattern variable into account #9337

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
ChaiTRex opened this issue Jun 19, 2021 · 0 comments · Fixed by #11248
Closed

Merge match arms fails to take type of pattern variable into account #9337

ChaiTRex opened this issue Jun 19, 2021 · 0 comments · Fixed by #11248
Labels
A-assists S-actionable Someone could pick this issue up and work on it right now

Comments

@ChaiTRex
Copy link

In VS Code, Merge match arms offers to merge the two lines in the Display implementation, even though the type of the x in each is different. This will produce a type error when compiled.

use std::fmt::{Display, Formatter, Result};

#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum Value {
    Char(char),
    I8(i8),
}

impl Display for Value {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        match self {
            Value::Char(x) => x.fmt(f),
            Value::I8(x) => x.fmt(f),
        }
    }
}

rust-analyzer version: f0618a8 2021-06-14 stable
rust-analyzer VS Code extension version: v0.2.637
VS Code version: 1.57.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
2 participants