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

Can't find reference when Self is used to construct a type that takes parameters #12693

Closed
umanwizard opened this issue Jul 5, 2022 · 2 comments · Fixed by #15864
Closed
Assignees
Labels
A-ide general IDE features C-bug Category: bug E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@umanwizard
Copy link
Contributor

umanwizard commented Jul 5, 2022

use std::marker::PhantomData;

struct S<T> {
    t: PhantomData<T>,
}

impl<T> S<T> {
    fn new() -> Self {
        Self {
            t: Default::default(),
        }
    }
}

fn main() {}

Navigate to the S in struct S and try to find references. Note that the Self constructor later on is not found.

rust-analyzer version: latest origin/master

rustc version: 1.62.0

@umanwizard umanwizard changed the title Can't find reference when Self is used for a type that takes parameters Can't find reference when Self is used to construct a type that takes parameters Jul 5, 2022
@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution A-ide general IDE features C-bug Category: bug and removed A-ty type system / type inference / traits / method resolution labels Jul 5, 2022
@Veykril
Copy link
Member

Veykril commented Jul 7, 2022

The problem is the textual equality here, this should be changed to be done semantically

fn path_ends_with(path: Option<ast::Path>, name_ref: &ast::NameRef) -> bool {
path.and_then(|path| path.segment())
.and_then(|segment| segment.name_ref())
.map_or(false, |segment| segment == *name_ref)
}
fn is_lit_name_ref(name_ref: &ast::NameRef) -> bool {
name_ref.syntax().ancestors().find_map(|ancestor| {
match_ast! {
match ancestor {
ast::PathExpr(path_expr) => Some(path_ends_with(path_expr.path(), name_ref)),
ast::RecordExpr(record_expr) => Some(path_ends_with(record_expr.path(), name_ref)),
_ => None,
}
}
}).unwrap_or(false)
}

@Veykril Veykril added the E-has-instructions Issue has some instructions and pointers to code to get started label Jan 30, 2023
@Young-Flash
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-bug Category: bug E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants