Skip to content

Remove ItemKind::descr method #143279

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

Merged
merged 2 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4400,27 +4400,6 @@ impl ItemKind<'_> {
_ => return None,
})
}

pub fn descr(&self) -> &'static str {
match self {
ItemKind::ExternCrate(..) => "extern crate",
ItemKind::Use(..) => "`use` import",
ItemKind::Static(..) => "static item",
ItemKind::Const(..) => "constant item",
ItemKind::Fn { .. } => "function",
ItemKind::Macro(..) => "macro",
ItemKind::Mod(..) => "module",
ItemKind::ForeignMod { .. } => "extern block",
ItemKind::GlobalAsm { .. } => "global asm item",
ItemKind::TyAlias(..) => "type alias",
ItemKind::Enum(..) => "enum",
ItemKind::Struct(..) => "struct",
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl(..) => "implementation",
}
}
}

/// A reference from an trait to one of its associated items. This
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2844,7 +2844,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
.find(|item| !item.span.is_dummy()) // Skip prelude `use`s
.map(|item| errors::ItemFollowingInnerAttr {
span: if let Some(ident) = item.kind.ident() { ident.span } else { item.span },
kind: item.kind.descr(),
kind: tcx.def_descr(item.owner_id.to_def_id()),
});
let err = tcx.dcx().create_err(errors::InvalidAttrAtCrateLevel {
span,
Expand Down
10 changes: 8 additions & 2 deletions src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
cx,
UNNECESSARY_SAFETY_COMMENT,
span,
format!("{} has unnecessary safety comment", item.kind.descr()),
format!(
"{} has unnecessary safety comment",
cx.tcx.def_descr(item.owner_id.to_def_id()),
),
|diag| {
diag.span_help(help_span, "consider removing the safety comment");
},
Expand All @@ -274,7 +277,10 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
cx,
UNNECESSARY_SAFETY_COMMENT,
span,
format!("{} has unnecessary safety comment", item.kind.descr()),
format!(
"{} has unnecessary safety comment",
cx.tcx.def_descr(item.owner_id.to_def_id()),
),
|diag| {
diag.span_help(help_span, "consider removing the safety comment");
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ LL | unsafe impl TrailingComment for () {} // SAFETY:
|
= help: consider adding a safety comment on the preceding line

error: constant item has unnecessary safety comment
error: constant has unnecessary safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5
|
LL | const BIG_NUMBER: i32 = 1000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ LL | unsafe impl TrailingComment for () {} // SAFETY:
|
= help: consider adding a safety comment on the preceding line

error: constant item has unnecessary safety comment
error: constant has unnecessary safety comment
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:508:5
|
LL | const BIG_NUMBER: i32 = 1000000;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: constant item has unnecessary safety comment
error: constant has unnecessary safety comment
--> tests/ui/unnecessary_safety_comment.rs:6:5
|
LL | const CONST: u32 = 0;
Expand All @@ -12,7 +12,7 @@ LL | // SAFETY:
= note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]`

error: static item has unnecessary safety comment
error: static has unnecessary safety comment
--> tests/ui/unnecessary_safety_comment.rs:10:5
|
LL | static STATIC: u32 = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lowering/issue-121108.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | #![derive(Clone, Copy)]
| ^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | use std::ptr::addr_of;
| ------- the inner attribute doesn't annotate this `use` import
| ------- the inner attribute doesn't annotate this import
|
help: perhaps you meant to use an outer attribute
|
Expand Down
Loading