Skip to content

Commit 526ee51

Browse files
Move Lint to rustc_session
This commit breaks early-lint registration, which will be fixed in the next commit. This movement will allow essentially all crates in the compiler tree to declare lints (though not lint passes).
1 parent 433e546 commit 526ee51

File tree

4 files changed

+75
-87
lines changed

4 files changed

+75
-87
lines changed

src/librustc/lint/levels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl LintLevelSets {
9393

9494
// If `level` is none then we actually assume the default level for this
9595
// lint.
96-
let mut level = level.unwrap_or_else(|| lint.default_level(sess));
96+
let mut level = level.unwrap_or_else(|| lint.default_level(sess.edition()));
9797

9898
// If we're about to issue a warning, check at the last minute for any
9999
// directives against the warnings "lint". If, for example, there's an

src/librustc/lint/mod.rs

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
2727
use crate::hir::intravisit;
2828
use crate::hir;
2929
use crate::lint::builtin::BuiltinLintDiagnostics;
30-
use crate::lint::builtin::parser::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE};
31-
use crate::lint::builtin::parser::INCOMPLETE_INCLUDE;
3230
use crate::session::{Session, DiagnosticMessageId};
3331
use crate::ty::TyCtxt;
3432
use crate::ty::query::Providers;
@@ -37,8 +35,6 @@ use errors::{DiagnosticBuilder, DiagnosticId};
3735
use std::{hash, ptr};
3836
use syntax::ast;
3937
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
40-
use syntax::early_buffered_lints::BufferedEarlyLintId;
41-
use syntax::edition::Edition;
4238
use syntax::symbol::Symbol;
4339
use syntax_pos::hygiene::MacroKind;
4440
use syntax_pos::Span;
@@ -47,87 +43,7 @@ pub use crate::lint::context::{LateContext, EarlyContext, LintContext, LintStore
4743
check_crate, check_ast_crate, late_lint_mod, CheckLintNameResult,
4844
BufferedEarlyLint,};
4945

50-
pub use rustc_session::lint::Level;
51-
52-
/// Specification of a single lint.
53-
#[derive(Copy, Clone, Debug)]
54-
pub struct Lint {
55-
/// A string identifier for the lint.
56-
///
57-
/// This identifies the lint in attributes and in command-line arguments.
58-
/// In those contexts it is always lowercase, but this field is compared
59-
/// in a way which is case-insensitive for ASCII characters. This allows
60-
/// `declare_lint!()` invocations to follow the convention of upper-case
61-
/// statics without repeating the name.
62-
///
63-
/// The name is written with underscores, e.g., "unused_imports".
64-
/// On the command line, underscores become dashes.
65-
pub name: &'static str,
66-
67-
/// Default level for the lint.
68-
pub default_level: Level,
69-
70-
/// Description of the lint or the issue it detects.
71-
///
72-
/// e.g., "imports that are never used"
73-
pub desc: &'static str,
74-
75-
/// Starting at the given edition, default to the given lint level. If this is `None`, then use
76-
/// `default_level`.
77-
pub edition_lint_opts: Option<(Edition, Level)>,
78-
79-
/// `true` if this lint is reported even inside expansions of external macros.
80-
pub report_in_external_macro: bool,
81-
82-
pub future_incompatible: Option<FutureIncompatibleInfo>,
83-
84-
pub is_plugin: bool,
85-
}
86-
87-
/// Extra information for a future incompatibility lint.
88-
#[derive(Copy, Clone, Debug)]
89-
pub struct FutureIncompatibleInfo {
90-
/// e.g., a URL for an issue/PR/RFC or error code
91-
pub reference: &'static str,
92-
/// If this is an edition fixing lint, the edition in which
93-
/// this lint becomes obsolete
94-
pub edition: Option<Edition>,
95-
}
96-
97-
impl Lint {
98-
pub const fn default_fields_for_macro() -> Self {
99-
Lint {
100-
name: "",
101-
default_level: Level::Forbid,
102-
desc: "",
103-
edition_lint_opts: None,
104-
is_plugin: false,
105-
report_in_external_macro: false,
106-
future_incompatible: None,
107-
}
108-
}
109-
110-
/// Returns the `rust::lint::Lint` for a `syntax::early_buffered_lints::BufferedEarlyLintId`.
111-
pub fn from_parser_lint_id(lint_id: BufferedEarlyLintId) -> &'static Self {
112-
match lint_id {
113-
BufferedEarlyLintId::IllFormedAttributeInput => ILL_FORMED_ATTRIBUTE_INPUT,
114-
BufferedEarlyLintId::MetaVariableMisuse => META_VARIABLE_MISUSE,
115-
BufferedEarlyLintId::IncompleteInclude => INCOMPLETE_INCLUDE,
116-
}
117-
}
118-
119-
/// Gets the lint's name, with ASCII letters converted to lowercase.
120-
pub fn name_lower(&self) -> String {
121-
self.name.to_ascii_lowercase()
122-
}
123-
124-
pub fn default_level(&self, session: &Session) -> Level {
125-
self.edition_lint_opts
126-
.filter(|(e, _)| *e <= session.edition())
127-
.map(|(_, l)| l)
128-
.unwrap_or(self.default_level)
129-
}
130-
}
46+
pub use rustc_session::lint::{Lint, Level, FutureIncompatibleInfo};
13147

13248
/// Declares a static item of type `&'static Lint`.
13349
#[macro_export]

src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_session::cgu_reuse_tracker::CguReuseTracker;
55
use rustc_data_structures::fingerprint::Fingerprint;
66
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77

8-
use crate::lint;
8+
use rustc_session::lint;
99
use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
1010
use crate::session::search_paths::{PathKind, SearchPath};
1111
use crate::util::common::{duration_to_secs_str, ErrorReported};

src/librustc_session/lint.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use syntax_pos::{Symbol, sym};
2+
use syntax_pos::edition::Edition;
23
pub use self::Level::*;
34

45
/// Setting for how to handle a lint.
@@ -42,3 +43,74 @@ impl Level {
4243
}
4344
}
4445
}
46+
47+
/// Specification of a single lint.
48+
#[derive(Copy, Clone, Debug)]
49+
pub struct Lint {
50+
/// A string identifier for the lint.
51+
///
52+
/// This identifies the lint in attributes and in command-line arguments.
53+
/// In those contexts it is always lowercase, but this field is compared
54+
/// in a way which is case-insensitive for ASCII characters. This allows
55+
/// `declare_lint!()` invocations to follow the convention of upper-case
56+
/// statics without repeating the name.
57+
///
58+
/// The name is written with underscores, e.g., "unused_imports".
59+
/// On the command line, underscores become dashes.
60+
pub name: &'static str,
61+
62+
/// Default level for the lint.
63+
pub default_level: Level,
64+
65+
/// Description of the lint or the issue it detects.
66+
///
67+
/// e.g., "imports that are never used"
68+
pub desc: &'static str,
69+
70+
/// Starting at the given edition, default to the given lint level. If this is `None`, then use
71+
/// `default_level`.
72+
pub edition_lint_opts: Option<(Edition, Level)>,
73+
74+
/// `true` if this lint is reported even inside expansions of external macros.
75+
pub report_in_external_macro: bool,
76+
77+
pub future_incompatible: Option<FutureIncompatibleInfo>,
78+
79+
pub is_plugin: bool,
80+
}
81+
82+
/// Extra information for a future incompatibility lint.
83+
#[derive(Copy, Clone, Debug)]
84+
pub struct FutureIncompatibleInfo {
85+
/// e.g., a URL for an issue/PR/RFC or error code
86+
pub reference: &'static str,
87+
/// If this is an edition fixing lint, the edition in which
88+
/// this lint becomes obsolete
89+
pub edition: Option<Edition>,
90+
}
91+
92+
impl Lint {
93+
pub const fn default_fields_for_macro() -> Self {
94+
Lint {
95+
name: "",
96+
default_level: Level::Forbid,
97+
desc: "",
98+
edition_lint_opts: None,
99+
is_plugin: false,
100+
report_in_external_macro: false,
101+
future_incompatible: None,
102+
}
103+
}
104+
105+
/// Gets the lint's name, with ASCII letters converted to lowercase.
106+
pub fn name_lower(&self) -> String {
107+
self.name.to_ascii_lowercase()
108+
}
109+
110+
pub fn default_level(&self, edition: Edition) -> Level {
111+
self.edition_lint_opts
112+
.filter(|(e, _)| *e <= edition)
113+
.map(|(_, l)| l)
114+
.unwrap_or(self.default_level)
115+
}
116+
}

0 commit comments

Comments
 (0)