-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Import trait not suggested #16989
Comments
The bad commit after a bisect turned out to be c246a93. I can only guess what is required to repro:
Hopefully now that it is known which commit causes the issue, someone more knowledgeable than me can figure why it causes the issue. |
Do you have any information on the implementations of said trait (and the crates they live in), the crate of the trait itself, the receiver type in your example (and the crate of your the receiver type if it is an ADT) and the dependency relationships between the releveant crates? That's "all" t hat is needed in terms of info for this @davidbarsky looks like your approach does cause some problems 😕 |
I just checked it out, the structure looks something like this:
The plot is the following, and contains several twists:
The trait is used via the wrapper trait that is bound to a generic type:
So there are several layers of macroception as well as generics, I'm not surprised no one else has run into this. I'll try to get an MCVE sometime this week based on this setup. |
ugh, good to know. given that basically nobody uses @tamasfe: i'm sorry about the trouble! |
I set up an MCVE here: https://github.com/tamasfe/ra-completion-repro/blob/master/crates/completion-here/src/lib.rs It seems that adding the "wrapper" trait is what breaks completion:
So far it doesn't seem to matter where this trait is defined, via macro, It also seems to me that any macros or |
@Veykril @davidbarsky sorry to bother, it seems my knowledge is rather limited here and I won't have enough time to dive into the issue anytime soon. Would it be possible to (partially?) revert the changes in the linked commit until this is solved, as the codebase I'm working with relies heavily on the patterns outlied in this issue and we have to maintain a separate older RA version. |
I didn't see your update with the reproduction, sorry! I don't think I will revert it, but I'll work on reproducing it tomorrow. |
If I don't make sufficient progress tomorrow, I was thinking of adding a config option to disable the filtering I introduced in that PR. Would that be okay with you? |
Yeah, thank you, much appreciated! |
Commenting to link to #16555, since I couldn't find this issue be linked from the PR. |
You may have alluded to this already, but the reproduction can be even more minimal. Writing the following in a single crate: pub trait NotInScope {
fn not_in_scope(&self);
}
pub trait Wrapper {
type Inner: NotInScope;
fn inner(&self) -> Self::Inner;
}
pub struct Whatever {
pub id: i32,
}
impl NotInScope for Whatever {
fn not_in_scope(&self) {
todo!()
}
} ...and in another crate, trying to do completions on: // No completion here for generic type
fn no_completion<T: Wrapper>(whatever: T) {
whatever.inner().$0
} ...results in no completions. Something about the associated type isn't being recorded in |
My conclusions is that |
Why would |
I think probably the fix rather needs to be to adapt the logic in |
i don't honestly know: all i can see is that one of the traits ( |
Yeah, if I understand correctly that's because the filtering logic is incorrect for these kinds of receiver types -- it's based on the assumption that the type can only implement traits for which a possibly matching impl exists, but for an associated type it can also implement traits through implied bounds. The assumption also doesn't work for placeholder types, like in this case: fn foo<T: SomeTrait>(t: T) { t.<|> } but here it doesn't matter since any such trait will be in scope automatically already, so we don't need to care about it in autoimport. |
thanks for the tip! this should fix it: #17270 |
Just checked the PR out, works great indeed, thank you! |
rust-analyzer version: rust-analyzer version: 0.4.1905-standalone
rustc version: rustc 1.76.0 (07dca489a 2024-02-04)
editor or extension: vscode
issue:
We have an example trait somewhere:
When calling a trait function on a variable (
foo.not_in_scope()
) and the trait is not in scope, import of the trait is not offered anymore. rustc correctly fails withthe following trait is implemented but not in scope; perhaps add a
usefor it: ...
.The text was updated successfully, but these errors were encountered: