mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Exclude methods from non-parameter types introduced by generic constraints
This commit is contained in:
parent
20252efb32
commit
5b05209744
2 changed files with 34 additions and 6 deletions
|
@ -377,12 +377,17 @@ fn iterate_trait_method_candidates<T>(
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
// if ty is `impl Trait` or `dyn Trait`, the trait doesn't need to be in scope
|
// if ty is `impl Trait` or `dyn Trait`, the trait doesn't need to be in scope
|
||||||
let inherent_trait = self_ty.value.inherent_trait().into_iter();
|
let inherent_trait = self_ty.value.inherent_trait().into_iter();
|
||||||
|
let env_traits = if let Ty::Placeholder(_) = self_ty.value {
|
||||||
// if we have `T: Trait` in the param env, the trait doesn't need to be in scope
|
// if we have `T: Trait` in the param env, the trait doesn't need to be in scope
|
||||||
let traits_from_env = env
|
env.trait_predicates_for_self_ty(&self_ty.value)
|
||||||
.trait_predicates_for_self_ty(&self_ty.value)
|
|
||||||
.map(|tr| tr.trait_)
|
.map(|tr| tr.trait_)
|
||||||
.flat_map(|t| all_super_traits(db, t));
|
.flat_map(|t| all_super_traits(db, t))
|
||||||
let traits = inherent_trait.chain(traits_from_env).chain(traits_in_scope.iter().copied());
|
.collect()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
let traits =
|
||||||
|
inherent_trait.chain(env_traits.into_iter()).chain(traits_in_scope.iter().copied());
|
||||||
'traits: for t in traits {
|
'traits: for t in traits {
|
||||||
let data = db.trait_data(t);
|
let data = db.trait_data(t);
|
||||||
|
|
||||||
|
|
|
@ -1007,6 +1007,29 @@ fn test() { foo.call()<|>; }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn method_resolution_non_parameter_type() {
|
||||||
|
let t = type_at(
|
||||||
|
r#"
|
||||||
|
//- /main.rs
|
||||||
|
mod a {
|
||||||
|
pub trait Foo {
|
||||||
|
fn foo(&self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Wrapper<T>(T);
|
||||||
|
fn foo<T>(t: Wrapper<T>)
|
||||||
|
where
|
||||||
|
Wrapper<T>: a::Foo,
|
||||||
|
{
|
||||||
|
t.foo()<|>;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
assert_eq!(t, "{unknown}");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn method_resolution_slow() {
|
fn method_resolution_slow() {
|
||||||
// this can get quite slow if we set the solver size limit too high
|
// this can get quite slow if we set the solver size limit too high
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue