1
Fork 0

Don't warn on fields in the unreachable_pub lint

This commit is contained in:
Urgau 2024-06-05 19:16:43 +02:00
parent a83cf567b5
commit 89d86ae5bd
3 changed files with 34 additions and 29 deletions

View file

@ -51,7 +51,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use rustc_hir::intravisit::FnKind as HirFnKind;
use rustc_hir::{Body, FnDecl, GenericParamKind, Node, PatKind, PredicateOrigin};
use rustc_hir::{Body, FnDecl, GenericParamKind, PatKind, PredicateOrigin};
use rustc_middle::bug;
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::layout::LayoutOf;
@ -1423,11 +1423,20 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
self.perform_lint(cx, "item", foreign_item.owner_id.def_id, foreign_item.vis_span, true);
}
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
if matches!(cx.tcx.parent_hir_node(field.hir_id), Node::Variant(_)) {
return;
}
self.perform_lint(cx, "field", field.def_id, field.vis_span, false);
fn check_field_def(&mut self, _cx: &LateContext<'_>, _field: &hir::FieldDef<'_>) {
// - If an ADT definition is reported then we don't need to check fields
// (as it would add unnecessary complexity to the source code, the struct
// definition is in the immediate proximity to give the "real" visibility).
// - If an ADT is not reported because it's not `pub` - we don't need to
// check fields.
// - If an ADT is not reported because it's reachable - we also don't need
// to check fields because then they are reachable by construction if they
// are pub.
//
// Therefore in no case we check the fields.
//
// cf. https://github.com/rust-lang/rust/pull/126013#issuecomment-2152839205
// cf. https://github.com/rust-lang/rust/pull/126040#issuecomment-2152944506
}
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {