Skip to content

"Generate Deref impl" should abbreviate std::ops::Deref if already in scope #12265

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
jonas-schievink opened this issue May 15, 2022 · 2 comments · Fixed by #12276
Closed

"Generate Deref impl" should abbreviate std::ops::Deref if already in scope #12265

jonas-schievink opened this issue May 15, 2022 · 2 comments · Fixed by #12276
Labels
A-assists S-actionable Someone could pick this issue up and work on it right now

Comments

@jonas-schievink
Copy link
Contributor

use std::ops::Deref;

struct S {
    target$0: u8,
}

Applying the "Generate Deref impl using target" assist generates this:

impl std::ops::Deref for S {
    type Target = u8;

    fn deref(&self) -> &Self::Target {
        &self.target
    }
}

The std::ops::Deref is unnecessarily qualified here, just Deref would be enough. We have code that can automatically do this, should just be a matter of calling that.

@jonas-schievink jonas-schievink added S-actionable Someone could pick this issue up and work on it right now A-assists labels May 15, 2022
@jhgg
Copy link
Contributor

jhgg commented May 16, 2022

What's the code? Happy to make this fix!

@Veykril
Copy link
Member

Veykril commented May 16, 2022

https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir/src/lib.rs#L569-L585
Should be what you need here (you'll first want to fetch Deref via FamousDefs, then fetch a path via one of those)

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
Development

Successfully merging a pull request may close this issue.

3 participants