Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. --I tried this code: I expected to see this happen: build cleanly Instead, this happened: Running the program shows the field is used: <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --Rust version 1.77.0 (tested in playground) </p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
Derived code is intentionally ignored for dead code analysis - if you try just You'll get a note explaining this. The note doesn't seem to be attached for warnings, just
Ah, so it's intentional. Interesting. I assume the solution is to mark it with then.
claim
release-assignment so can claim it
Error: Parsing assign command in failed: ...'assignment' ' so Please file an issue on GitHub at if there's a problem with this bot, or reach out on on Zulip.
claim
Note that while getting a warning if is just derived but never explicitly used may be understandable (as discussed in other issues), you will get a warning if you do use it explicitly (see ) which, in my opinion, should not be the case.
As mentioned above, the fix for this issue is adding a note about how derived traits are intentionally ignored, not to stop ignoring them.

Discussion:
parent_item: Option<LocalDefId>, report_on: ReportOn, ) { <ins> fn get_parent_if_enum_variant<'tcx>( tcx: TyCtxt<'tcx>, may_variant: LocalDefId, ) -> LocalDefId { if let Node::Variant(_) = tcx.hir_node_by_def_id(may_variant) && let Some(enum_did) = tcx.opt_parent(may_variant.to_def_id()) && let Some(enum_local_id) = enum_did.as_local() && let Node::Item(item) = tcx.hir_node_by_def_id(enum_local_id) && let ItemKind::Enum(_, _) = item.kind { enum_local_id } else { may_variant } } </ins> let Some(&first_item) = dead_codes.first() else { return; };

}; let encl_def_id = parent_item.unwrap_or(first_item.def_id); <ins> // If parent of encl_def_id is an enum, use the parent ID intead. let encl_def_id = get_parent_if_enum_variant(tcx, encl_def_id); </ins> let ignored_derived_impls = if let Some(ign_traits) = self.ignored_derived_traits.get(&encl_def_id) { let trait_list = ign_traits

Variant2, } <ins> #[derive(Debug)] enum TupleVariant { Variant1(i32), //~ ERROR: variant `Variant1` is never constructed Variant2, } #[derive(Debug)] enum StructVariant { Variant1 { id: i32 }, //~ ERROR: variant `Variant1` is never constructed Variant2, } </ins> fn main() { let e = Enum::Variant2; e.clone(); <ins> let _ = TupleVariant::Variant2; let _ = StructVariant::Variant2; </ins> }

LL | #![deny(dead_code)] |         ^^^^^^^^^ <del> error: aborting due to 1 previous error </del> <ins> error: variant `Variant1` is never constructed --> $DIR/unused-variant.rs:11:5 | LL | enum TupleVariant { |      ------------ variant in this enum LL |     Variant1(i32), |     ^^^^^^^^ | = note: `TupleVariant` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis error: variant `Variant1` is never constructed --> $DIR/unused-variant.rs:17:5 | LL | enum StructVariant { |      ------------- variant in this enum LL |     Variant1 { id: i32 }, |     ^^^^^^^^ | = note: `StructVariant` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis error: aborting due to 3 previous errors </ins>