Querify early_lint_checks.
This commit is contained in:
parent
b7e2b049f3
commit
c90fc105cb
@ -436,6 +436,7 @@ fn compute_hir_hash(
|
|||||||
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
|
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
|
||||||
let sess = tcx.sess;
|
let sess = tcx.sess;
|
||||||
tcx.ensure().output_filenames(());
|
tcx.ensure().output_filenames(());
|
||||||
|
let _ = tcx.early_lint_checks(()); // Borrows `resolver_for_lowering`.
|
||||||
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
|
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
|
||||||
|
|
||||||
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
|
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
|
||||||
|
@ -331,6 +331,7 @@ fn run_compiler(
|
|||||||
if let Some(ppm) = &sess.opts.pretty {
|
if let Some(ppm) = &sess.opts.pretty {
|
||||||
if ppm.needs_ast_map() {
|
if ppm.needs_ast_map() {
|
||||||
queries.global_ctxt()?.enter(|tcx| {
|
queries.global_ctxt()?.enter(|tcx| {
|
||||||
|
tcx.ensure().early_lint_checks(());
|
||||||
pretty::print_after_hir_lowering(tcx, *ppm);
|
pretty::print_after_hir_lowering(tcx, *ppm);
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
@ -11,7 +11,7 @@ use rustc_data_structures::parallel;
|
|||||||
use rustc_data_structures::steal::Steal;
|
use rustc_data_structures::steal::Steal;
|
||||||
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
|
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
|
||||||
use rustc_errors::PResult;
|
use rustc_errors::PResult;
|
||||||
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
|
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
|
||||||
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
|
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
|
||||||
use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintStore};
|
use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintStore};
|
||||||
use rustc_metadata::creader::CStore;
|
use rustc_metadata::creader::CStore;
|
||||||
@ -302,6 +302,16 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
|
|||||||
|
|
||||||
// Done with macro expansion!
|
// Done with macro expansion!
|
||||||
|
|
||||||
|
resolver.resolve_crate(&krate);
|
||||||
|
|
||||||
|
krate
|
||||||
|
}
|
||||||
|
|
||||||
|
fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
|
||||||
|
let sess = tcx.sess;
|
||||||
|
let (resolver, krate) = &*tcx.resolver_for_lowering(()).borrow();
|
||||||
|
let mut lint_buffer = resolver.lint_buffer.steal();
|
||||||
|
|
||||||
if sess.opts.unstable_opts.input_stats {
|
if sess.opts.unstable_opts.input_stats {
|
||||||
eprintln!("Post-expansion node count: {}", count_nodes(&krate));
|
eprintln!("Post-expansion node count: {}", count_nodes(&krate));
|
||||||
}
|
}
|
||||||
@ -310,8 +320,6 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
|
|||||||
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS", "ast-stats-2");
|
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS", "ast-stats-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
resolver.resolve_crate(&krate);
|
|
||||||
|
|
||||||
// Needs to go *after* expansion to be able to check the results of macro expansion.
|
// Needs to go *after* expansion to be able to check the results of macro expansion.
|
||||||
sess.time("complete_gated_feature_checking", || {
|
sess.time("complete_gated_feature_checking", || {
|
||||||
rustc_ast_passes::feature_gate::check_crate(&krate, sess);
|
rustc_ast_passes::feature_gate::check_crate(&krate, sess);
|
||||||
@ -321,7 +329,7 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
|
|||||||
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
|
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
|
||||||
info!("{} parse sess buffered_lints", buffered_lints.len());
|
info!("{} parse sess buffered_lints", buffered_lints.len());
|
||||||
for early_lint in buffered_lints.drain(..) {
|
for early_lint in buffered_lints.drain(..) {
|
||||||
resolver.lint_buffer().add_early_lint(early_lint);
|
lint_buffer.add_early_lint(early_lint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -340,20 +348,16 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sess.time("early_lint_checks", || {
|
let lint_store = unerased_lint_store(tcx);
|
||||||
let lint_buffer = Some(std::mem::take(resolver.lint_buffer()));
|
rustc_lint::check_ast_node(
|
||||||
rustc_lint::check_ast_node(
|
sess,
|
||||||
sess,
|
false,
|
||||||
false,
|
lint_store,
|
||||||
lint_store,
|
tcx.registered_tools(()),
|
||||||
resolver.registered_tools(),
|
Some(lint_buffer),
|
||||||
lint_buffer,
|
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
|
||||||
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
|
&**krate,
|
||||||
&krate,
|
)
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
krate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns all the paths that correspond to generated files.
|
// Returns all the paths that correspond to generated files.
|
||||||
@ -630,6 +634,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
|
|||||||
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
|
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
|
||||||
providers.output_filenames = output_filenames;
|
providers.output_filenames = output_filenames;
|
||||||
providers.resolver_for_lowering = resolver_for_lowering;
|
providers.resolver_for_lowering = resolver_for_lowering;
|
||||||
|
providers.early_lint_checks = early_lint_checks;
|
||||||
proc_macro_decls::provide(providers);
|
proc_macro_decls::provide(providers);
|
||||||
rustc_const_eval::provide(providers);
|
rustc_const_eval::provide(providers);
|
||||||
rustc_middle::hir::provide(providers);
|
rustc_middle::hir::provide(providers);
|
||||||
|
@ -526,6 +526,7 @@ pub enum BuiltinLintDiagnostics {
|
|||||||
|
|
||||||
/// Lints that are buffered up early on in the `Session` before the
|
/// Lints that are buffered up early on in the `Session` before the
|
||||||
/// `LintLevels` is calculated.
|
/// `LintLevels` is calculated.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct BufferedEarlyLint {
|
pub struct BufferedEarlyLint {
|
||||||
/// The span of code that we are linting on.
|
/// The span of code that we are linting on.
|
||||||
pub span: MultiSpan,
|
pub span: MultiSpan,
|
||||||
@ -544,7 +545,7 @@ pub struct BufferedEarlyLint {
|
|||||||
pub diagnostic: BuiltinLintDiagnostics,
|
pub diagnostic: BuiltinLintDiagnostics,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, Debug)]
|
||||||
pub struct LintBuffer {
|
pub struct LintBuffer {
|
||||||
pub map: FxIndexMap<NodeId, Vec<BufferedEarlyLint>>,
|
pub map: FxIndexMap<NodeId, Vec<BufferedEarlyLint>>,
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ rustc_queries! {
|
|||||||
desc { "compute registered tools for crate" }
|
desc { "compute registered tools for crate" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query early_lint_checks(_: ()) -> () {
|
||||||
|
desc { "perform lints prior to macro expansion" }
|
||||||
|
}
|
||||||
|
|
||||||
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
|
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
|
||||||
feedable
|
feedable
|
||||||
no_hash
|
no_hash
|
||||||
|
@ -34,6 +34,7 @@ use rustc_attr as attr;
|
|||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
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::tagged_ptr::CopyTaggedPtr;
|
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
@ -44,6 +45,7 @@ use rustc_index::vec::IndexVec;
|
|||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
use rustc_serialize::{Decodable, Encodable};
|
use rustc_serialize::{Decodable, Encodable};
|
||||||
|
use rustc_session::lint::LintBuffer;
|
||||||
pub use rustc_session::lint::RegisteredTools;
|
pub use rustc_session::lint::RegisteredTools;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
@ -211,6 +213,9 @@ pub struct ResolverAstLowering {
|
|||||||
pub builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
|
pub builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
|
||||||
/// List functions and methods for which lifetime elision was successful.
|
/// List functions and methods for which lifetime elision was successful.
|
||||||
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,
|
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,
|
||||||
|
|
||||||
|
/// Lints that were emitted by the resolver and early lints.
|
||||||
|
pub lint_buffer: Steal<LintBuffer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
@ -27,6 +27,7 @@ use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
|
|||||||
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
|
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
|
use rustc_data_structures::steal::Steal;
|
||||||
use rustc_data_structures::sync::{Lrc, MappedReadGuard};
|
use rustc_data_structures::sync::{Lrc, MappedReadGuard};
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, SubdiagnosticMessage,
|
Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, SubdiagnosticMessage,
|
||||||
@ -1441,6 +1442,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
trait_map: self.trait_map,
|
trait_map: self.trait_map,
|
||||||
builtin_macro_kinds: self.builtin_macro_kinds,
|
builtin_macro_kinds: self.builtin_macro_kinds,
|
||||||
lifetime_elision_allowed: self.lifetime_elision_allowed,
|
lifetime_elision_allowed: self.lifetime_elision_allowed,
|
||||||
|
lint_buffer: Steal::new(self.lint_buffer),
|
||||||
};
|
};
|
||||||
ResolverOutputs { global_ctxt, ast_lowering }
|
ResolverOutputs { global_ctxt, ast_lowering }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user