mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
Merge #10775
10775: minor: Simplify r=lnicola a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
b88b01ecec
@ -3035,6 +3035,18 @@ impl HasCrate for Function {
|
||||
}
|
||||
}
|
||||
|
||||
impl HasCrate for Const {
|
||||
fn krate(&self, db: &dyn HirDatabase) -> Crate {
|
||||
self.module(db).krate()
|
||||
}
|
||||
}
|
||||
|
||||
impl HasCrate for TypeAlias {
|
||||
fn krate(&self, db: &dyn HirDatabase) -> Crate {
|
||||
self.module(db).krate()
|
||||
}
|
||||
}
|
||||
|
||||
impl HasCrate for Type {
|
||||
fn krate(&self, _db: &dyn HirDatabase) -> Crate {
|
||||
self.krate.into()
|
||||
|
@ -86,6 +86,10 @@ impl Completions {
|
||||
local_name: hir::Name,
|
||||
resolution: &hir::ScopeDef,
|
||||
) {
|
||||
if ctx.is_scope_def_hidden(resolution) {
|
||||
cov_mark::hit!(qualified_path_doc_hidden);
|
||||
return;
|
||||
}
|
||||
self.add_opt(render_resolution(RenderContext::new(ctx), local_name, resolution));
|
||||
}
|
||||
|
||||
@ -108,6 +112,9 @@ impl Completions {
|
||||
func: hir::Function,
|
||||
local_name: Option<hir::Name>,
|
||||
) {
|
||||
if !ctx.is_visible(&func) {
|
||||
return;
|
||||
}
|
||||
self.add_opt(render_fn(RenderContext::new(ctx), None, local_name, func));
|
||||
}
|
||||
|
||||
@ -118,14 +125,23 @@ impl Completions {
|
||||
receiver: Option<hir::Name>,
|
||||
local_name: Option<hir::Name>,
|
||||
) {
|
||||
if !ctx.is_visible(&func) {
|
||||
return;
|
||||
}
|
||||
self.add_opt(render_method(RenderContext::new(ctx), None, receiver, local_name, func));
|
||||
}
|
||||
|
||||
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
|
||||
self.add_opt(render_const(RenderContext::new(ctx), constant));
|
||||
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, konst: hir::Const) {
|
||||
if !ctx.is_visible(&konst) {
|
||||
return;
|
||||
}
|
||||
self.add_opt(render_const(RenderContext::new(ctx), konst));
|
||||
}
|
||||
|
||||
pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
|
||||
if !ctx.is_visible(&type_alias) {
|
||||
return;
|
||||
}
|
||||
self.add_opt(render_type_alias(RenderContext::new(ctx), type_alias));
|
||||
}
|
||||
|
||||
@ -164,6 +180,9 @@ impl Completions {
|
||||
field: hir::Field,
|
||||
ty: &hir::Type,
|
||||
) {
|
||||
if !ctx.is_visible(&field) {
|
||||
return;
|
||||
}
|
||||
let item = render_field(RenderContext::new(ctx), receiver, field, ty);
|
||||
self.add(item);
|
||||
}
|
||||
|
@ -63,9 +63,6 @@ fn complete_fields(
|
||||
) {
|
||||
for receiver in receiver.autoderef(ctx.db) {
|
||||
for (field, ty) in receiver.fields(ctx.db) {
|
||||
if !ctx.is_visible(&field) {
|
||||
continue;
|
||||
}
|
||||
f(Either::Left(field), ty);
|
||||
}
|
||||
for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
|
||||
@ -84,10 +81,7 @@ fn complete_methods(
|
||||
let mut seen_methods = FxHashSet::default();
|
||||
let traits_in_scope = ctx.scope.traits_in_scope();
|
||||
receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {
|
||||
if func.self_param(ctx.db).is_some()
|
||||
&& ctx.is_visible(&func)
|
||||
&& seen_methods.insert(func.name(ctx.db))
|
||||
{
|
||||
if func.self_param(ctx.db).is_some() && seen_methods.insert(func.name(ctx.db)) {
|
||||
f(func);
|
||||
}
|
||||
None::<()>
|
||||
|
@ -102,11 +102,6 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.is_scope_def_hidden(&def) {
|
||||
cov_mark::hit!(qualified_path_doc_hidden);
|
||||
continue;
|
||||
}
|
||||
|
||||
let add_resolution = match def {
|
||||
// Don't suggest attribute macros and derives.
|
||||
hir::ScopeDef::MacroDef(mac) => mac.is_fn_like(),
|
||||
@ -167,18 +162,12 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||
if let Some(krate) = krate {
|
||||
let traits_in_scope = ctx.scope.traits_in_scope();
|
||||
ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| {
|
||||
if !ctx.is_visible(&item) {
|
||||
return None;
|
||||
}
|
||||
add_assoc_item(acc, ctx, item);
|
||||
None::<()>
|
||||
});
|
||||
|
||||
// Iterate assoc types separately
|
||||
ty.iterate_assoc_items(ctx.db, krate, |item| {
|
||||
if !ctx.is_visible(&item) {
|
||||
return None;
|
||||
}
|
||||
if let hir::AssocItem::TypeAlias(ty) = item {
|
||||
acc.add_type_alias(ctx, ty)
|
||||
}
|
||||
@ -189,9 +178,6 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||
hir::PathResolution::Def(hir::ModuleDef::Trait(t)) => {
|
||||
// Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`.
|
||||
for item in t.items(ctx.db) {
|
||||
if !ctx.is_visible(&item) {
|
||||
continue;
|
||||
}
|
||||
add_assoc_item(acc, ctx, item);
|
||||
}
|
||||
}
|
||||
@ -210,10 +196,6 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||
let traits_in_scope = ctx.scope.traits_in_scope();
|
||||
let mut seen = FxHashSet::default();
|
||||
ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| {
|
||||
if !ctx.is_visible(&item) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// We might iterate candidates of a trait multiple times here, so deduplicate
|
||||
// them.
|
||||
if seen.insert(item) {
|
||||
|
Loading…
Reference in New Issue
Block a user