mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-14 21:16:50 +00:00
move LintSource to levels
This commit is contained in:
parent
03bdfe9db3
commit
f577b44712
@ -1,8 +1,8 @@
|
||||
use std::cmp;
|
||||
|
||||
use crate::ich::StableHashingContext;
|
||||
use crate::lint;
|
||||
use crate::lint::context::{CheckLintNameResult, LintStore};
|
||||
use crate::lint::{self, LintSource};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
||||
@ -11,6 +11,7 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::source_map::MultiSpan;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::print::pprust;
|
||||
@ -18,6 +19,22 @@ use syntax::sess::feature_err;
|
||||
|
||||
use rustc_error_codes::*;
|
||||
|
||||
/// How a lint level was set.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
|
||||
pub enum LintSource {
|
||||
/// Lint is at the default level as declared
|
||||
/// in rustc or a plugin.
|
||||
Default,
|
||||
|
||||
/// Lint level was set by an attribute.
|
||||
Node(Symbol, Span, Option<Symbol> /* RFC 2383 reason */),
|
||||
|
||||
/// Lint level was set by a command-line flag.
|
||||
CommandLine(Symbol),
|
||||
}
|
||||
|
||||
pub type LevelSource = (Level, LintSource);
|
||||
|
||||
pub struct LintLevelSets {
|
||||
list: Vec<LintSet>,
|
||||
lint_cap: Level,
|
||||
@ -27,27 +44,27 @@ enum LintSet {
|
||||
CommandLine {
|
||||
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
|
||||
// flag.
|
||||
specs: FxHashMap<LintId, (Level, LintSource)>,
|
||||
specs: FxHashMap<LintId, LevelSource>,
|
||||
},
|
||||
|
||||
Node {
|
||||
specs: FxHashMap<LintId, (Level, LintSource)>,
|
||||
specs: FxHashMap<LintId, LevelSource>,
|
||||
parent: u32,
|
||||
},
|
||||
}
|
||||
|
||||
impl LintLevelSets {
|
||||
fn new() -> Self {
|
||||
pub fn new() -> Self {
|
||||
LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
|
||||
}
|
||||
|
||||
fn get_lint_level(
|
||||
pub fn get_lint_level(
|
||||
&self,
|
||||
lint: &'static Lint,
|
||||
idx: u32,
|
||||
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
|
||||
aux: Option<&FxHashMap<LintId, LevelSource>>,
|
||||
sess: &Session,
|
||||
) -> (Level, LintSource) {
|
||||
) -> LevelSource {
|
||||
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
|
||||
|
||||
// If `level` is none then we actually assume the default level for this
|
||||
@ -59,7 +76,7 @@ impl LintLevelSets {
|
||||
// `allow(warnings)` in scope then we want to respect that instead.
|
||||
if level == Level::Warn {
|
||||
let (warnings_level, warnings_src) =
|
||||
self.get_lint_id_level(LintId::of(lint::builtin::WARNINGS), idx, aux);
|
||||
self.get_lint_id_level(LintId::of(builtin::WARNINGS), idx, aux);
|
||||
if let Some(configured_warning_level) = warnings_level {
|
||||
if configured_warning_level != Level::Warn {
|
||||
level = configured_warning_level;
|
||||
@ -79,11 +96,11 @@ impl LintLevelSets {
|
||||
return (level, src);
|
||||
}
|
||||
|
||||
fn get_lint_id_level(
|
||||
pub fn get_lint_id_level(
|
||||
&self,
|
||||
id: LintId,
|
||||
mut idx: u32,
|
||||
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
|
||||
aux: Option<&FxHashMap<LintId, LevelSource>>,
|
||||
) -> (Option<Level>, LintSource) {
|
||||
if let Some(specs) = aux {
|
||||
if let Some(&(level, src)) = specs.get(&id) {
|
||||
@ -499,7 +516,7 @@ impl LintLevelMap {
|
||||
lint: &'static Lint,
|
||||
id: HirId,
|
||||
session: &Session,
|
||||
) -> Option<(Level, LintSource)> {
|
||||
) -> Option<LevelSource> {
|
||||
self.id_to_set.get(&id).map(|idx| self.sets.get_lint_level(lint, *idx, None, session))
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@
|
||||
//! example) requires more effort. See `emit_lint` and `GatherNodeLevels`
|
||||
//! in `context.rs`.
|
||||
|
||||
pub use self::levels::LintSource::{self, *};
|
||||
pub use self::Level::*;
|
||||
pub use self::LintSource::*;
|
||||
|
||||
use crate::ty::TyCtxt;
|
||||
use rustc_data_structures::sync;
|
||||
@ -29,7 +29,6 @@ use rustc_session::lint::builtin::HardwiredLints;
|
||||
use rustc_session::{DiagnosticMessageId, Session};
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
use syntax::ast;
|
||||
|
||||
@ -38,9 +37,8 @@ pub use crate::lint::context::{
|
||||
LintContext, LintStore,
|
||||
};
|
||||
|
||||
pub use rustc_session::lint::builtin;
|
||||
pub use rustc_session::lint::{builtin, LintArray, LintPass};
|
||||
pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Level, Lint, LintId};
|
||||
pub use rustc_session::lint::{LintArray, LintPass};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! late_lint_methods {
|
||||
@ -316,22 +314,6 @@ pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + sync::Sync +
|
||||
pub type LateLintPassObject =
|
||||
Box<dyn for<'a, 'tcx> LateLintPass<'a, 'tcx> + sync::Send + sync::Sync + 'static>;
|
||||
|
||||
/// How a lint level was set.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
|
||||
pub enum LintSource {
|
||||
/// Lint is at the default level as declared
|
||||
/// in rustc or a plugin.
|
||||
Default,
|
||||
|
||||
/// Lint level was set by an attribute.
|
||||
Node(ast::Name, Span, Option<Symbol> /* RFC 2383 reason */),
|
||||
|
||||
/// Lint level was set by a command-line flag.
|
||||
CommandLine(Symbol),
|
||||
}
|
||||
|
||||
pub type LevelSource = (Level, LintSource);
|
||||
|
||||
mod context;
|
||||
pub mod internal;
|
||||
mod levels;
|
||||
|
@ -20,9 +20,6 @@ use crate::mir::interpret::{Allocation, ConstValue, Scalar};
|
||||
use crate::mir::{
|
||||
interpret, BodyAndCache, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
|
||||
};
|
||||
use crate::session::config::CrateType;
|
||||
use crate::session::config::{BorrowckMode, OutputFilenames};
|
||||
use crate::session::Session;
|
||||
use crate::traits;
|
||||
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
|
||||
use crate::ty::free_region_map::FreeRegionMap;
|
||||
@ -49,6 +46,9 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
|
||||
use rustc_hir::{HirId, Node, TraitCandidate};
|
||||
use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet};
|
||||
use rustc_session::config::CrateType;
|
||||
use rustc_session::config::{BorrowckMode, OutputFilenames};
|
||||
use rustc_session::Session;
|
||||
|
||||
use arena::SyncDroplessArena;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
|
Loading…
Reference in New Issue
Block a user