Skip to content

Commit f03d8f3

Browse files
Move early lint declarations to librustc_session
1 parent 526ee51 commit f03d8f3

File tree

18 files changed

+172
-171
lines changed

18 files changed

+172
-171
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,7 @@ dependencies = [
37003700
"rustc_error_codes",
37013701
"rustc_feature",
37023702
"rustc_index",
3703+
"rustc_session",
37033704
"rustc_target",
37043705
"syntax",
37053706
"syntax_pos",
@@ -4477,6 +4478,7 @@ dependencies = [
44774478
"rustc_index",
44784479
"rustc_lexer",
44794480
"rustc_macros",
4481+
"rustc_session",
44804482
"scoped-tls",
44814483
"serialize",
44824484
"smallvec 1.0.0",

src/librustc/lint/builtin.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use syntax::ast;
1212
use syntax::edition::Edition;
1313
use syntax::source_map::Span;
1414
use syntax::symbol::Symbol;
15+
use syntax::early_buffered_lints::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE};
16+
use rustc_session::declare_lint;
1517

1618
declare_lint! {
1719
pub EXCEEDING_BITSHIFTS,
@@ -404,31 +406,6 @@ declare_lint! {
404406
};
405407
}
406408

407-
/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`.
408-
pub mod parser {
409-
declare_lint! {
410-
pub ILL_FORMED_ATTRIBUTE_INPUT,
411-
Deny,
412-
"ill-formed attribute inputs that were previously accepted and used in practice",
413-
@future_incompatible = super::FutureIncompatibleInfo {
414-
reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
415-
edition: None,
416-
};
417-
}
418-
419-
declare_lint! {
420-
pub META_VARIABLE_MISUSE,
421-
Allow,
422-
"possible meta-variable misuse at macro definition"
423-
}
424-
425-
declare_lint! {
426-
pub INCOMPLETE_INCLUDE,
427-
Deny,
428-
"trailing content in included file"
429-
}
430-
}
431-
432409
declare_lint! {
433410
pub DEPRECATED_IN_FUTURE,
434411
Allow,
@@ -520,8 +497,8 @@ declare_lint_pass! {
520497
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
521498
MACRO_USE_EXTERN_CRATE,
522499
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
523-
parser::ILL_FORMED_ATTRIBUTE_INPUT,
524-
parser::META_VARIABLE_MISUSE,
500+
ILL_FORMED_ATTRIBUTE_INPUT,
501+
META_VARIABLE_MISUSE,
525502
DEPRECATED_IN_FUTURE,
526503
AMBIGUOUS_ASSOCIATED_ITEMS,
527504
MUTABLE_BORROW_RESERVATION_CONFLICT,

src/librustc/lint/internal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use errors::Applicability;
99
use rustc_data_structures::fx::FxHashMap;
1010
use syntax::ast::{Ident, Item, ItemKind};
1111
use syntax::symbol::{sym, Symbol};
12+
use rustc_session::declare_tool_lint;
1213

1314
declare_tool_lint! {
1415
pub rustc::DEFAULT_HASH_TYPES,

src/librustc/lint/levels.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::lint::{self, Lint, LintId, Level, LintSource};
88
use crate::session::Session;
99
use crate::util::nodemap::FxHashMap;
1010
use errors::{Applicability, DiagnosticBuilder};
11-
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
11+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use syntax::ast;
1313
use syntax::attr;
1414
use syntax::feature_gate;
@@ -566,19 +566,3 @@ impl<'a> HashStable<StableHashingContext<'a>> for LintLevelMap {
566566
})
567567
}
568568
}
569-
570-
impl<HCX> HashStable<HCX> for LintId {
571-
#[inline]
572-
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
573-
self.lint_name_raw().hash_stable(hcx, hasher);
574-
}
575-
}
576-
577-
impl<HCX> ToStableHashKey<HCX> for LintId {
578-
type KeyType = &'static str;
579-
580-
#[inline]
581-
fn to_stable_hash_key(&self, _: &HCX) -> &'static str {
582-
self.lint_name_raw()
583-
}
584-
}

src/librustc/lint/mod.rs

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use crate::ty::TyCtxt;
3232
use crate::ty::query::Providers;
3333
use crate::util::nodemap::NodeMap;
3434
use errors::{DiagnosticBuilder, DiagnosticId};
35-
use std::{hash, ptr};
3635
use syntax::ast;
3736
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
3837
use syntax::symbol::Symbol;
@@ -43,72 +42,7 @@ pub use crate::lint::context::{LateContext, EarlyContext, LintContext, LintStore
4342
check_crate, check_ast_crate, late_lint_mod, CheckLintNameResult,
4443
BufferedEarlyLint,};
4544

46-
pub use rustc_session::lint::{Lint, Level, FutureIncompatibleInfo};
47-
48-
/// Declares a static item of type `&'static Lint`.
49-
#[macro_export]
50-
macro_rules! declare_lint {
51-
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
52-
declare_lint!(
53-
$vis $NAME, $Level, $desc,
54-
);
55-
);
56-
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
57-
$(@future_incompatible = $fi:expr;)? $($v:ident),*) => (
58-
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
59-
name: stringify!($NAME),
60-
default_level: $crate::lint::$Level,
61-
desc: $desc,
62-
edition_lint_opts: None,
63-
is_plugin: false,
64-
$($v: true,)*
65-
$(future_incompatible: Some($fi),)*
66-
..$crate::lint::Lint::default_fields_for_macro()
67-
};
68-
);
69-
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
70-
$lint_edition: expr => $edition_level: ident
71-
) => (
72-
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
73-
name: stringify!($NAME),
74-
default_level: $crate::lint::$Level,
75-
desc: $desc,
76-
edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)),
77-
report_in_external_macro: false,
78-
is_plugin: false,
79-
};
80-
);
81-
}
82-
83-
#[macro_export]
84-
macro_rules! declare_tool_lint {
85-
(
86-
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
87-
) => (
88-
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
89-
);
90-
(
91-
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
92-
report_in_external_macro: $rep:expr
93-
) => (
94-
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
95-
);
96-
(
97-
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
98-
$external:expr
99-
) => (
100-
$(#[$attr])*
101-
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
102-
name: &concat!(stringify!($tool), "::", stringify!($NAME)),
103-
default_level: $crate::lint::$Level,
104-
desc: $desc,
105-
edition_lint_opts: None,
106-
report_in_external_macro: $external,
107-
future_incompatible: None,
108-
is_plugin: true,
109-
};
110-
);
111-
}
45+
pub use rustc_session::lint::{Lint, LintId, Level, FutureIncompatibleInfo};
11246

11347
/// Declares a static `LintArray` and return it as an expression.
11448
#[macro_export]
@@ -420,46 +354,6 @@ pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + sync::Sync +
420354
pub type LateLintPassObject = Box<dyn for<'a, 'tcx> LateLintPass<'a, 'tcx> + sync::Send
421355
+ sync::Sync + 'static>;
422356

423-
/// Identifies a lint known to the compiler.
424-
#[derive(Clone, Copy, Debug)]
425-
pub struct LintId {
426-
// Identity is based on pointer equality of this field.
427-
lint: &'static Lint,
428-
}
429-
430-
impl PartialEq for LintId {
431-
fn eq(&self, other: &LintId) -> bool {
432-
ptr::eq(self.lint, other.lint)
433-
}
434-
}
435-
436-
impl Eq for LintId { }
437-
438-
impl hash::Hash for LintId {
439-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
440-
let ptr = self.lint as *const Lint;
441-
ptr.hash(state);
442-
}
443-
}
444-
445-
impl LintId {
446-
/// Gets the `LintId` for a `Lint`.
447-
pub fn of(lint: &'static Lint) -> LintId {
448-
LintId {
449-
lint,
450-
}
451-
}
452-
453-
pub fn lint_name_raw(&self) -> &'static str {
454-
self.lint.name
455-
}
456-
457-
/// Gets the name of the lint.
458-
pub fn to_string(&self) -> String {
459-
self.lint.name_lower()
460-
}
461-
}
462-
463357
/// How a lint level was set.
464358
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
465359
pub enum LintSource {

src/librustc/session/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Contains infrastructure for configuring the compiler, including parsing
22
//! command-line options.
33
4-
use crate::lint;
4+
use rustc_session::lint;
55
use crate::middle::cstore;
66
use crate::session::{early_error, early_warn, Session};
77
use crate::session::search_paths::SearchPath;
@@ -2854,7 +2854,7 @@ impl PpMode {
28542854
/// we have an opt-in scheme here, so one is hopefully forced to think about
28552855
/// how the hash should be calculated when adding a new command-line argument.
28562856
mod dep_tracking {
2857-
use crate::lint;
2857+
use rustc_session::lint;
28582858
use crate::middle::cstore;
28592859
use std::collections::BTreeMap;
28602860
use std::hash::Hash;

src/librustc_driver/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ Available lint options:
828828

829829
fn sort_lints(sess: &Session, mut lints: Vec<&'static Lint>) -> Vec<&'static Lint> {
830830
// The sort doesn't case-fold but it's doubtful we care.
831-
lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess), x.name));
831+
lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess.edition()), x.name));
832832
lints
833833
}
834834

src/librustc_interface/passes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,7 @@ fn configure_and_expand_inner<'a>(
439439
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
440440
info!("{} parse sess buffered_lints", buffered_lints.len());
441441
for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) {
442-
let lint = lint::Lint::from_parser_lint_id(lint_id);
443-
resolver.lint_buffer().buffer_lint(lint, id, span, &msg);
442+
resolver.lint_buffer().buffer_lint(lint_id, id, span, &msg);
444443
}
445444
});
446445

src/librustc_lint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ rustc_data_structures = { path = "../librustc_data_structures" }
1818
rustc_feature = { path = "../librustc_feature" }
1919
rustc_index = { path = "../librustc_index" }
2020
rustc_error_codes = { path = "../librustc_error_codes" }
21+
rustc_session = { path = "../librustc_session" }

src/librustc_lint/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#[macro_use]
2323
extern crate rustc;
24+
#[macro_use]
25+
extern crate rustc_session;
2426

2527
mod array_into_iter;
2628
mod nonstandard_style;

src/librustc_parse/validate_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use errors::{PResult, Applicability};
44
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP};
55
use syntax::ast::{self, Attribute, AttrKind, Ident, MacArgs, MetaItem, MetaItemKind};
66
use syntax::attr::mk_name_value_item_str;
7-
use syntax::early_buffered_lints::BufferedEarlyLintId;
7+
use syntax::early_buffered_lints::ILL_FORMED_ATTRIBUTE_INPUT;
88
use syntax::sess::ParseSess;
99
use syntax_pos::{Symbol, sym};
1010

@@ -93,7 +93,7 @@ pub fn check_builtin_attribute(
9393
}
9494
if should_warn(name) {
9595
sess.buffer_lint(
96-
BufferedEarlyLintId::IllFormedAttributeInput,
96+
&ILL_FORMED_ATTRIBUTE_INPUT,
9797
meta.span,
9898
ast::CRATE_NODE_ID,
9999
&msg,

src/librustc_session/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod cgu_reuse_tracker;
22
pub mod utils;
3+
#[macro_use]
34
pub mod lint;

0 commit comments

Comments
 (0)