mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Rollup merge of #103338 - l4l:enum-unreachable-pub, r=nagisa
Fix unreachable_pub suggestion for enum with fields Resolves #103317
This commit is contained in:
commit
5ee0fb1c68
@ -40,7 +40,7 @@ use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, Gate
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
||||||
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind, PredicateOrigin};
|
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, Node, PatKind, PredicateOrigin};
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
|
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
|
||||||
@ -1423,7 +1423,11 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
|
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
|
||||||
let def_id = cx.tcx.hir().local_def_id(field.hir_id);
|
let map = cx.tcx.hir();
|
||||||
|
let def_id = map.local_def_id(field.hir_id);
|
||||||
|
if matches!(map.get(map.get_parent_node(field.hir_id)), Node::Variant(_)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.perform_lint(cx, "field", def_id, field.vis_span, false);
|
self.perform_lint(cx, "field", def_id, field.vis_span, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
src/test/ui/lint/issue-103317.fixed
Normal file
14
src/test/ui/lint/issue-103317.fixed
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// check-pass
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#[warn(unreachable_pub)]
|
||||||
|
mod inner {
|
||||||
|
#[allow(unused)]
|
||||||
|
pub(crate) enum T {
|
||||||
|
//~^ WARN unreachable `pub` item
|
||||||
|
A(u8),
|
||||||
|
X { a: f32, b: () },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
14
src/test/ui/lint/issue-103317.rs
Normal file
14
src/test/ui/lint/issue-103317.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// check-pass
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#[warn(unreachable_pub)]
|
||||||
|
mod inner {
|
||||||
|
#[allow(unused)]
|
||||||
|
pub enum T {
|
||||||
|
//~^ WARN unreachable `pub` item
|
||||||
|
A(u8),
|
||||||
|
X { a: f32, b: () },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
17
src/test/ui/lint/issue-103317.stderr
Normal file
17
src/test/ui/lint/issue-103317.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
warning: unreachable `pub` item
|
||||||
|
--> $DIR/issue-103317.rs:7:5
|
||||||
|
|
|
||||||
|
LL | pub enum T {
|
||||||
|
| ---^^^^^^^
|
||||||
|
| |
|
||||||
|
| help: consider restricting its visibility: `pub(crate)`
|
||||||
|
|
|
||||||
|
= help: or consider exporting it for use by other crates
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/issue-103317.rs:4:8
|
||||||
|
|
|
||||||
|
LL | #[warn(unreachable_pub)]
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
Loading…
Reference in New Issue
Block a user