diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 229b6c10759d6..f498d2fb02319 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -847,14 +847,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { let bodies = SortedMap::from_presorted_elements(bodies); // Don't hash unless necessary, because it's expensive. - let rustc_middle::hir::Hashes { opt_hash_including_bodies, attrs_hash, delayed_lints_hash } = - self.tcx.hash_owner_nodes(node, &bodies, &attrs, &delayed_lints, define_opaque); + let rustc_middle::hir::Hashes { opt_hash_including_bodies, attrs_hash } = + self.tcx.hash_owner_nodes(node, &bodies, &attrs, define_opaque); let num_nodes = self.item_local_id_counter.as_usize(); let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes); let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies }; let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque }; - let delayed_lints = - hir::lints::DelayedLints { lints: delayed_lints, opt_hash: delayed_lints_hash }; self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints }) } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index e4e6642981d1a..c662b88209bd5 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1631,6 +1631,10 @@ pub struct OwnerInfo<'hir> { /// Lints delayed during ast lowering to be emitted /// after hir has completely built + /// + /// WARNING: The delayed lints are not hashed as a part of the `OwnerInfo`, and therefore + /// should only be accessed in `eval_always` queries. + #[stable_hasher(ignore)] pub delayed_lints: DelayedLints, } diff --git a/compiler/rustc_hir/src/lints.rs b/compiler/rustc_hir/src/lints.rs index 23eda1a0355e2..5c2ae98eb870f 100644 --- a/compiler/rustc_hir/src/lints.rs +++ b/compiler/rustc_hir/src/lints.rs @@ -1,17 +1,10 @@ -use rustc_data_structures::fingerprint::Fingerprint; use rustc_error_messages::MultiSpan; use rustc_lint_defs::LintId; pub use rustc_lint_defs::{AttributeLintKind, FormatWarning}; -use rustc_macros::HashStable_Generic; use crate::HirId; -#[derive(Debug)] -pub struct DelayedLints { - pub lints: Box<[DelayedLint]>, - // Only present when the crate hash is needed. - pub opt_hash: Option, -} +pub type DelayedLints = Box<[DelayedLint]>; /// During ast lowering, no lints can be emitted. /// That is because lints attach to nodes either in the AST, or on the built HIR. @@ -19,12 +12,12 @@ pub struct DelayedLints { /// and then there's a gap where no lints can be emitted until HIR is done. /// The variants in this enum represent lints that are temporarily stashed during /// AST lowering to be emitted once HIR is built. -#[derive(Debug, HashStable_Generic)] +#[derive(Debug)] pub enum DelayedLint { AttributeParsing(AttributeLint), } -#[derive(Debug, HashStable_Generic)] +#[derive(Debug)] pub struct AttributeLint { pub lint_id: LintId, pub id: Id, diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index f2cfeaf027f3b..3a10f790cd5cc 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -7,7 +7,6 @@ use crate::hir::{ AttributeMap, BodyId, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId, }; use crate::hir_id::ItemLocalId; -use crate::lints::DelayedLints; impl ToStableHashKey for BodyId { type KeyType = (DefPathHash, ItemLocalId); @@ -74,13 +73,6 @@ impl<'tcx, Hcx: HashStableContext> HashStable for OwnerNodes<'tcx> { } } -impl HashStable for DelayedLints { - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { - let DelayedLints { opt_hash, .. } = *self; - opt_hash.unwrap().hash_stable(hcx, hasher); - } -} - impl<'tcx, Hcx: HashStableContext> HashStable for AttributeMap<'tcx> { fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { // We ignore the `map` since it refers to information included in `opt_hash` which is diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 23a055e1e26f4..72d3afd5426f9 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1030,7 +1030,7 @@ pub fn create_and_enter_global_ctxt FnOnce(TyCtxt<'tcx>) -> T>( pub fn emit_delayed_lints(tcx: TyCtxt<'_>) { for owner_id in tcx.hir_crate_items(()).delayed_lint_items() { if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) { - for lint in &delayed_lints.lints { + for lint in delayed_lints { match lint { DelayedLint::AttributeParsing(attribute_lint) => { tcx.emit_node_span_lint( @@ -1113,11 +1113,11 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { { let hir_items = tcx.hir_crate_items(()); for owner_id in hir_items.owners() { - if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) { - if !delayed_lints.lints.is_empty() { - // Assert that delayed_lint_items also picked up this item to have lints. - assert!(hir_items.delayed_lint_items().any(|i| i == owner_id)); - } + if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) + && !delayed_lints.is_empty() + { + // Assert that delayed_lint_items also picked up this item to have lints. + assert!(hir_items.delayed_lint_items().any(|i| i == owner_id)); } } } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 731d3ca426038..cb9fd38c5da57 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -652,7 +652,7 @@ pub enum DeprecatedSinceKind { InVersion(String), } -#[derive(Debug, HashStable_Generic)] +#[derive(Debug)] pub enum AttributeLintKind { UnusedDuplicate { this: Span, diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 814b333cfb0f8..7f82b9161fe61 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -17,7 +17,6 @@ use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; -use rustc_hir::lints::DelayedLint; use rustc_hir::*; use rustc_index::IndexVec; use rustc_macros::{Decodable, Encodable, HashStable}; @@ -236,15 +235,10 @@ impl<'tcx> TyCtxt<'tcx> { node: OwnerNode<'_>, bodies: &SortedMap>, attrs: &SortedMap, - delayed_lints: &[DelayedLint], define_opaque: Option<&[(Span, LocalDefId)]>, ) -> Hashes { if !self.needs_crate_hash() { - return Hashes { - opt_hash_including_bodies: None, - attrs_hash: None, - delayed_lints_hash: None, - }; + return Hashes { opt_hash_including_bodies: None, attrs_hash: None }; } self.with_stable_hashing_context(|mut hcx| { @@ -262,16 +256,7 @@ impl<'tcx> TyCtxt<'tcx> { let h2 = stable_hasher.finish(); - // hash lints emitted during ast lowering - let mut stable_hasher = StableHasher::new(); - delayed_lints.hash_stable(&mut hcx, &mut stable_hasher); - let h3 = stable_hasher.finish(); - - Hashes { - opt_hash_including_bodies: Some(h1), - attrs_hash: Some(h2), - delayed_lints_hash: Some(h3), - } + Hashes { opt_hash_including_bodies: Some(h1), attrs_hash: Some(h2) } }) } @@ -465,7 +450,6 @@ impl<'tcx> TyCtxt<'tcx> { pub struct Hashes { pub opt_hash_including_bodies: Option, pub attrs_hash: Option, - pub delayed_lints_hash: Option, } pub fn provide(providers: &mut Providers) { diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index dd36cbf1b8f6f..7c6ab642b2736 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -276,6 +276,10 @@ rustc_queries! { /// Avoid calling this query directly. query opt_ast_lowering_delayed_lints(key: hir::OwnerId) -> Option<&'tcx hir::lints::DelayedLints> { desc { "getting AST lowering delayed lints in `{}`", tcx.def_path_str(key) } + // This query has to be `no_hash` and `eval_always`, + // because it accesses `delayed_lints` which is not hashed as part of the HIR + no_hash + eval_always } /// Returns the *default* of the const pararameter given by `DefId`. diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index b908a6c6e8439..d50a527576025 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -708,7 +708,7 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> { let attrs = hir::AttributeMap::EMPTY; let rustc_middle::hir::Hashes { opt_hash_including_bodies, .. } = - self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, &[], attrs.define_opaque); + self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque); let node = node.into(); self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes { opt_hash_including_bodies, diff --git a/tests/incremental/hashes/delayed_lints.rs b/tests/incremental/hashes/delayed_lints.rs new file mode 100644 index 0000000000000..eb65a455160e9 --- /dev/null +++ b/tests/incremental/hashes/delayed_lints.rs @@ -0,0 +1,27 @@ +// Some lints are emitted in `rustc_attr_parsing`, during ast lowering. +// Emitting these lints is delayed until after ast lowering. +// This test tests that the delayed hints are correctly hashed for incremental. + +//@ check-pass +//@ revisions: cfail1 cfail2 cfail3 +//@ compile-flags: -Z query-dep-graph -O -Zincremental-ignore-spans +//@ ignore-backends: gcc +#![feature(rustc_attrs)] + +// This attribute is here so the `has_delayed_lints` will be true on all revisions +#[doc(test = 1)] +//~^ WARN `#[doc(test(...)]` takes a list of attributes [invalid_doc_attributes] + +// Between revision 1 and 2, the only thing we change is that we add "test = 2" +// This will emit an extra delayed lint, but it will not change the HIR hash. +// We check that even tho the HIR hash didn't change, the extra lint is emitted +#[cfg_attr(cfail1, doc(hidden))] +#[cfg_attr(not(cfail1), doc(hidden, test = 2))] +//[cfail2,cfail3]~^ WARN `#[doc(test(...)]` takes a list of attributes [invalid_doc_attributes] + +// The HIR hash should not change between revisions, for this test to be representative +#[rustc_clean(cfg="cfail2")] +#[rustc_clean(cfg="cfail3")] +trait Test {} + +fn main() {}