Auto merge of #118001 - TaKO8Ki:rollup-fedlwwj, r=TaKO8Ki

Rollup of 5 pull requests

Successful merges:

 - #117649 (Move `lint_store`)
 - #117850 (bootstrap: simplify setting unstable-options for tools)
 - #117889 (docs(release): Clarify cargo entries)
 - #117946 (avoid exhaustive i16 test in Miri)
 - #117963 (`rustc_query_system` cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-11-17 03:57:57 +00:00
commit 4770d91093
22 changed files with 118 additions and 160 deletions

View File

@ -71,17 +71,17 @@ These APIs are now stable in const contexts:
Cargo Cargo
----- -----
- [fix: Set MSRV for internal packages](https://github.com/rust-lang/cargo/pull/12381/) - [In `Cargo.toml`, stabilize `[lints]`](https://github.com/rust-lang/cargo/pull/12648/)
- [config: merge lists in precedence order](https://github.com/rust-lang/cargo/pull/12515/) - [Stabilize credential-process and registry-auth](https://github.com/rust-lang/cargo/pull/12649/)
- [fix(update): Clarify meaning of --aggressive as --recursive](https://github.com/rust-lang/cargo/pull/12544/) - [Stabilize `--keep-going` build flag](https://github.com/rust-lang/cargo/pull/12568/)
- [fix(update): Make `-p` more convenient by being positional](https://github.com/rust-lang/cargo/pull/12545/) - [Add styling to `--help` output](https://github.com/rust-lang/cargo/pull/12578/)
- [feat(help): Add styling to help output ](https://github.com/rust-lang/cargo/pull/12578/) - [For `cargo clean`, add `--dry-run` flag and summary line at the end](https://github.com/rust-lang/cargo/pull/12638)
- [feat(pkgid): Allow incomplete versions when unambigious](https://github.com/rust-lang/cargo/pull/12614/) - [For `cargo update`, make `--package` more convenient by being positional](https://github.com/rust-lang/cargo/pull/12545/)
- [feat: stabilize credential-process and registry-auth](https://github.com/rust-lang/cargo/pull/12649/) - [For `cargo update`, clarify meaning of --aggressive as --recursive](https://github.com/rust-lang/cargo/pull/12544/)
- [feat(cli): Add '-n' to dry-run](https://github.com/rust-lang/cargo/pull/12660/) - [Add '-n' as an alias for `--dry-run`](https://github.com/rust-lang/cargo/pull/12660/)
- [Allow version-prefixes in pkgid's (e.g. `--package` flags) to resolve ambiguities](https://github.com/rust-lang/cargo/pull/12614/)
- [In `.cargo/config.toml`, merge lists in precedence order](https://github.com/rust-lang/cargo/pull/12515/)
- [Add support for `target.'cfg(..)'.linker`](https://github.com/rust-lang/cargo/pull/12535/) - [Add support for `target.'cfg(..)'.linker`](https://github.com/rust-lang/cargo/pull/12535/)
- [Stabilize `--keep-going`](https://github.com/rust-lang/cargo/pull/12568/)
- [feat: Stabilize lints](https://github.com/rust-lang/cargo/pull/12648/)
<a id="1.74.0-Rustdoc"></a> <a id="1.74.0-Rustdoc"></a>
@ -200,7 +200,6 @@ These APIs are now stable in const contexts:
Cargo Cargo
----- -----
- [Encode URL params correctly for `SourceId` in `Cargo.lock`.](https://github.com/rust-lang/cargo/pull/12280/)
- [Bail out an error when using `cargo::` in custom build script.](https://github.com/rust-lang/cargo/pull/12332/) - [Bail out an error when using `cargo::` in custom build script.](https://github.com/rust-lang/cargo/pull/12332/)
<a id="1.73.0-Misc"></a> <a id="1.73.0-Misc"></a>

View File

@ -33,7 +33,7 @@ use rustc_feature::find_gated_cfg;
use rustc_fluent_macro::fluent_messages; use rustc_fluent_macro::fluent_messages;
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend}; use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
use rustc_interface::{interface, Queries}; use rustc_interface::{interface, Queries};
use rustc_lint::{unerased_lint_store, LintStore}; use rustc_lint::unerased_lint_store;
use rustc_metadata::locator; use rustc_metadata::locator;
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS}; use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths}; use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
@ -356,16 +356,7 @@ fn run_compiler(
let handler = EarlyErrorHandler::new(sopts.error_format); let handler = EarlyErrorHandler::new(sopts.error_format);
if sopts.describe_lints { if sopts.describe_lints {
let mut lint_store = describe_lints(compiler.session());
rustc_lint::new_lint_store(compiler.session().enable_internal_lints());
let registered_lints =
if let Some(register_lints) = compiler.register_lints() {
register_lints(compiler.session(), &mut lint_store);
true
} else {
false
};
describe_lints(compiler.session(), &lint_store, registered_lints);
return; return;
} }
let should_stop = print_crate_info( let should_stop = print_crate_info(
@ -442,9 +433,7 @@ fn run_compiler(
} }
if sess.opts.describe_lints { if sess.opts.describe_lints {
queries describe_lints(sess);
.global_ctxt()?
.enter(|tcx| describe_lints(sess, unerased_lint_store(tcx), true));
return early_exit(); return early_exit();
} }
@ -991,7 +980,7 @@ the command line flag directly.
} }
/// Write to stdout lint command options, together with a list of all available lints /// Write to stdout lint command options, together with a list of all available lints
pub fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_lints: bool) { pub fn describe_lints(sess: &Session) {
safe_println!( safe_println!(
" "
Available lint options: Available lint options:
@ -1017,6 +1006,7 @@ Available lint options:
lints lints
} }
let lint_store = unerased_lint_store(sess);
let (loaded, builtin): (Vec<_>, _) = let (loaded, builtin): (Vec<_>, _) =
lint_store.get_lints().iter().cloned().partition(|&lint| lint.is_loaded); lint_store.get_lints().iter().cloned().partition(|&lint| lint.is_loaded);
let loaded = sort_lints(sess, loaded); let loaded = sort_lints(sess, loaded);
@ -1094,7 +1084,7 @@ Available lint options:
print_lint_groups(builtin_groups, true); print_lint_groups(builtin_groups, true);
match (loaded_lints, loaded.len(), loaded_groups.len()) { match (sess.registered_lints, loaded.len(), loaded_groups.len()) {
(false, 0, _) | (false, _, 0) => { (false, 0, _) | (false, _, 0) => {
safe_println!("Lint tools like Clippy can load additional lints and lint groups."); safe_println!("Lint tools like Clippy can load additional lints and lint groups.");
} }

View File

@ -40,7 +40,6 @@ pub type Result<T> = result::Result<T, ErrorGuaranteed>;
pub struct Compiler { pub struct Compiler {
pub(crate) sess: Lrc<Session>, pub(crate) sess: Lrc<Session>,
codegen_backend: Lrc<dyn CodegenBackend>, codegen_backend: Lrc<dyn CodegenBackend>,
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
pub(crate) override_queries: Option<fn(&Session, &mut Providers)>, pub(crate) override_queries: Option<fn(&Session, &mut Providers)>,
} }
@ -51,9 +50,6 @@ impl Compiler {
pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> { pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> {
&self.codegen_backend &self.codegen_backend
} }
pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> {
&self.register_lints
}
pub fn build_output_filenames( pub fn build_output_filenames(
&self, &self,
sess: &Session, sess: &Session,
@ -485,10 +481,19 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
sess.opts.untracked_state_hash = hasher.finish() sess.opts.untracked_state_hash = hasher.finish()
} }
// Even though the session holds the lint store, we can't build the
// lint store until after the session exists. And we wait until now
// so that `register_lints` sees the fully initialized session.
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
if let Some(register_lints) = config.register_lints.as_deref() {
register_lints(&sess, &mut lint_store);
sess.registered_lints = true;
}
sess.lint_store = Some(Lrc::new(lint_store));
let compiler = Compiler { let compiler = Compiler {
sess: Lrc::new(sess), sess: Lrc::new(sess),
codegen_backend: Lrc::from(codegen_backend), codegen_backend: Lrc::from(codegen_backend),
register_lints: config.register_lints,
override_queries: config.override_queries, override_queries: config.override_queries,
}; };

View File

@ -72,17 +72,6 @@ fn count_nodes(krate: &ast::Crate) -> usize {
counter.count counter.count
} }
pub(crate) fn create_lint_store(
sess: &Session,
register_lints: Option<impl Fn(&Session, &mut LintStore)>,
) -> LintStore {
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
if let Some(register_lints) = register_lints {
register_lints(sess, &mut lint_store);
}
lint_store
}
fn pre_expansion_lint<'a>( fn pre_expansion_lint<'a>(
sess: &Session, sess: &Session,
features: &Features, features: &Features,
@ -138,7 +127,7 @@ fn configure_and_expand(
let tcx = resolver.tcx(); let tcx = resolver.tcx();
let sess = tcx.sess; let sess = tcx.sess;
let features = tcx.features(); let features = tcx.features();
let lint_store = unerased_lint_store(tcx); let lint_store = unerased_lint_store(&tcx.sess);
let crate_name = tcx.crate_name(LOCAL_CRATE); let crate_name = tcx.crate_name(LOCAL_CRATE);
let lint_check_node = (&krate, pre_configured_attrs); let lint_check_node = (&krate, pre_configured_attrs);
pre_expansion_lint( pre_expansion_lint(
@ -330,7 +319,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
} }
}); });
let lint_store = unerased_lint_store(tcx); let lint_store = unerased_lint_store(&tcx.sess);
rustc_lint::check_ast_node( rustc_lint::check_ast_node(
sess, sess,
tcx.features(), tcx.features(),
@ -645,7 +634,6 @@ pub fn create_global_ctxt<'tcx>(
compiler: &'tcx Compiler, compiler: &'tcx Compiler,
crate_types: Vec<CrateType>, crate_types: Vec<CrateType>,
stable_crate_id: StableCrateId, stable_crate_id: StableCrateId,
lint_store: Lrc<LintStore>,
dep_graph: DepGraph, dep_graph: DepGraph,
untracked: Untracked, untracked: Untracked,
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>, gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>,
@ -676,7 +664,6 @@ pub fn create_global_ctxt<'tcx>(
sess, sess,
crate_types, crate_types,
stable_crate_id, stable_crate_id,
lint_store,
arena, arena,
hir_arena, hir_arena,
untracked, untracked,

View File

@ -148,8 +148,6 @@ impl<'tcx> Queries<'tcx> {
); );
let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?; let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?;
let lint_store =
Lrc::new(passes::create_lint_store(sess, self.compiler.register_lints.as_deref()));
let cstore = FreezeLock::new(Box::new(CStore::new( let cstore = FreezeLock::new(Box::new(CStore::new(
self.codegen_backend().metadata_loader(), self.codegen_backend().metadata_loader(),
stable_crate_id, stable_crate_id,
@ -164,7 +162,6 @@ impl<'tcx> Queries<'tcx> {
self.compiler, self.compiler,
crate_types, crate_types,
stable_crate_id, stable_crate_id,
lint_store,
dep_graph, dep_graph,
untracked, untracked,
&self.gcx_cell, &self.gcx_cell,

View File

@ -497,9 +497,6 @@ pub struct LateContext<'tcx> {
/// Items accessible from the crate being checked. /// Items accessible from the crate being checked.
pub effective_visibilities: &'tcx EffectiveVisibilities, pub effective_visibilities: &'tcx EffectiveVisibilities,
/// The store of registered lints and the lint levels.
pub lint_store: &'tcx LintStore,
pub last_node_with_lint_attrs: hir::HirId, pub last_node_with_lint_attrs: hir::HirId,
/// Generic type parameters in scope for the item we are in. /// Generic type parameters in scope for the item we are in.
@ -515,21 +512,14 @@ pub struct EarlyContext<'a> {
pub buffered: LintBuffer, pub buffered: LintBuffer,
} }
pub trait LintPassObject: Sized {} pub trait LintContext {
impl LintPassObject for EarlyLintPassObject {}
impl LintPassObject for LateLintPassObject<'_> {}
pub trait LintContext: Sized {
type PassObject: LintPassObject;
fn sess(&self) -> &Session; fn sess(&self) -> &Session;
fn lints(&self) -> &LintStore;
/// Emit a lint at the appropriate level, with an optional associated span and an existing diagnostic. /// Emit a lint at the appropriate level, with an optional associated span and an existing
/// diagnostic.
/// ///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation. /// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed
/// explanation.
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
@ -1059,17 +1049,11 @@ impl<'a> EarlyContext<'a> {
} }
impl<'tcx> LintContext for LateContext<'tcx> { impl<'tcx> LintContext for LateContext<'tcx> {
type PassObject = LateLintPassObject<'tcx>;
/// Gets the overall compiler `Session` object. /// Gets the overall compiler `Session` object.
fn sess(&self) -> &Session { fn sess(&self) -> &Session {
&self.tcx.sess &self.tcx.sess
} }
fn lints(&self) -> &LintStore {
&*self.lint_store
}
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>( fn lookup<S: Into<MultiSpan>>(
&self, &self,
@ -1094,17 +1078,11 @@ impl<'tcx> LintContext for LateContext<'tcx> {
} }
impl LintContext for EarlyContext<'_> { impl LintContext for EarlyContext<'_> {
type PassObject = EarlyLintPassObject;
/// Gets the overall compiler `Session` object. /// Gets the overall compiler `Session` object.
fn sess(&self) -> &Session { fn sess(&self) -> &Session {
&self.builder.sess() &self.builder.sess()
} }
fn lints(&self) -> &LintStore {
self.builder.lint_store()
}
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>( fn lookup<S: Into<MultiSpan>>(
&self, &self,

View File

@ -17,22 +17,25 @@
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore}; use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::sync::join; use rustc_data_structures::sync::{join, Lrc};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_hir::intravisit as hir_visit; use rustc_hir::intravisit as hir_visit;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_session::lint::LintPass; use rustc_session::lint::LintPass;
use rustc_session::Session;
use rustc_span::Span; use rustc_span::Span;
use std::any::Any; use std::any::Any;
use std::cell::Cell; use std::cell::Cell;
/// Extract the `LintStore` from the query context. /// Extract the `LintStore` from the query context.
/// This function exists because we've erased `LintStore` as `dyn Any` in the context. /// This function exists because we've erased `LintStore` as `dyn Any` in the session.
pub fn unerased_lint_store(tcx: TyCtxt<'_>) -> &LintStore { pub fn unerased_lint_store(sess: &Session) -> &LintStore {
let store: &dyn Any = &*tcx.lint_store; assert!(sess.lint_store.is_some());
let store: &Lrc<_> = sess.lint_store.as_ref().unwrap();
let store: &dyn Any = &**store;
store.downcast_ref().unwrap() store.downcast_ref().unwrap()
} }
@ -353,7 +356,6 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
cached_typeck_results: Cell::new(None), cached_typeck_results: Cell::new(None),
param_env: ty::ParamEnv::empty(), param_env: ty::ParamEnv::empty(),
effective_visibilities: &tcx.effective_visibilities(()), effective_visibilities: &tcx.effective_visibilities(()),
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: tcx.hir().local_def_id_to_hir_id(module_def_id), last_node_with_lint_attrs: tcx.hir().local_def_id_to_hir_id(module_def_id),
generics: None, generics: None,
only_module: true, only_module: true,
@ -362,8 +364,11 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
// Note: `passes` is often empty. In that case, it's faster to run // Note: `passes` is often empty. In that case, it's faster to run
// `builtin_lints` directly rather than bundling it up into the // `builtin_lints` directly rather than bundling it up into the
// `RuntimeCombinedLateLintPass`. // `RuntimeCombinedLateLintPass`.
let mut passes: Vec<_> = let mut passes: Vec<_> = unerased_lint_store(&tcx.sess)
unerased_lint_store(tcx).late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect(); .late_module_passes
.iter()
.map(|mk_pass| (mk_pass)(tcx))
.collect();
if passes.is_empty() { if passes.is_empty() {
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints); late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
} else { } else {
@ -400,7 +405,7 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) { fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
// Note: `passes` is often empty. // Note: `passes` is often empty.
let mut passes: Vec<_> = let mut passes: Vec<_> =
unerased_lint_store(tcx).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect(); unerased_lint_store(&tcx.sess).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
if passes.is_empty() { if passes.is_empty() {
return; return;
@ -412,7 +417,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
cached_typeck_results: Cell::new(None), cached_typeck_results: Cell::new(None),
param_env: ty::ParamEnv::empty(), param_env: ty::ParamEnv::empty(),
effective_visibilities: &tcx.effective_visibilities(()), effective_visibilities: &tcx.effective_visibilities(()),
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: hir::CRATE_HIR_ID, last_node_with_lint_attrs: hir::CRATE_HIR_ID,
generics: None, generics: None,
only_module: false, only_module: false,

View File

@ -123,7 +123,7 @@ impl LintLevelSets {
} }
fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> { fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> {
let store = unerased_lint_store(tcx); let store = unerased_lint_store(&tcx.sess);
let mut builder = LintLevelsBuilder { let mut builder = LintLevelsBuilder {
sess: tcx.sess, sess: tcx.sess,
@ -152,7 +152,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
#[instrument(level = "trace", skip(tcx), ret)] #[instrument(level = "trace", skip(tcx), ret)]
fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLevelMap { fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLevelMap {
let store = unerased_lint_store(tcx); let store = unerased_lint_store(&tcx.sess);
let attrs = tcx.hir_attrs(owner); let attrs = tcx.hir_attrs(owner);
let mut levels = LintLevelsBuilder { let mut levels = LintLevelsBuilder {
@ -548,10 +548,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
self.features self.features
} }
pub(crate) fn lint_store(&self) -> &LintStore {
self.store
}
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> { fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
self.provider.current_specs() self.provider.current_specs()
} }

View File

@ -8,8 +8,8 @@ mod dep_node;
pub use rustc_query_system::dep_graph::debug::EdgeFilter; pub use rustc_query_system::dep_graph::debug::EdgeFilter;
pub use rustc_query_system::dep_graph::{ pub use rustc_query_system::dep_graph::{
debug::DepNodeFilter, hash_result, DepContext, DepGraphQuery, DepNodeColor, DepNodeIndex, Deps, debug::DepNodeFilter, hash_result, DepContext, DepGraphQuery, DepNodeIndex, Deps,
SerializedDepGraph, SerializedDepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct, WorkProductId, SerializedDepGraph, SerializedDepNodeIndex, TaskDepsRef, WorkProduct, WorkProductId,
WorkProductMap, WorkProductMap,
}; };

View File

@ -39,7 +39,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal; use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, WorkerLocal}; use rustc_data_structures::sync::{FreezeReadGuard, Lock, WorkerLocal};
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_errors::{ use rustc_errors::{
DecorateLint, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan, DecorateLint, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
@ -69,7 +69,6 @@ use rustc_type_ir::TyKind::*;
use rustc_type_ir::WithCachedTypeInfo; use rustc_type_ir::WithCachedTypeInfo;
use rustc_type_ir::{CollectAndApply, Interner, TypeFlags}; use rustc_type_ir::{CollectAndApply, Interner, TypeFlags};
use std::any::Any;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::fmt; use std::fmt;
@ -544,12 +543,6 @@ pub struct GlobalCtxt<'tcx> {
/// `rustc_symbol_mangling` crate for more information. /// `rustc_symbol_mangling` crate for more information.
stable_crate_id: StableCrateId, stable_crate_id: StableCrateId,
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
///
/// FIXME(Centril): consider `dyn LintStoreMarker` once
/// we can upcast to `Any` for some additional type safety.
pub lint_store: Lrc<dyn Any + sync::DynSync + sync::DynSend>,
pub dep_graph: DepGraph, pub dep_graph: DepGraph,
pub prof: SelfProfilerRef, pub prof: SelfProfilerRef,
@ -709,7 +702,6 @@ impl<'tcx> TyCtxt<'tcx> {
s: &'tcx Session, s: &'tcx Session,
crate_types: Vec<CrateType>, crate_types: Vec<CrateType>,
stable_crate_id: StableCrateId, stable_crate_id: StableCrateId,
lint_store: Lrc<dyn Any + sync::DynSend + sync::DynSync>,
arena: &'tcx WorkerLocal<Arena<'tcx>>, arena: &'tcx WorkerLocal<Arena<'tcx>>,
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>, hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
untracked: Untracked, untracked: Untracked,
@ -730,7 +722,6 @@ impl<'tcx> TyCtxt<'tcx> {
sess: s, sess: s,
crate_types, crate_types,
stable_crate_id, stable_crate_id,
lint_store,
arena, arena,
hir_arena, hir_arena,
interners, interners,

View File

@ -5,7 +5,7 @@ use std::iter::Extend;
use std::ops::Deref; use std::ops::Deref;
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct EdgesVec { pub(crate) struct EdgesVec {
max: u32, max: u32,
edges: SmallVec<[DepNodeIndex; EdgesVec::INLINE_CAPACITY]>, edges: SmallVec<[DepNodeIndex; EdgesVec::INLINE_CAPACITY]>,
} }
@ -18,21 +18,21 @@ impl Hash for EdgesVec {
} }
impl EdgesVec { impl EdgesVec {
pub const INLINE_CAPACITY: usize = 8; pub(crate) const INLINE_CAPACITY: usize = 8;
#[inline] #[inline]
pub fn new() -> Self { pub(crate) fn new() -> Self {
Self::default() Self::default()
} }
#[inline] #[inline]
pub fn push(&mut self, edge: DepNodeIndex) { pub(crate) fn push(&mut self, edge: DepNodeIndex) {
self.max = self.max.max(edge.as_u32()); self.max = self.max.max(edge.as_u32());
self.edges.push(edge); self.edges.push(edge);
} }
#[inline] #[inline]
pub fn max_index(&self) -> u32 { pub(crate) fn max_index(&self) -> u32 {
self.max self.max
} }
} }

View File

@ -18,7 +18,7 @@ use std::sync::atomic::Ordering::Relaxed;
use super::query::DepGraphQuery; use super::query::DepGraphQuery;
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex}; use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId}; use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId};
use crate::dep_graph::EdgesVec; use crate::dep_graph::edges::EdgesVec;
use crate::ich::StableHashingContext; use crate::ich::StableHashingContext;
use crate::query::{QueryContext, QuerySideEffects}; use crate::query::{QueryContext, QuerySideEffects};
@ -41,8 +41,7 @@ rustc_index::newtype_index! {
} }
impl DepNodeIndex { impl DepNodeIndex {
pub const INVALID: DepNodeIndex = DepNodeIndex::MAX; const SINGLETON_DEPENDENCYLESS_ANON_NODE: DepNodeIndex = DepNodeIndex::from_u32(0);
pub const SINGLETON_DEPENDENCYLESS_ANON_NODE: DepNodeIndex = DepNodeIndex::from_u32(0);
pub const FOREVER_RED_NODE: DepNodeIndex = DepNodeIndex::from_u32(1); pub const FOREVER_RED_NODE: DepNodeIndex = DepNodeIndex::from_u32(1);
} }
@ -53,20 +52,20 @@ impl From<DepNodeIndex> for QueryInvocationId {
} }
} }
pub struct MarkFrame<'a> { pub(crate) struct MarkFrame<'a> {
index: SerializedDepNodeIndex, index: SerializedDepNodeIndex,
parent: Option<&'a MarkFrame<'a>>, parent: Option<&'a MarkFrame<'a>>,
} }
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum DepNodeColor { enum DepNodeColor {
Red, Red,
Green(DepNodeIndex), Green(DepNodeIndex),
} }
impl DepNodeColor { impl DepNodeColor {
#[inline] #[inline]
pub fn is_green(self) -> bool { fn is_green(self) -> bool {
match self { match self {
DepNodeColor::Red => false, DepNodeColor::Red => false,
DepNodeColor::Green(_) => true, DepNodeColor::Green(_) => true,
@ -74,7 +73,7 @@ impl DepNodeColor {
} }
} }
pub struct DepGraphData<D: Deps> { pub(crate) struct DepGraphData<D: Deps> {
/// The new encoding of the dependency graph, optimized for red/green /// The new encoding of the dependency graph, optimized for red/green
/// tracking. The `current` field is the dependency graph of only the /// tracking. The `current` field is the dependency graph of only the
/// current compilation session: We don't merge the previous dep-graph into /// current compilation session: We don't merge the previous dep-graph into
@ -185,7 +184,7 @@ impl<D: Deps> DepGraph<D> {
} }
#[inline] #[inline]
pub fn data(&self) -> Option<&DepGraphData<D>> { pub(crate) fn data(&self) -> Option<&DepGraphData<D>> {
self.data.as_deref() self.data.as_deref()
} }
@ -333,7 +332,7 @@ impl<D: Deps> DepGraphData<D> {
/// ///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
#[inline(always)] #[inline(always)]
pub fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>( pub(crate) fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>(
&self, &self,
key: DepNode, key: DepNode,
cx: Ctxt, cx: Ctxt,
@ -398,7 +397,7 @@ impl<D: Deps> DepGraphData<D> {
/// Executes something within an "anonymous" task, that is, a task the /// Executes something within an "anonymous" task, that is, a task the
/// `DepNode` of which is determined by the list of inputs it read from. /// `DepNode` of which is determined by the list of inputs it read from.
pub fn with_anon_task<Tcx: DepContext<Deps = D>, OP, R>( pub(crate) fn with_anon_task<Tcx: DepContext<Deps = D>, OP, R>(
&self, &self,
cx: Tcx, cx: Tcx,
dep_kind: DepKind, dep_kind: DepKind,
@ -618,7 +617,7 @@ impl<D: Deps> DepGraph<D> {
impl<D: Deps> DepGraphData<D> { impl<D: Deps> DepGraphData<D> {
#[inline] #[inline]
pub fn dep_node_index_of_opt(&self, dep_node: &DepNode) -> Option<DepNodeIndex> { fn dep_node_index_of_opt(&self, dep_node: &DepNode) -> Option<DepNodeIndex> {
if let Some(prev_index) = self.previous.node_to_index_opt(dep_node) { if let Some(prev_index) = self.previous.node_to_index_opt(dep_node) {
self.current.prev_index_to_index.lock()[prev_index] self.current.prev_index_to_index.lock()[prev_index]
} else { } else {
@ -627,7 +626,7 @@ impl<D: Deps> DepGraphData<D> {
} }
#[inline] #[inline]
pub fn dep_node_exists(&self, dep_node: &DepNode) -> bool { fn dep_node_exists(&self, dep_node: &DepNode) -> bool {
self.dep_node_index_of_opt(dep_node).is_some() self.dep_node_index_of_opt(dep_node).is_some()
} }
@ -643,21 +642,21 @@ impl<D: Deps> DepGraphData<D> {
/// Returns true if the given node has been marked as green during the /// Returns true if the given node has been marked as green during the
/// current compilation session. Used in various assertions /// current compilation session. Used in various assertions
#[inline] #[inline]
pub fn is_index_green(&self, prev_index: SerializedDepNodeIndex) -> bool { pub(crate) fn is_index_green(&self, prev_index: SerializedDepNodeIndex) -> bool {
self.colors.get(prev_index).is_some_and(|c| c.is_green()) self.colors.get(prev_index).is_some_and(|c| c.is_green())
} }
#[inline] #[inline]
pub fn prev_fingerprint_of(&self, prev_index: SerializedDepNodeIndex) -> Fingerprint { pub(crate) fn prev_fingerprint_of(&self, prev_index: SerializedDepNodeIndex) -> Fingerprint {
self.previous.fingerprint_by_index(prev_index) self.previous.fingerprint_by_index(prev_index)
} }
#[inline] #[inline]
pub fn prev_node_of(&self, prev_index: SerializedDepNodeIndex) -> DepNode { pub(crate) fn prev_node_of(&self, prev_index: SerializedDepNodeIndex) -> DepNode {
self.previous.index_to_node(prev_index) self.previous.index_to_node(prev_index)
} }
pub fn mark_debug_loaded_from_disk(&self, dep_node: DepNode) { pub(crate) fn mark_debug_loaded_from_disk(&self, dep_node: DepNode) {
self.debug_loaded_from_disk.lock().insert(dep_node); self.debug_loaded_from_disk.lock().insert(dep_node);
} }
} }
@ -684,8 +683,9 @@ impl<D: Deps> DepGraph<D> {
self.data.as_ref().unwrap().debug_loaded_from_disk.lock().contains(&dep_node) self.data.as_ref().unwrap().debug_loaded_from_disk.lock().contains(&dep_node)
} }
#[cfg(debug_assertions)]
#[inline(always)] #[inline(always)]
pub fn register_dep_node_debug_str<F>(&self, dep_node: DepNode, debug_str_gen: F) pub(crate) fn register_dep_node_debug_str<F>(&self, dep_node: DepNode, debug_str_gen: F)
where where
F: FnOnce() -> String, F: FnOnce() -> String,
{ {
@ -725,7 +725,7 @@ impl<D: Deps> DepGraphData<D> {
/// A node will have an index, when it's already been marked green, or when we can mark it /// A node will have an index, when it's already been marked green, or when we can mark it
/// green. This function will mark the current task as a reader of the specified node, when /// green. This function will mark the current task as a reader of the specified node, when
/// a node index can be found for that node. /// a node index can be found for that node.
pub fn try_mark_green<Qcx: QueryContext<Deps = D>>( pub(crate) fn try_mark_green<Qcx: QueryContext<Deps = D>>(
&self, &self,
qcx: Qcx, qcx: Qcx,
dep_node: &DepNode, dep_node: &DepNode,

View File

@ -6,11 +6,8 @@ mod query;
mod serialized; mod serialized;
pub use dep_node::{DepKind, DepKindStruct, DepNode, DepNodeParams, WorkProductId}; pub use dep_node::{DepKind, DepKindStruct, DepNode, DepNodeParams, WorkProductId};
pub use edges::EdgesVec; pub(crate) use graph::DepGraphData;
pub use graph::{ pub use graph::{hash_result, DepGraph, DepNodeIndex, TaskDepsRef, WorkProduct, WorkProductMap};
hash_result, DepGraph, DepGraphData, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef,
WorkProduct, WorkProductMap,
};
pub use query::DepGraphQuery; pub use query::DepGraphQuery;
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex}; pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};

View File

@ -37,7 +37,7 @@
use super::query::DepGraphQuery; use super::query::DepGraphQuery;
use super::{DepKind, DepNode, DepNodeIndex, Deps}; use super::{DepKind, DepNode, DepNodeIndex, Deps};
use crate::dep_graph::EdgesVec; use crate::dep_graph::edges::EdgesVec;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fingerprint::PackedFingerprint; use rustc_data_structures::fingerprint::PackedFingerprint;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;

View File

@ -28,7 +28,7 @@ pub struct StableHashingContext<'a> {
// `CachingSourceMapView`, so we initialize it lazily. // `CachingSourceMapView`, so we initialize it lazily.
raw_source_map: &'a SourceMap, raw_source_map: &'a SourceMap,
caching_source_map: Option<CachingSourceMapView<'a>>, caching_source_map: Option<CachingSourceMapView<'a>>,
pub(super) hashing_controls: HashingControls, hashing_controls: HashingControls,
} }
/// The `BodyResolver` allows mapping a `BodyId` to the corresponding `hir::Body`. /// The `BodyResolver` allows mapping a `BodyId` to the corresponding `hir::Body`.

View File

@ -2,9 +2,7 @@
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(hash_raw_entry)] #![feature(hash_raw_entry)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(extern_types)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(inline_const)]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]

View File

@ -16,7 +16,9 @@ use rustc_data_structures::flock;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_data_structures::jobserver::{self, Client}; use rustc_data_structures::jobserver::{self, Client};
use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef}; use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
use rustc_data_structures::sync::{AtomicU64, Lock, Lrc, OneThread, Ordering::SeqCst}; use rustc_data_structures::sync::{
AtomicU64, DynSend, DynSync, Lock, Lrc, OneThread, Ordering::SeqCst,
};
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter; use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
use rustc_errors::emitter::{DynEmitter, EmitterWriter, HumanReadableErrorType}; use rustc_errors::emitter::{DynEmitter, EmitterWriter, HumanReadableErrorType};
use rustc_errors::json::JsonEmitter; use rustc_errors::json::JsonEmitter;
@ -37,6 +39,7 @@ use rustc_target::spec::{
DebuginfoKind, SanitizerSet, SplitDebuginfo, StackProtector, Target, TargetTriple, TlsModel, DebuginfoKind, SanitizerSet, SplitDebuginfo, StackProtector, Target, TargetTriple, TlsModel,
}; };
use std::any::Any;
use std::cell::{self, RefCell}; use std::cell::{self, RefCell};
use std::env; use std::env;
use std::fmt; use std::fmt;
@ -167,6 +170,15 @@ pub struct Session {
/// false positives about a job server in our environment. /// false positives about a job server in our environment.
pub jobserver: Client, pub jobserver: Client,
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
///
/// FIXME(Centril): consider `dyn LintStoreMarker` once
/// we can upcast to `Any` for some additional type safety.
pub lint_store: Option<Lrc<dyn Any + DynSync + DynSend>>,
/// Should be set if any lints are registered in `lint_store`.
pub registered_lints: bool,
/// Cap lint level specified by a driver specifically. /// Cap lint level specified by a driver specifically.
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>, pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
@ -1483,6 +1495,8 @@ pub fn build_session(
optimization_fuel, optimization_fuel,
print_fuel, print_fuel,
jobserver: jobserver::client(), jobserver: jobserver::client(),
lint_store: None,
registered_lints: false,
driver_lint_caps, driver_lint_caps,
ctfe_backtrace, ctfe_backtrace,
miri_unleashed_features: Lock::new(Default::default()), miri_unleashed_features: Lock::new(Default::default()),

View File

@ -152,8 +152,11 @@ fn test_format_int_exp_precision() {
assert_eq!(format!("{:+10.3e}", 1), " +1.000e0"); assert_eq!(format!("{:+10.3e}", 1), " +1.000e0");
// test precision remains correct when rounding to next power // test precision remains correct when rounding to next power
#[cfg(miri)] // can't cover all of `i16` in Miri
for i in i16::MIN..=i16::MAX { let range = [i16::MIN, -1, 1, i16::MAX];
#[cfg(not(miri))]
let range = i16::MIN..=i16::MAX;
for i in range {
for p in 0..=5 { for p in 0..=5 {
assert_eq!( assert_eq!(
format!("{i:.p$e}"), format!("{i:.p$e}"),

View File

@ -463,10 +463,6 @@ macro_rules! tool_check_step {
cargo.arg("--all-targets"); cargo.arg("--all-targets");
} }
// Enable internal lints for clippy and rustdoc
// NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]`
// See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
cargo.rustflag("-Zunstable-options");
let _guard = builder.msg_check(&concat!(stringify!($name), " artifacts").to_lowercase(), target); let _guard = builder.msg_check(&concat!(stringify!($name), " artifacts").to_lowercase(), target);
run_cargo( run_cargo(
builder, builder,

View File

@ -203,6 +203,16 @@ pub fn prepare_tool_cargo(
if !features.is_empty() { if !features.is_empty() {
cargo.arg("--features").arg(&features.join(", ")); cargo.arg("--features").arg(&features.join(", "));
} }
// Enable internal lints for clippy and rustdoc
// NOTE: this doesn't enable lints for any other tools unless they explicitly add `#![warn(rustc::internal)]`
// See https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776
//
// NOTE: We unconditionally set this here to avoid recompiling tools between `x check $tool`
// and `x test $tool` executions.
// See https://github.com/rust-lang/rust/issues/116538
cargo.rustflag("-Zunstable-options");
cargo cargo
} }

View File

@ -797,14 +797,7 @@ fn main_args(
let sess = compiler.session(); let sess = compiler.session();
if sess.opts.describe_lints { if sess.opts.describe_lints {
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints()); rustc_driver::describe_lints(sess);
let registered_lints = if let Some(register_lints) = compiler.register_lints() {
register_lints(sess, &mut lint_store);
true
} else {
false
};
rustc_driver::describe_lints(sess, &lint_store, registered_lints);
return Ok(()); return Ok(());
} }

View File

@ -1,17 +1,11 @@
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:25:5
|
LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
|
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::macro_use_imports)]`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:23:5 --> $DIR/macro_use_imports.rs:23:5
| |
LL | #[macro_use] LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};`
|
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::macro_use_imports)]`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:21:5 --> $DIR/macro_use_imports.rs:21:5
@ -19,6 +13,12 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition
LL | #[macro_use] LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:25:5
|
LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:19:5 --> $DIR/macro_use_imports.rs:19:5
| |