Skip to content

Commit f577b44

Browse files
committed
move LintSource to levels
1 parent 03bdfe9 commit f577b44

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

src/librustc/lint/levels.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::cmp;
22

33
use crate::ich::StableHashingContext;
4+
use crate::lint;
45
use crate::lint::context::{CheckLintNameResult, LintStore};
5-
use crate::lint::{self, LintSource};
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
88
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
@@ -11,13 +11,30 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
1111
use rustc_session::Session;
1212
use rustc_span::source_map::MultiSpan;
1313
use rustc_span::symbol::{sym, Symbol};
14+
use rustc_span::Span;
1415
use syntax::ast;
1516
use syntax::attr;
1617
use syntax::print::pprust;
1718
use syntax::sess::feature_err;
1819

1920
use rustc_error_codes::*;
2021

22+
/// How a lint level was set.
23+
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
24+
pub enum LintSource {
25+
/// Lint is at the default level as declared
26+
/// in rustc or a plugin.
27+
Default,
28+
29+
/// Lint level was set by an attribute.
30+
Node(Symbol, Span, Option<Symbol> /* RFC 2383 reason */),
31+
32+
/// Lint level was set by a command-line flag.
33+
CommandLine(Symbol),
34+
}
35+
36+
pub type LevelSource = (Level, LintSource);
37+
2138
pub struct LintLevelSets {
2239
list: Vec<LintSet>,
2340
lint_cap: Level,
@@ -27,27 +44,27 @@ enum LintSet {
2744
CommandLine {
2845
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
2946
// flag.
30-
specs: FxHashMap<LintId, (Level, LintSource)>,
47+
specs: FxHashMap<LintId, LevelSource>,
3148
},
3249

3350
Node {
34-
specs: FxHashMap<LintId, (Level, LintSource)>,
51+
specs: FxHashMap<LintId, LevelSource>,
3552
parent: u32,
3653
},
3754
}
3855

3956
impl LintLevelSets {
40-
fn new() -> Self {
57+
pub fn new() -> Self {
4158
LintLevelSets { list: Vec::new(), lint_cap: Level::Forbid }
4259
}
4360

44-
fn get_lint_level(
61+
pub fn get_lint_level(
4562
&self,
4663
lint: &'static Lint,
4764
idx: u32,
48-
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
65+
aux: Option<&FxHashMap<LintId, LevelSource>>,
4966
sess: &Session,
50-
) -> (Level, LintSource) {
67+
) -> LevelSource {
5168
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
5269

5370
// If `level` is none then we actually assume the default level for this
@@ -59,7 +76,7 @@ impl LintLevelSets {
5976
// `allow(warnings)` in scope then we want to respect that instead.
6077
if level == Level::Warn {
6178
let (warnings_level, warnings_src) =
62-
self.get_lint_id_level(LintId::of(lint::builtin::WARNINGS), idx, aux);
79+
self.get_lint_id_level(LintId::of(builtin::WARNINGS), idx, aux);
6380
if let Some(configured_warning_level) = warnings_level {
6481
if configured_warning_level != Level::Warn {
6582
level = configured_warning_level;
@@ -79,11 +96,11 @@ impl LintLevelSets {
7996
return (level, src);
8097
}
8198

82-
fn get_lint_id_level(
99+
pub fn get_lint_id_level(
83100
&self,
84101
id: LintId,
85102
mut idx: u32,
86-
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
103+
aux: Option<&FxHashMap<LintId, LevelSource>>,
87104
) -> (Option<Level>, LintSource) {
88105
if let Some(specs) = aux {
89106
if let Some(&(level, src)) = specs.get(&id) {
@@ -499,7 +516,7 @@ impl LintLevelMap {
499516
lint: &'static Lint,
500517
id: HirId,
501518
session: &Session,
502-
) -> Option<(Level, LintSource)> {
519+
) -> Option<LevelSource> {
503520
self.id_to_set.get(&id).map(|idx| self.sets.get_lint_level(lint, *idx, None, session))
504521
}
505522
}

src/librustc/lint/mod.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
//! example) requires more effort. See `emit_lint` and `GatherNodeLevels`
1919
//! in `context.rs`.
2020
21+
pub use self::levels::LintSource::{self, *};
2122
pub use self::Level::*;
22-
pub use self::LintSource::*;
2323

2424
use crate::ty::TyCtxt;
2525
use rustc_data_structures::sync;
@@ -29,7 +29,6 @@ use rustc_session::lint::builtin::HardwiredLints;
2929
use rustc_session::{DiagnosticMessageId, Session};
3030
use rustc_span::hygiene::MacroKind;
3131
use rustc_span::source_map::{DesugaringKind, ExpnKind, MultiSpan};
32-
use rustc_span::symbol::Symbol;
3332
use rustc_span::Span;
3433
use syntax::ast;
3534

@@ -38,9 +37,8 @@ pub use crate::lint::context::{
3837
LintContext, LintStore,
3938
};
4039

41-
pub use rustc_session::lint::builtin;
40+
pub use rustc_session::lint::{builtin, LintArray, LintPass};
4241
pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Level, Lint, LintId};
43-
pub use rustc_session::lint::{LintArray, LintPass};
4442

4543
#[macro_export]
4644
macro_rules! late_lint_methods {
@@ -316,22 +314,6 @@ pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + sync::Sync +
316314
pub type LateLintPassObject =
317315
Box<dyn for<'a, 'tcx> LateLintPass<'a, 'tcx> + sync::Send + sync::Sync + 'static>;
318316

319-
/// How a lint level was set.
320-
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
321-
pub enum LintSource {
322-
/// Lint is at the default level as declared
323-
/// in rustc or a plugin.
324-
Default,
325-
326-
/// Lint level was set by an attribute.
327-
Node(ast::Name, Span, Option<Symbol> /* RFC 2383 reason */),
328-
329-
/// Lint level was set by a command-line flag.
330-
CommandLine(Symbol),
331-
}
332-
333-
pub type LevelSource = (Level, LintSource);
334-
335317
mod context;
336318
pub mod internal;
337319
mod levels;

src/librustc/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ use crate::mir::interpret::{Allocation, ConstValue, Scalar};
2020
use crate::mir::{
2121
interpret, BodyAndCache, Field, Local, Place, PlaceElem, ProjectionKind, Promoted,
2222
};
23-
use crate::session::config::CrateType;
24-
use crate::session::config::{BorrowckMode, OutputFilenames};
25-
use crate::session::Session;
2623
use crate::traits;
2724
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
2825
use crate::ty::free_region_map::FreeRegionMap;
@@ -49,6 +46,9 @@ use rustc_hir::def::{DefKind, Res};
4946
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
5047
use rustc_hir::{HirId, Node, TraitCandidate};
5148
use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet};
49+
use rustc_session::config::CrateType;
50+
use rustc_session::config::{BorrowckMode, OutputFilenames};
51+
use rustc_session::Session;
5252

5353
use arena::SyncDroplessArena;
5454
use rustc_data_structures::fx::{FxHashMap, FxHashSet};

0 commit comments

Comments
 (0)