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

try_into from custom trait misresolved for prelude TryInto in 2021 edition #10677

Closed
johnmave126 opened this issue Nov 1, 2021 · 0 comments · Fixed by #13147
Closed

try_into from custom trait misresolved for prelude TryInto in 2021 edition #10677

johnmave126 opened this issue Nov 1, 2021 · 0 comments · Fixed by #13147
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@johnmave126
Copy link

Environment

rust 1.56.1
rust-analyzer 2021-11-01
edition 2021

Steps to reproduce

pub struct GreaterThanZero(i32);

impl TryFrom<i32> for GreaterThanZero {
    type Error = &'static str;

    fn try_from(value: i32) -> Result<Self, Self::Error> {        
        Ok(GreaterThanZero(value))
    }
}

pub trait MyTrait {
    // This has the same name as `TryInto::try_into`
    fn try_into(&self, addition: i32) -> Result<GreaterThanZero, ()>;
}

impl MyTrait for i32 {
    fn try_into(&self, addition: i32) -> Result<GreaterThanZero, ()> {
        Ok(GreaterThanZero(*self + addition))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn internal() {
        let a: &dyn MyTrait = &2;
        let v: GreaterThanZero = (&*a).try_into(1).unwrap();
        assert_eq!(3, v.0);
    }
}
  • Expected: No error. try_into in internal() resolves to MyTrait::try_into
  • What happened: cargo compiles fine but RA reports mismatched-arg-count. try_into in internal() resolves to TryInto::try_into from the prelude.

Courtesy of minstrel1977@rustcc

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-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants