Rollup merge of #138331 - nnethercote:use-RUSTC_LINT_FLAGS-more, r=onur-ozkan,jieyouxu

Use `RUSTC_LINT_FLAGS` more

An alternative to the failed #138084.

Fixes #138106.

r? ````@jieyouxu````
This commit is contained in:
Matthias Krüger 2025-03-12 17:59:08 +01:00 committed by GitHub
commit d93ef397ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
71 changed files with 38 additions and 94 deletions

View File

@ -5,7 +5,6 @@
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
#![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
#![cfg_attr(feature = "nightly", feature(step_trait))]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
/*! ABI handling for rustc

View File

@ -23,7 +23,6 @@
#![feature(maybe_uninit_slice)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::alloc::Layout;

View File

@ -19,7 +19,6 @@
#![feature(never_type)]
#![feature(rustdoc_internals)]
#![feature(stmt_expr_attributes)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod util {

View File

@ -9,7 +9,6 @@
#![cfg_attr(feature = "nightly", allow(internal_features))]
#![cfg_attr(feature = "nightly", feature(never_type))]
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
#[cfg(feature = "nightly")]

View File

@ -39,7 +39,6 @@
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::sync::Arc;

View File

@ -10,7 +10,6 @@
#![feature(iter_is_partitioned)]
#![feature(let_chains)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod ast_validation;

View File

@ -3,7 +3,6 @@
#![doc(rust_logo)]
#![feature(box_patterns)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod helpers;

View File

@ -3,7 +3,6 @@
#![doc(rust_logo)]
#![feature(let_chains)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod attributes;

View File

@ -80,7 +80,6 @@
#![doc(rust_logo)]
#![feature(let_chains)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
#[macro_use]

View File

@ -23,6 +23,7 @@
// tidy-alphabetical-start
#![allow(elided_lifetimes_in_paths)]
#![allow(internal_features)]
#![allow(unreachable_pub)] // because this crate is mostly generated code
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
// #![warn(unreachable_pub)] // don't use because this crate is mostly generated code

View File

@ -13,7 +13,6 @@
#![feature(rustdoc_internals)]
#![feature(stmt_expr_attributes)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::borrow::Cow;

View File

@ -18,7 +18,6 @@
#![feature(rustdoc_internals)]
#![feature(string_from_utf8_lossy_owned)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
extern crate proc_macro;

View File

@ -19,7 +19,6 @@
#![feature(rustdoc_internals)]
#![feature(slice_as_array)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::any::Any;

View File

@ -14,7 +14,6 @@
#![feature(rustdoc_internals)]
#![feature(trait_alias)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
//! This crate contains codegen code that is used by all codegen backends (LLVM and others).

View File

@ -16,7 +16,6 @@
#![feature(unqualified_local_imports)]
#![feature(yeet_expr)]
#![warn(unqualified_local_imports)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod check_consts;

View File

@ -3,7 +3,7 @@ use std::cmp::max;
use super::*;
use crate::fx::FxHashMap;
pub struct TestGraph {
pub(super) struct TestGraph {
num_nodes: usize,
start_node: usize,
successors: FxHashMap<usize, Vec<usize>>,
@ -11,7 +11,7 @@ pub struct TestGraph {
}
impl TestGraph {
pub fn new(start_node: usize, edges: &[(usize, usize)]) -> Self {
pub(super) fn new(start_node: usize, edges: &[(usize, usize)]) -> Self {
let mut graph = TestGraph {
num_nodes: start_node + 1,
start_node,

View File

@ -313,7 +313,7 @@ pub struct Error<O, E> {
mod helper {
use super::*;
pub type ObligationTreeIdGenerator = impl Iterator<Item = ObligationTreeId>;
pub(super) type ObligationTreeIdGenerator = impl Iterator<Item = ObligationTreeId>;
impl<O: ForestObligation> ObligationForest<O> {
#[cfg_attr(not(bootstrap), define_opaque(ObligationTreeIdGenerator))]
pub fn new() -> ObligationForest<O> {

View File

@ -88,7 +88,7 @@ mod mode {
// Whether thread safety might be enabled.
#[inline]
pub fn might_be_dyn_thread_safe() -> bool {
pub(super) fn might_be_dyn_thread_safe() -> bool {
DYN_THREAD_SAFE_MODE.load(Ordering::Relaxed) != DYN_NOT_THREAD_SAFE
}

View File

@ -46,7 +46,7 @@ pub fn parallel_guard<R>(f: impl FnOnce(&ParallelGuard) -> R) -> R {
ret
}
pub fn serial_join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
fn serial_join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where
A: FnOnce() -> RA,
B: FnOnce() -> RB,

View File

@ -7,7 +7,7 @@ use crate::stable_hasher::{HashStable, StableHasher};
/// A tag type used in [`TaggedRef`] tests.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Tag2 {
enum Tag2 {
B00 = 0b00,
B01 = 0b01,
B10 = 0b10,

View File

@ -16,7 +16,6 @@
#![feature(result_flattening)]
#![feature(rustdoc_internals)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::cmp::max;

View File

@ -6,7 +6,6 @@
#![deny(rustdoc::invalid_codeblock_attributes)]
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
// This higher-order macro defines the error codes that are in use. It is used

View File

@ -4,7 +4,6 @@
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![feature(type_alias_impl_trait)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::borrow::Cow;

View File

@ -25,7 +25,6 @@
#![feature(trait_alias)]
#![feature(try_blocks)]
#![feature(yeet_expr)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
extern crate self as rustc_errors;

View File

@ -13,7 +13,6 @@
#![feature(rustdoc_internals)]
#![feature(try_blocks)]
#![feature(yeet_expr)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
extern crate proc_macro as pm;

View File

@ -15,7 +15,6 @@
#![allow(internal_features)]
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod accepted;

View File

@ -7,7 +7,6 @@
#![feature(proc_macro_span)]
#![feature(rustdoc_internals)]
#![feature(track_path)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use proc_macro::TokenStream;

View File

@ -277,7 +277,6 @@
)]
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::borrow::Cow;

View File

@ -13,7 +13,6 @@
#![feature(never_type)]
#![feature(rustc_attrs)]
#![feature(variant_count)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
extern crate self as rustc_hir;

View File

@ -73,7 +73,6 @@ This API is completely unstable and subject to change.
#![feature(slice_partition_dedup)]
#![feature(try_blocks)]
#![feature(unwrap_infallible)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
// These are used by Clippy.

View File

@ -3,7 +3,6 @@
// tidy-alphabetical-start
#![recursion_limit = "256"]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::cell::Cell;

View File

@ -8,7 +8,6 @@
#![feature(let_chains)]
#![feature(never_type)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod _match;

View File

@ -7,7 +7,6 @@
#![doc(rust_logo)]
#![feature(file_buffered)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod assert_dep_graph;

View File

@ -4,7 +4,6 @@
#![cfg_attr(feature = "nightly", feature(extend_one, step_trait, test))]
#![cfg_attr(feature = "nightly", feature(new_range_api))]
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod bit_set;

View File

@ -305,7 +305,7 @@ impl Parse for Newtype {
}
}
pub fn newtype(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
pub(crate) fn newtype(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as Newtype);
input.0.into()
}

View File

@ -24,7 +24,6 @@
#![feature(let_chains)]
#![feature(rustdoc_internals)]
#![recursion_limit = "512"] // For rustdoc
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod errors;

View File

@ -4,7 +4,6 @@
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod callbacks;

View File

@ -23,7 +23,6 @@
// We want to be able to build this crate with a stable compiler,
// so no `#![feature]` attributes should be added.
#![deny(unstable_features)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod cursor;

View File

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

View File

@ -1,7 +1,3 @@
// tidy-alphabetical-start
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_abi::ExternAbi;
use rustc_ast::AttrId;
use rustc_ast::attr::AttributeExt;

View File

@ -4,7 +4,6 @@
#![doc(rust_logo)]
#![feature(extern_types)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::cell::RefCell;

View File

@ -6,7 +6,6 @@
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_span)]
#![feature(proc_macro_tracked_env)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use proc_macro::TokenStream;

View File

@ -15,7 +15,6 @@
#![feature(proc_macro_internals)]
#![feature(rustdoc_internals)]
#![feature(trusted_len)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
extern crate proc_macro;

View File

@ -61,7 +61,6 @@
#![feature(try_trait_v2_yeet)]
#![feature(type_alias_impl_trait)]
#![feature(yeet_expr)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
#[cfg(test)]

View File

@ -8,7 +8,6 @@
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
// The `builder` module used to be named `build`, but that was causing GitHub's

View File

@ -7,7 +7,6 @@
#![feature(let_chains)]
#![feature(never_type)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_middle::ty;

View File

@ -12,7 +12,6 @@
#![feature(never_type)]
#![feature(try_blocks)]
#![feature(yeet_expr)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use hir::ConstContext;

View File

@ -4,7 +4,6 @@
#![feature(if_let_guard)]
#![feature(impl_trait_in_assoc_type)]
#![feature(let_chains)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_hir::lang_items::LangItem;

View File

@ -6,7 +6,6 @@
// tidy-alphabetical-start
#![allow(rustc::usage_of_type_ir_inherent)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod canonicalizer;

View File

@ -12,7 +12,6 @@
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(string_from_utf8_lossy_owned)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::path::{Path, PathBuf};

View File

@ -13,7 +13,6 @@
html_playground_url = "https://play.rust-lang.org/",
test(attr(deny(warnings)))
)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub use Alignment::*;

View File

@ -12,7 +12,6 @@
#![feature(map_try_insert)]
#![feature(rustdoc_internals)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_middle::query::Providers;

View File

@ -6,7 +6,6 @@
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(feature = "rustc", feature(let_chains))]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod constructor;

View File

@ -5,7 +5,7 @@ use rustc_pattern_analysis::usefulness::{PlaceValidity, UsefulnessReport};
use rustc_pattern_analysis::{MatchArm, PatCx, PrivateUninhabitedField};
/// Sets up `tracing` for easier debugging. Tries to look like the `rustc` setup.
pub fn init_tracing() {
fn init_tracing() {
use tracing_subscriber::Layer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
@ -24,7 +24,7 @@ pub fn init_tracing() {
/// A simple set of types.
#[allow(dead_code)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Ty {
pub(super) enum Ty {
/// Booleans
Bool,
/// 8-bit unsigned integers
@ -41,7 +41,7 @@ pub enum Ty {
/// The important logic.
impl Ty {
pub fn sub_tys(&self, ctor: &Constructor<Cx>) -> Vec<Self> {
pub(super) fn sub_tys(&self, ctor: &Constructor<Cx>) -> Vec<Self> {
use Constructor::*;
match (ctor, *self) {
(Struct, Ty::Tuple(tys)) => tys.iter().copied().collect(),
@ -63,7 +63,7 @@ impl Ty {
}
}
pub fn ctor_set(&self) -> ConstructorSet<Cx> {
fn ctor_set(&self) -> ConstructorSet<Cx> {
match *self {
Ty::Bool => ConstructorSet::Bool,
Ty::U8 => ConstructorSet::Integers {
@ -104,7 +104,7 @@ impl Ty {
}
}
pub fn write_variant_name(
fn write_variant_name(
&self,
f: &mut std::fmt::Formatter<'_>,
ctor: &Constructor<Cx>,
@ -120,7 +120,7 @@ impl Ty {
}
/// Compute usefulness in our simple context (and set up tracing for easier debugging).
pub fn compute_match_usefulness<'p>(
pub(super) fn compute_match_usefulness<'p>(
arms: &[MatchArm<'p, Cx>],
ty: Ty,
scrut_validity: PlaceValidity,
@ -137,7 +137,7 @@ pub fn compute_match_usefulness<'p>(
}
#[derive(Debug)]
pub struct Cx;
pub(super) struct Cx;
/// The context for pattern analysis. Forwards anything interesting to `Ty` methods.
impl PatCx for Cx {

View File

@ -6,7 +6,6 @@
#![feature(let_chains)]
#![feature(rustdoc_internals)]
#![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod errors;

View File

@ -8,7 +8,6 @@
#![feature(min_specialization)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_data_structures::stable_hasher::HashStable;

View File

@ -5,7 +5,6 @@
#![feature(dropck_eyepatch)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod cache;

View File

@ -20,7 +20,6 @@
#![feature(let_chains)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::cell::{Cell, RefCell};

View File

@ -5,7 +5,6 @@
// tidy-alphabetical-start
#![feature(let_chains)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod cfi;

View File

@ -14,7 +14,6 @@
#![feature(min_specialization)]
#![feature(never_type)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub use self::serialize::{Decodable, Decoder, Encodable, Encoder};

View File

@ -7,7 +7,6 @@
// To generate CodegenOptionsTargetModifiers and UnstableOptionsTargetModifiers enums
// with macro_rules, it is necessary to use recursive mechanic ("Incremental TT Munchers").
#![recursion_limit = "256"]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod errors;

View File

@ -15,7 +15,6 @@
)]
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub mod rustc_internal;

View File

@ -32,7 +32,6 @@
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![feature(slice_as_chunks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
// The code produced by the `Encodable`/`Decodable` derive macros refer to

View File

@ -93,7 +93,6 @@
#![doc(rust_logo)]
#![feature(let_chains)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_hir::def::DefKind;

View File

@ -16,7 +16,6 @@
#![feature(let_chains)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use std::path::{Path, PathBuf};

View File

@ -31,7 +31,6 @@
#![feature(unwrap_infallible)]
#![feature(yeet_expr)]
#![recursion_limit = "512"] // For rustdoc
#![warn(unreachable_pub)] // For rustdoc
// tidy-alphabetical-end
pub mod error_reporting;

View File

@ -2,7 +2,6 @@
// tidy-alphabetical-start
#![recursion_limit = "256"]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod codegen;

View File

@ -1,6 +1,5 @@
// tidy-alphabetical-start
#![feature(never_type)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
pub(crate) use rustc_data_structures::fx::{FxIndexMap as Map, FxIndexSet as Set};

View File

@ -16,7 +16,6 @@
#![feature(let_chains)]
#![feature(never_type)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
use rustc_middle::query::Providers;

View File

@ -6,7 +6,6 @@
feature(associated_type_defaults, never_type, rustc_attrs, negative_impls)
)]
#![cfg_attr(feature = "nightly", allow(internal_features))]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
extern crate self as rustc_type_ir;

View File

@ -1045,8 +1045,11 @@ impl Builder<'_> {
// so this line allows the use of custom libcs.
cargo.env("LIBC_CHECK_CFG", "1");
let mut lint_flags = Vec::new();
// Lints for all in-tree code: compiler, rustdoc, cranelift, gcc,
// clippy, rustfmt, rust-analyzer, etc.
if source_type == SourceType::InTree {
let mut lint_flags = Vec::new();
// When extending this list, add the new lints to the RUSTFLAGS of the
// build_bootstrap function of src/bootstrap/bootstrap.py as well as
// some code doesn't go through this `rustc` wrapper.
@ -1058,28 +1061,33 @@ impl Builder<'_> {
rustdocflags.arg("-Dwarnings");
}
// This does not use RUSTFLAGS due to caching issues with Cargo.
// Clippy is treated as an "in tree" tool, but shares the same
// cache as other "submodule" tools. With these options set in
// RUSTFLAGS, that causes *every* shared dependency to be rebuilt.
// By injecting this into the rustc wrapper, this circumvents
// Cargo's fingerprint detection. This is fine because lint flags
// are always ignored in dependencies. Eventually this should be
// fixed via better support from Cargo.
cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
rustdocflags.arg("-Wrustdoc::invalid_codeblock_attributes");
}
// Lints just for `compiler/` crates.
if mode == Mode::Rustc {
rustflags.arg("-Wrustc::internal");
rustflags.arg("-Drustc::symbol_intern_string_literal");
lint_flags.push("-Wrustc::internal");
lint_flags.push("-Drustc::symbol_intern_string_literal");
// FIXME(edition_2024): Change this to `-Wrust_2024_idioms` when all
// of the individual lints are satisfied.
rustflags.arg("-Wkeyword_idents_2024");
rustflags.arg("-Wunsafe_op_in_unsafe_fn");
lint_flags.push("-Wkeyword_idents_2024");
lint_flags.push("-Wunreachable_pub");
lint_flags.push("-Wunsafe_op_in_unsafe_fn");
}
// This does not use RUSTFLAGS for two reasons.
// - Due to caching issues with Cargo. Clippy is treated as an "in
// tree" tool, but shares the same cache as other "submodule" tools.
// With these options set in RUSTFLAGS, that causes *every* shared
// dependency to be rebuilt. By injecting this into the rustc
// wrapper, this circumvents Cargo's fingerprint detection. This is
// fine because lint flags are always ignored in dependencies.
// Eventually this should be fixed via better support from Cargo.
// - RUSTFLAGS is ignored for proc macro crates that are being built on
// the host (because `--target` is given). But we want the lint flags
// to be applied to proc macro crates.
cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
if self.config.rust_frame_pointers {
rustflags.arg("-Cforce-frame-pointers=true");
}