Skip to content

When auto-importing the trait for .deref(), RA chooses lazy_static::__Deref over std::ops::Deref #10882

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
rben01 opened this issue Nov 29, 2021 · 1 comment

Comments

@rben01
Copy link

rben01 commented Nov 29, 2021

Description: when RA suggests .deref() and picks a trait to auto-import to bring deref() into scope, it chooses lazy_static::__Deref instead of the more common std::ops::Deref or core::ops::Deref. My Cargo.toml contains lazy_static = "1.4.0" under [dependencies].

VSCode screenshot:

image

Code to reproduce is below. The issue also occurs if rc::Rc is replaced with cell::RefCell (and .borrow() added to obtain a Ref), but I'm not sure about what happens with other Deref implementors.

use std::rc::Rc;

struct A {
	r: Rc<String>,
}

fn f() {
	let a = A {
		r: Rc::new("s".to_owned()),
	};
	let s = a.r.der|      // Cursor to the right of `der`
	//             ┌──────────────────────────────────────────┐
	//             │³ deref() (use lazy_static::__Deref)      │
	//             │³ deref_mut() (use std::ops::DerefMut)    │
	//             └──────────────────────────────────────────┘
}

RA correctly suggests .deref() as an autocomplete for der, but chooses to auto-import the necessary trait from lazy_static::__Deref, instead of std::ops::Deref or core::ops::Deref, which seem like more reasonable choices. (It correctly offers to import .deref_mut() from std::ops::DerefMut.) In the attached screenshot, pressing <TAB> will insert use lazy_static::__Deref near the top of the file.

Similarly, if you write out deref() without importing anything, the fix-it for the error offers to import or qualify with lazy_static::_Deref (same underlying issue, I assume).

@Veykril
Copy link
Member

Veykril commented Nov 29, 2021

Duplicate of #9197

@Veykril Veykril marked this as a duplicate of #9197 Nov 29, 2021
@Veykril Veykril closed this as completed Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants