mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
minor: Simplify
This commit is contained in:
parent
73668334f0
commit
f2f89618b7
@ -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 {
|
impl HasCrate for Type {
|
||||||
fn krate(&self, _db: &dyn HirDatabase) -> Crate {
|
fn krate(&self, _db: &dyn HirDatabase) -> Crate {
|
||||||
self.krate.into()
|
self.krate.into()
|
||||||
|
@ -86,6 +86,10 @@ impl Completions {
|
|||||||
local_name: hir::Name,
|
local_name: hir::Name,
|
||||||
resolution: &hir::ScopeDef,
|
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));
|
self.add_opt(render_resolution(RenderContext::new(ctx), local_name, resolution));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +112,9 @@ impl Completions {
|
|||||||
func: hir::Function,
|
func: hir::Function,
|
||||||
local_name: Option<hir::Name>,
|
local_name: Option<hir::Name>,
|
||||||
) {
|
) {
|
||||||
|
if !ctx.is_visible(&func) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.add_opt(render_fn(RenderContext::new(ctx), None, local_name, func));
|
self.add_opt(render_fn(RenderContext::new(ctx), None, local_name, func));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,14 +125,23 @@ impl Completions {
|
|||||||
receiver: Option<hir::Name>,
|
receiver: Option<hir::Name>,
|
||||||
local_name: 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));
|
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) {
|
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, konst: hir::Const) {
|
||||||
self.add_opt(render_const(RenderContext::new(ctx), constant));
|
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) {
|
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));
|
self.add_opt(render_type_alias(RenderContext::new(ctx), type_alias));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +180,9 @@ impl Completions {
|
|||||||
field: hir::Field,
|
field: hir::Field,
|
||||||
ty: &hir::Type,
|
ty: &hir::Type,
|
||||||
) {
|
) {
|
||||||
|
if !ctx.is_visible(&field) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let item = render_field(RenderContext::new(ctx), receiver, field, ty);
|
let item = render_field(RenderContext::new(ctx), receiver, field, ty);
|
||||||
self.add(item);
|
self.add(item);
|
||||||
}
|
}
|
||||||
|
@ -63,9 +63,6 @@ fn complete_fields(
|
|||||||
) {
|
) {
|
||||||
for receiver in receiver.autoderef(ctx.db) {
|
for receiver in receiver.autoderef(ctx.db) {
|
||||||
for (field, ty) in receiver.fields(ctx.db) {
|
for (field, ty) in receiver.fields(ctx.db) {
|
||||||
if !ctx.is_visible(&field) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
f(Either::Left(field), ty);
|
f(Either::Left(field), ty);
|
||||||
}
|
}
|
||||||
for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
|
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 mut seen_methods = FxHashSet::default();
|
||||||
let traits_in_scope = ctx.scope.traits_in_scope();
|
let traits_in_scope = ctx.scope.traits_in_scope();
|
||||||
receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {
|
receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {
|
||||||
if func.self_param(ctx.db).is_some()
|
if func.self_param(ctx.db).is_some() && seen_methods.insert(func.name(ctx.db)) {
|
||||||
&& ctx.is_visible(&func)
|
|
||||||
&& seen_methods.insert(func.name(ctx.db))
|
|
||||||
{
|
|
||||||
f(func);
|
f(func);
|
||||||
}
|
}
|
||||||
None::<()>
|
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 {
|
let add_resolution = match def {
|
||||||
// Don't suggest attribute macros and derives.
|
// Don't suggest attribute macros and derives.
|
||||||
hir::ScopeDef::MacroDef(mac) => mac.is_fn_like(),
|
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 {
|
if let Some(krate) = krate {
|
||||||
let traits_in_scope = ctx.scope.traits_in_scope();
|
let traits_in_scope = ctx.scope.traits_in_scope();
|
||||||
ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| {
|
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);
|
add_assoc_item(acc, ctx, item);
|
||||||
None::<()>
|
None::<()>
|
||||||
});
|
});
|
||||||
|
|
||||||
// Iterate assoc types separately
|
// Iterate assoc types separately
|
||||||
ty.iterate_assoc_items(ctx.db, krate, |item| {
|
ty.iterate_assoc_items(ctx.db, krate, |item| {
|
||||||
if !ctx.is_visible(&item) {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
if let hir::AssocItem::TypeAlias(ty) = item {
|
if let hir::AssocItem::TypeAlias(ty) = item {
|
||||||
acc.add_type_alias(ctx, ty)
|
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)) => {
|
hir::PathResolution::Def(hir::ModuleDef::Trait(t)) => {
|
||||||
// Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`.
|
// Handles `Trait::assoc` as well as `<Ty as Trait>::assoc`.
|
||||||
for item in t.items(ctx.db) {
|
for item in t.items(ctx.db) {
|
||||||
if !ctx.is_visible(&item) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
add_assoc_item(acc, ctx, item);
|
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 traits_in_scope = ctx.scope.traits_in_scope();
|
||||||
let mut seen = FxHashSet::default();
|
let mut seen = FxHashSet::default();
|
||||||
ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| {
|
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
|
// We might iterate candidates of a trait multiple times here, so deduplicate
|
||||||
// them.
|
// them.
|
||||||
if seen.insert(item) {
|
if seen.insert(item) {
|
||||||
|
Loading…
Reference in New Issue
Block a user