1
Fork 0

Add warn(unreachable_pub) to rustc_lint.

This commit is contained in:
Nicholas Nethercote 2024-08-27 15:24:11 +10:00
parent 6c84c55c9f
commit f10284162f
11 changed files with 269 additions and 268 deletions

View file

@ -413,7 +413,7 @@ pub fn check_ast_node<'a>(
} }
} }
pub fn check_ast_node_inner<'a, T: EarlyLintPass>( fn check_ast_node_inner<'a, T: EarlyLintPass>(
sess: &Session, sess: &Session,
check_node: impl EarlyCheckNode<'a>, check_node: impl EarlyCheckNode<'a>,
context: EarlyContext<'_>, context: EarlyContext<'_>,

View file

@ -8,7 +8,7 @@ use crate::fluent_generated as fluent;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_overruled_attribute, code = E0453)] #[diag(lint_overruled_attribute, code = E0453)]
pub struct OverruledAttribute<'a> { pub(crate) struct OverruledAttribute<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[label] #[label]
@ -19,7 +19,7 @@ pub struct OverruledAttribute<'a> {
pub sub: OverruledAttributeSub, pub sub: OverruledAttributeSub,
} }
pub enum OverruledAttributeSub { pub(crate) enum OverruledAttributeSub {
DefaultSource { id: String }, DefaultSource { id: String },
NodeSource { span: Span, reason: Option<Symbol> }, NodeSource { span: Span, reason: Option<Symbol> },
CommandLineSource, CommandLineSource,
@ -52,7 +52,7 @@ impl Subdiagnostic for OverruledAttributeSub {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_malformed_attribute, code = E0452)] #[diag(lint_malformed_attribute, code = E0452)]
pub struct MalformedAttribute { pub(crate) struct MalformedAttribute {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[subdiagnostic] #[subdiagnostic]
@ -60,7 +60,7 @@ pub struct MalformedAttribute {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum MalformedAttributeSub { pub(crate) enum MalformedAttributeSub {
#[label(lint_bad_attribute_argument)] #[label(lint_bad_attribute_argument)]
BadAttributeArgument(#[primary_span] Span), BadAttributeArgument(#[primary_span] Span),
#[label(lint_reason_must_be_string_literal)] #[label(lint_reason_must_be_string_literal)]
@ -71,7 +71,7 @@ pub enum MalformedAttributeSub {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_unknown_tool_in_scoped_lint, code = E0710)] #[diag(lint_unknown_tool_in_scoped_lint, code = E0710)]
pub struct UnknownToolInScopedLint { pub(crate) struct UnknownToolInScopedLint {
#[primary_span] #[primary_span]
pub span: Option<Span>, pub span: Option<Span>,
pub tool_name: Symbol, pub tool_name: Symbol,
@ -82,7 +82,7 @@ pub struct UnknownToolInScopedLint {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = E0783)] #[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = E0783)]
pub struct BuiltinEllipsisInclusiveRangePatterns { pub(crate) struct BuiltinEllipsisInclusiveRangePatterns {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")] #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
@ -92,20 +92,20 @@ pub struct BuiltinEllipsisInclusiveRangePatterns {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(lint_requested_level)] #[note(lint_requested_level)]
pub struct RequestedLevel<'a> { pub(crate) struct RequestedLevel<'a> {
pub level: Level, pub level: Level,
pub lint_name: &'a str, pub lint_name: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_unsupported_group, code = E0602)] #[diag(lint_unsupported_group, code = E0602)]
pub struct UnsupportedGroup { pub(crate) struct UnsupportedGroup {
pub lint_group: String, pub lint_group: String,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_check_name_unknown_tool, code = E0602)] #[diag(lint_check_name_unknown_tool, code = E0602)]
pub struct CheckNameUnknownTool<'a> { pub(crate) struct CheckNameUnknownTool<'a> {
pub tool_name: Symbol, pub tool_name: Symbol,
#[subdiagnostic] #[subdiagnostic]
pub sub: RequestedLevel<'a>, pub sub: RequestedLevel<'a>,

View file

@ -47,7 +47,7 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
/// Implements the AST traversal for late lint passes. `T` provides the /// Implements the AST traversal for late lint passes. `T` provides the
/// `check_*` methods. /// `check_*` methods.
pub struct LateContextAndPass<'tcx, T: LateLintPass<'tcx>> { struct LateContextAndPass<'tcx, T: LateLintPass<'tcx>> {
context: LateContext<'tcx>, context: LateContext<'tcx>,
pass: T, pass: T,
} }

View file

@ -1103,7 +1103,7 @@ pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { shallow_lint_levels_on, lint_expectations, ..*providers }; *providers = Providers { shallow_lint_levels_on, lint_expectations, ..*providers };
} }
pub fn parse_lint_and_tool_name(lint_name: &str) -> (Option<Symbol>, &str) { pub(crate) fn parse_lint_and_tool_name(lint_name: &str) -> (Option<Symbol>, &str) {
match lint_name.split_once("::") { match lint_name.split_once("::") {
Some((tool_name, lint_name)) => { Some((tool_name, lint_name)) => {
let tool_name = Symbol::intern(tool_name); let tool_name = Symbol::intern(tool_name);

View file

@ -39,6 +39,7 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![feature(rustdoc_internals)] #![feature(rustdoc_internals)]
#![feature(trait_upcasting)] #![feature(trait_upcasting)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end // tidy-alphabetical-end
mod async_closures; mod async_closures;

File diff suppressed because it is too large Load diff

View file

@ -55,7 +55,7 @@ declare_lint! {
} }
#[derive(Default)] #[derive(Default)]
pub struct NonLocalDefinitions { pub(crate) struct NonLocalDefinitions {
body_depth: u32, body_depth: u32,
} }

View file

@ -17,13 +17,13 @@ use crate::lints::{
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum MethodLateContext { pub(crate) enum MethodLateContext {
TraitAutoImpl, TraitAutoImpl,
TraitImpl, TraitImpl,
PlainImpl, PlainImpl,
} }
pub fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext { pub(crate) fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext {
let item = cx.tcx.associated_item(id); let item = cx.tcx.associated_item(id);
match item.container { match item.container {
ty::TraitContainer => MethodLateContext::TraitAutoImpl, ty::TraitContainer => MethodLateContext::TraitAutoImpl,

View file

@ -65,7 +65,7 @@ declare_lint! {
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct ShadowedIntoIter; pub(crate) struct ShadowedIntoIter;
impl_lint_pass!(ShadowedIntoIter => [ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER]); impl_lint_pass!(ShadowedIntoIter => [ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER]);

View file

@ -165,7 +165,7 @@ declare_lint! {
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct TypeLimits { pub(crate) struct TypeLimits {
/// Id of the last visited negated expression /// Id of the last visited negated expression
negated_expr_id: Option<hir::HirId>, negated_expr_id: Option<hir::HirId>,
/// Span of the last visited negated expression /// Span of the last visited negated expression
@ -180,7 +180,7 @@ impl_lint_pass!(TypeLimits => [
]); ]);
impl TypeLimits { impl TypeLimits {
pub fn new() -> TypeLimits { pub(crate) fn new() -> TypeLimits {
TypeLimits { negated_expr_id: None, negated_expr_span: None } TypeLimits { negated_expr_id: None, negated_expr_span: None }
} }
} }
@ -1008,7 +1008,7 @@ pub(crate) fn nonnull_optimization_guaranteed<'tcx>(
/// `repr(transparent)` structs can have a single non-1-ZST field, this function returns that /// `repr(transparent)` structs can have a single non-1-ZST field, this function returns that
/// field. /// field.
pub fn transparent_newtype_field<'a, 'tcx>( pub(crate) fn transparent_newtype_field<'a, 'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
variant: &'a ty::VariantDef, variant: &'a ty::VariantDef,
) -> Option<&'a ty::FieldDef> { ) -> Option<&'a ty::FieldDef> {

View file

@ -1019,7 +1019,7 @@ declare_lint! {
"`if`, `match`, `while` and `return` do not need parentheses" "`if`, `match`, `while` and `return` do not need parentheses"
} }
pub struct UnusedParens { pub(crate) struct UnusedParens {
with_self_ty_parens: bool, with_self_ty_parens: bool,
/// `1 as (i32) < 2` parses to ExprKind::Lt /// `1 as (i32) < 2` parses to ExprKind::Lt
/// `1 as i32 < 2` parses to i32::<2[missing angle bracket] /// `1 as i32 < 2` parses to i32::<2[missing angle bracket]
@ -1027,7 +1027,7 @@ pub struct UnusedParens {
} }
impl UnusedParens { impl UnusedParens {
pub fn new() -> Self { pub(crate) fn new() -> Self {
Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() } Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() }
} }
} }