introduce new lint infra
lint on duplicates during attribute parsing To do this we stuff them in the diagnostic context to be emitted after hir is constructed
This commit is contained in:
@@ -34,6 +34,7 @@ use crate::def::{CtorKind, DefKind, PerNS, Res};
|
||||
use crate::def_id::{DefId, LocalDefIdMap};
|
||||
pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId};
|
||||
use crate::intravisit::{FnKind, VisitorExt};
|
||||
use crate::lints::DelayedLints;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
|
||||
pub enum AngleBrackets {
|
||||
@@ -1526,6 +1527,10 @@ pub struct OwnerInfo<'hir> {
|
||||
/// Map indicating what traits are in scope for places where this
|
||||
/// is relevant; generated by resolve.
|
||||
pub trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
|
||||
|
||||
/// Lints delayed during ast lowering to be emitted
|
||||
/// after hir has completely built
|
||||
pub delayed_lints: DelayedLints,
|
||||
}
|
||||
|
||||
impl<'tcx> OwnerInfo<'tcx> {
|
||||
|
||||
@@ -27,6 +27,7 @@ mod hir;
|
||||
pub mod hir_id;
|
||||
pub mod intravisit;
|
||||
pub mod lang_items;
|
||||
pub mod lints;
|
||||
pub mod pat_util;
|
||||
mod stable_hash_impls;
|
||||
mod target;
|
||||
|
||||
23
compiler/rustc_hir/src/lints.rs
Normal file
23
compiler/rustc_hir/src/lints.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use rustc_attr_data_structures::lints::AttributeLint;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
|
||||
use crate::HirId;
|
||||
|
||||
/// During ast lowering, no lints can be emitted.
|
||||
/// That is because lints attach to nodes either in the AST, or on the built HIR.
|
||||
/// When attached to AST nodes, they're emitted just before building HIR,
|
||||
/// 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(Clone, Debug, HashStable_Generic)]
|
||||
pub enum DelayedLint {
|
||||
AttributeParsing(AttributeLint<HirId>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DelayedLints {
|
||||
pub lints: Box<[DelayedLint]>,
|
||||
// Only present when the crate hash is needed.
|
||||
pub opt_hash: Option<Fingerprint>,
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use crate::hir::{
|
||||
AttributeMap, BodyId, Crate, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
|
||||
};
|
||||
use crate::hir_id::{HirId, ItemLocalId};
|
||||
use crate::lints::DelayedLints;
|
||||
|
||||
/// Requirements for a `StableHashingContext` to be used in this crate.
|
||||
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
||||
@@ -102,6 +103,13 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'
|
||||
}
|
||||
}
|
||||
|
||||
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DelayedLints {
|
||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||
let DelayedLints { opt_hash, .. } = *self;
|
||||
opt_hash.unwrap().hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
|
||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||
// We ignore the `map` since it refers to information included in `opt_hash` which is
|
||||
|
||||
Reference in New Issue
Block a user