From ee9f1a3e7c05e308370b1b88c0319dba80d3b085 Mon Sep 17 00:00:00 2001 From: r0cky Date: Sun, 24 Dec 2023 11:15:07 +0800 Subject: [PATCH] Use correct lint --- compiler/rustc_passes/src/dead.rs | 16 ++++++++-------- tests/ui/lint/dead-code/issue-119267.rs | 9 +++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 tests/ui/lint/dead-code/issue-119267.rs diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index d270794978b27..d60d920a7976f 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -805,11 +805,17 @@ impl<'tcx> DeadVisitor<'tcx> { }; let tcx = self.tcx; + let lint = if is_positional { + lint::builtin::UNUSED_TUPLE_STRUCT_FIELDS + } else { + lint::builtin::DEAD_CODE + }; + let first_hir_id = tcx.local_def_id_to_hir_id(first_id); - let first_lint_level = tcx.lint_level_at_node(lint::builtin::DEAD_CODE, first_hir_id).0; + let first_lint_level = tcx.lint_level_at_node(lint, first_hir_id).0; assert!(dead_codes.iter().skip(1).all(|id| { let hir_id = tcx.local_def_id_to_hir_id(*id); - let level = tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir_id).0; + let level = tcx.lint_level_at_node(lint, hir_id).0; level == first_lint_level })); @@ -835,12 +841,6 @@ impl<'tcx> DeadVisitor<'tcx> { let multiple = num > 6; let name_list = names.into(); - let lint = if is_positional { - lint::builtin::UNUSED_TUPLE_STRUCT_FIELDS - } else { - lint::builtin::DEAD_CODE - }; - let parent_info = if let Some(parent_item) = parent_item { let parent_descr = tcx.def_descr(parent_item.to_def_id()); let span = if let DefKind::Impl { .. } = tcx.def_kind(parent_item) { diff --git a/tests/ui/lint/dead-code/issue-119267.rs b/tests/ui/lint/dead-code/issue-119267.rs new file mode 100644 index 0000000000000..89bae326869fe --- /dev/null +++ b/tests/ui/lint/dead-code/issue-119267.rs @@ -0,0 +1,9 @@ +// run-pass + +#[derive(Debug)] +struct Foo(i32); + +#[derive(Debug)] +struct ConstainsDropField(Foo, #[allow(unused)] Foo); + +fn main() {}