Skip to content

Commit 05808ac

Browse files
Merge pull request #22083 from ada4a/22062-deprecatedness
fix: respect `#[deprecated]` attr when deciding if a `ModuleDef` completion is `deprecated`
2 parents 82902ef + 400c929 commit 05808ac

11 files changed

Lines changed: 431 additions & 101 deletions

File tree

crates/hir/src/attrs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ pub enum AttrsOwner {
3838
Field(FieldId),
3939
LifetimeParam(LifetimeParamId),
4040
TypeOrConstParam(TypeOrConstParamId),
41-
/// Things that do not have attributes. Used for builtin derives.
41+
/// Things that do not have attributes.
42+
///
43+
/// Used for:
44+
/// - builtin derives
45+
/// - builtin types (as those do not have attributes)
4246
Dummy,
4347
}
4448

crates/hir/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,23 @@ impl HasCrate for ModuleDef {
556556
}
557557
}
558558

559+
impl HasAttrs for ModuleDef {
560+
fn attr_id(self, db: &dyn HirDatabase) -> attrs::AttrsOwner {
561+
match self {
562+
ModuleDef::Module(it) => it.attr_id(db),
563+
ModuleDef::Function(it) => it.attr_id(db),
564+
ModuleDef::Adt(it) => it.attr_id(db),
565+
ModuleDef::EnumVariant(it) => it.attr_id(db),
566+
ModuleDef::Const(it) => it.attr_id(db),
567+
ModuleDef::Static(it) => it.attr_id(db),
568+
ModuleDef::Trait(it) => it.attr_id(db),
569+
ModuleDef::TypeAlias(it) => it.attr_id(db),
570+
ModuleDef::Macro(it) => it.attr_id(db),
571+
ModuleDef::BuiltinType(_) => attrs::AttrsOwner::Dummy,
572+
}
573+
}
574+
}
575+
559576
impl HasVisibility for ModuleDef {
560577
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
561578
match *self {

crates/ide-completion/src/completions.rs

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,13 @@ impl Completions {
234234
Visible::Editable => true,
235235
Visible::No => return,
236236
};
237-
self.add(
238-
render_path_resolution(
239-
RenderContext::new(ctx)
240-
.private_editable(is_private_editable)
241-
.doc_aliases(doc_aliases),
242-
path_ctx,
243-
local_name,
244-
resolution,
245-
)
246-
.build(ctx.db),
247-
);
237+
render_path_resolution(
238+
RenderContext::new(ctx).private_editable(is_private_editable).doc_aliases(doc_aliases),
239+
path_ctx,
240+
local_name,
241+
resolution,
242+
)
243+
.add_to(self, ctx.db);
248244
}
249245

250246
pub(crate) fn add_pattern_resolution(
@@ -259,15 +255,13 @@ impl Completions {
259255
Visible::Editable => true,
260256
Visible::No => return,
261257
};
262-
self.add(
263-
render_pattern_resolution(
264-
RenderContext::new(ctx).private_editable(is_private_editable),
265-
pattern_ctx,
266-
local_name,
267-
resolution,
268-
)
269-
.build(ctx.db),
270-
);
258+
render_pattern_resolution(
259+
RenderContext::new(ctx).private_editable(is_private_editable),
260+
pattern_ctx,
261+
local_name,
262+
resolution,
263+
)
264+
.add_to(self, ctx.db);
271265
}
272266

273267
pub(crate) fn add_enum_variants(
@@ -310,15 +304,13 @@ impl Completions {
310304
Visible::Editable => true,
311305
Visible::No => return,
312306
};
313-
self.add(
314-
render_macro(
315-
RenderContext::new(ctx).private_editable(is_private_editable),
316-
path_ctx,
317-
local_name,
318-
mac,
319-
)
320-
.build(ctx.db),
321-
);
307+
render_macro(
308+
RenderContext::new(ctx).private_editable(is_private_editable),
309+
path_ctx,
310+
local_name,
311+
mac,
312+
)
313+
.add_to(self, ctx.db);
322314
}
323315

324316
pub(crate) fn add_function(
@@ -334,17 +326,13 @@ impl Completions {
334326
Visible::No => return,
335327
};
336328
let doc_aliases = ctx.doc_aliases(&func);
337-
self.add(
338-
render_fn(
339-
RenderContext::new(ctx)
340-
.private_editable(is_private_editable)
341-
.doc_aliases(doc_aliases),
342-
path_ctx,
343-
local_name,
344-
func,
345-
)
346-
.build(ctx.db),
347-
);
329+
render_fn(
330+
RenderContext::new(ctx).private_editable(is_private_editable).doc_aliases(doc_aliases),
331+
path_ctx,
332+
local_name,
333+
func,
334+
)
335+
.add_to(self, ctx.db);
348336
}
349337

350338
pub(crate) fn add_method(
@@ -361,18 +349,14 @@ impl Completions {
361349
Visible::No => return,
362350
};
363351
let doc_aliases = ctx.doc_aliases(&func);
364-
self.add(
365-
render_method(
366-
RenderContext::new(ctx)
367-
.private_editable(is_private_editable)
368-
.doc_aliases(doc_aliases),
369-
dot_access,
370-
receiver,
371-
local_name,
372-
func,
373-
)
374-
.build(ctx.db),
375-
);
352+
render_method(
353+
RenderContext::new(ctx).private_editable(is_private_editable).doc_aliases(doc_aliases),
354+
dot_access,
355+
receiver,
356+
local_name,
357+
func,
358+
)
359+
.add_to(self, ctx.db);
376360
}
377361

378362
pub(crate) fn add_method_with_import(
@@ -388,19 +372,17 @@ impl Completions {
388372
Visible::No => return,
389373
};
390374
let doc_aliases = ctx.doc_aliases(&func);
391-
self.add(
392-
render_method(
393-
RenderContext::new(ctx)
394-
.private_editable(is_private_editable)
395-
.doc_aliases(doc_aliases)
396-
.import_to_add(Some(import)),
397-
dot_access,
398-
None,
399-
None,
400-
func,
401-
)
402-
.build(ctx.db),
403-
);
375+
render_method(
376+
RenderContext::new(ctx)
377+
.private_editable(is_private_editable)
378+
.doc_aliases(doc_aliases)
379+
.import_to_add(Some(import)),
380+
dot_access,
381+
None,
382+
None,
383+
func,
384+
)
385+
.add_to(self, ctx.db);
404386
}
405387

406388
pub(crate) fn add_const(&mut self, ctx: &CompletionContext<'_>, konst: hir::Const) {

0 commit comments

Comments
 (0)