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

type inference with std::borrow::Borrow doesn't seem to work. #13042

Open
jhgg opened this issue Aug 17, 2022 · 2 comments
Open

type inference with std::borrow::Borrow doesn't seem to work. #13042

jhgg opened this issue Aug 17, 2022 · 2 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@jhgg
Copy link
Contributor

jhgg commented Aug 17, 2022

consider the following code:

fn a<B>(b: B)
where
    B: std::borrow::Borrow<u64>,
{
    let c = b.borrow();
}

rust-analyzer infers the type of c to be &unknown.

However, now consider the following code, where we do not use std::borrow::Borrow, however we use an equivalently defined trait:

trait Borrow<Borrowed: ?Sized> {
    fn borrow(&self) -> &Borrowed;
}

fn a<B>(b: B)
where
    B: Borrow<u64>,
{
    let c = b.borrow();
}

rust-analyzer infers c as &u64.

rust-analyzer version: rust-analyzer version: 0.0.0 (3903243 2022-08-15)

rustc version: rustc 1.63.0 (4b91a6ea7 2022-08-08)

relevant settings: n/a

@Veykril Veykril added A-ty type system / type inference / traits / method resolution C-bug Category: bug labels Aug 17, 2022
@flodiebold
Copy link
Member

Probably duplicate of #5514

@Austaras
Copy link
Contributor

It really is a duplicate of #5514, following code would infer c as unknown

trait Borrow<Borrowed: ?Sized> {
    fn borrow(&self) -> &Borrowed;
}

impl<T: ?Sized> Borrow<T> for T {
    fn borrow(&self) -> &T {
        self
    }
}

fn a<B>(b: B)
where
    B: Borrow<u64>,
{
    let c = b.borrow();
}

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
Projects
None yet
Development

No branches or pull requests

4 participants