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

go to definition not working #17362

Closed
kzhui125 opened this issue Jun 7, 2024 · 1 comment
Closed

go to definition not working #17362

kzhui125 opened this issue Jun 7, 2024 · 1 comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@kzhui125
Copy link

kzhui125 commented Jun 7, 2024

rust-analyzer version: 0.3.1983-standalone (7852a4c 2024-06-02)

use std::borrow::{Borrow, BorrowMut};

pub trait Item: 'static {}

pub trait BorrowPoint {
    fn set_item1<T: Item>(&mut self, global: T);
    fn set_item2<T: Item>(&mut self, global: T);
    fn set_item3<T: Item>(&mut self, global: T);
}

struct Point;

impl Point {
    pub fn f1(&mut self) {
        println!("Point.f1");
    }

    pub fn set_item2(&mut self) {
        println!("Point.set_item2");
    }

    pub fn set_item3<I: Item>(&mut self, _item: I) {
        println!("Point.set_item3");
    }
}

struct PointWrapper(Point);

impl Borrow<Point> for PointWrapper {
    fn borrow(&self) -> &Point {
        &self.0
    }
}

impl BorrowMut<Point> for PointWrapper {
    fn borrow_mut(&mut self) -> &mut Point {
        &mut self.0
    }
}

impl<C> BorrowPoint for C
where
    C: BorrowMut<Point>,
{
    fn set_item1<I: Item>(&mut self, _item: I) {
        self.borrow_mut().f1();
    }

    fn set_item2<I: Item>(&mut self, _item: I) {
        self.borrow_mut().set_item2();
    }

    fn set_item3<I: Item>(&mut self, item: I) {
        self.borrow_mut().set_item3(item);
    }
}

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

    struct G1;
    impl Item for G1 {}

    #[test]
    fn test_name() {
        let mut s = PointWrapper(Point);
        s.set_item1(G1);
        s.set_item2(G1);
    }
}

issue1:

image

issue2: go to definition not working:

image

issue3: go to definition will go to wrong place:

image
@kzhui125 kzhui125 added the C-bug Category: bug label Jun 7, 2024
@Veykril Veykril added the A-ty type system / type inference / traits / method resolution label Jun 7, 2024
@ChayimFriedman2
Copy link
Contributor

Dup of #5514 (yet another case).

@Veykril Veykril closed this as completed Sep 24, 2024
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

3 participants