move LintSource to levels
This commit is contained in:
parent
03bdfe9db3
commit
f577b44712
3 changed files with 33 additions and 34 deletions
|
@ -1,8 +1,8 @@
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use crate::ich::StableHashingContext;
|
use crate::ich::StableHashingContext;
|
||||||
|
use crate::lint;
|
||||||
use crate::lint::context::{CheckLintNameResult, LintStore};
|
use crate::lint::context::{CheckLintNameResult, LintStore};
|
||||||
use crate::lint::{self, LintSource};
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
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_session::Session;
|
||||||
use rustc_span::source_map::MultiSpan;
|
use rustc_span::source_map::MultiSpan;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
|
use rustc_span::Span;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
|
@ -18,6 +19,22 @@ use syntax::sess::feature_err;
|
||||||
|
|
||||||
use rustc_error_codes::*;
|
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 {
|
pub struct LintLevelSets {
|
||||||
list: Vec<LintSet>,
|
list: Vec<LintSet>,
|
||||||
lint_cap: Level,
|
lint_cap: Level,
|
||||||
|
@ -27,27 +44,27 @@ enum LintSet {
|
||||||
CommandLine {
|
CommandLine {
|
||||||
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
|
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
|
||||||
// flag.
|
// flag.
|
||||||
specs: FxHashMap<LintId, (Level, LintSource)>,
|
specs: FxHashMap<LintId, LevelSource>,
|
||||||
},
|
},
|
||||||
|
|
||||||
Node {
|
Node {
|
||||||
specs: FxHashMap<LintId, (Level, LintSource)>,
|
specs: FxHashMap<LintId, LevelSource>,
|
||||||
parent: u32,
|
parent: u32,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintLevelSets {
|
impl LintLevelSets {
|
||||||
fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
|
LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_lint_level(
|
pub fn get_lint_level(
|
||||||
&self,
|
&self,
|
||||||
lint: &'static Lint,
|
lint: &'static Lint,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
|
aux: Option<&FxHashMap<LintId, LevelSource>>,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
) -> (Level, LintSource) {
|
) -> LevelSource {
|
||||||
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
|
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
|
// 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.
|
// `allow(warnings)` in scope then we want to respect that instead.
|
||||||
if level == Level::Warn {
|
if level == Level::Warn {
|
||||||
let (warnings_level, warnings_src) =
|
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 let Some(configured_warning_level) = warnings_level {
|
||||||
if configured_warning_level != Level::Warn {
|
if configured_warning_level != Level::Warn {
|
||||||
level = configured_warning_level;
|
level = configured_warning_level;
|
||||||
|
@ -79,11 +96,11 @@ impl LintLevelSets {
|
||||||
return (level, src);
|
return (level, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_lint_id_level(
|
pub fn get_lint_id_level(
|
||||||
&self,
|
&self,
|
||||||
id: LintId,
|
id: LintId,
|
||||||
mut idx: u32,
|
mut idx: u32,
|
||||||
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
|
aux: Option<&FxHashMap<LintId, LevelSource>>,
|
||||||
) -> (Option<Level>, LintSource) {
|
) -> (Option<Level>, LintSource) {
|
||||||
if let Some(specs) = aux {
|
if let Some(specs) = aux {
|
||||||
if let Some(&(level, src)) = specs.get(&id) {
|
if let Some(&(level, src)) = specs.get(&id) {
|
||||||
|
@ -499,7 +516,7 @@ impl LintLevelMap {
|
||||||
lint: &'static Lint,
|
lint: &'static Lint,
|
||||||
id: HirId,
|
id: HirId,
|
||||||
session: &Session,
|
session: &Session,
|
||||||
) -> Option<(Level, LintSource)> {
|
) -> Option<LevelSource> {
|
||||||
self.id_to_set.get(&id).map(|idx| self.sets.get_lint_level(lint, *idx, None, session))
|
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`
|
//! example) requires more effort. See `emit_lint` and `GatherNodeLevels`
|
||||||
//! in `context.rs`.
|
//! in `context.rs`.
|
||||||
|
|
||||||
|
pub use self::levels::LintSource::{self, *};
|
||||||
pub use self::Level::*;
|
pub use self::Level::*;
|
||||||
pub use self::LintSource::*;
|
|
||||||
|
|
||||||
use crate::ty::TyCtxt;
|
use crate::ty::TyCtxt;
|
||||||
use rustc_data_structures::sync;
|
use rustc_data_structures::sync;
|
||||||
|
@ -29,7 +29,6 @@ use rustc_session::lint::builtin::HardwiredLints;
|
||||||
use rustc_session::{DiagnosticMessageId, Session};
|
use rustc_session::{DiagnosticMessageId, Session};
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
|
use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
|
||||||
use rustc_span::symbol::Symbol;
|
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
|
||||||
|
@ -38,9 +37,8 @@ pub use crate::lint::context::{
|
||||||
LintContext, LintStore,
|
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::{BufferedEarlyLint, FutureIncompatibleInfo, Level, Lint, LintId};
|
||||||
pub use rustc_session::lint::{LintArray, LintPass};
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! late_lint_methods {
|
macro_rules! late_lint_methods {
|
||||||
|
@ -316,22 +314,6 @@ pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + sync::Sync +
|
||||||
pub type LateLintPassObject =
|
pub type LateLintPassObject =
|
||||||
Box<dyn for<'a, 'tcx> LateLintPass<'a, 'tcx> + sync::Send + sync::Sync + 'static>;
|
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;
|
mod context;
|
||||||
pub mod internal;
|
pub mod internal;
|
||||||
mod levels;
|
mod levels;
|
||||||
|
|
|
@ -20,9 +20,6 @@ use crate::mir::interpret::{Allocation, ConstValue, Scalar};
|
||||||
use crate::mir::{
|
use crate::mir::{
|
||||||
interpret, BodyAndCache, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
|
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;
|
||||||
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
|
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
|
||||||
use crate::ty::free_region_map::FreeRegionMap;
|
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::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
|
||||||
use rustc_hir::{HirId, Node, TraitCandidate};
|
use rustc_hir::{HirId, Node, TraitCandidate};
|
||||||
use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet};
|
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 arena::SyncDroplessArena;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue