Skip to content

Commit

Permalink
Move early lint declarations to librustc_session
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Dec 3, 2019
1 parent 526ee51 commit f03d8f3
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 171 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock
Expand Up @@ -3700,6 +3700,7 @@ dependencies = [
"rustc_error_codes",
"rustc_feature",
"rustc_index",
"rustc_session",
"rustc_target",
"syntax",
"syntax_pos",
Expand Down Expand Up @@ -4477,6 +4478,7 @@ dependencies = [
"rustc_index",
"rustc_lexer",
"rustc_macros",
"rustc_session",
"scoped-tls",
"serialize",
"smallvec 1.0.0",
Expand Down
31 changes: 4 additions & 27 deletions src/librustc/lint/builtin.rs
Expand Up @@ -12,6 +12,8 @@ use syntax::ast;
use syntax::edition::Edition;
use syntax::source_map::Span;
use syntax::symbol::Symbol;
use syntax::early_buffered_lints::{ILL_FORMED_ATTRIBUTE_INPUT, META_VARIABLE_MISUSE};
use rustc_session::declare_lint;

declare_lint! {
pub EXCEEDING_BITSHIFTS,
Expand Down Expand Up @@ -404,31 +406,6 @@ declare_lint! {
};
}

/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`.
pub mod parser {
declare_lint! {
pub ILL_FORMED_ATTRIBUTE_INPUT,
Deny,
"ill-formed attribute inputs that were previously accepted and used in practice",
@future_incompatible = super::FutureIncompatibleInfo {
reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
edition: None,
};
}

declare_lint! {
pub META_VARIABLE_MISUSE,
Allow,
"possible meta-variable misuse at macro definition"
}

declare_lint! {
pub INCOMPLETE_INCLUDE,
Deny,
"trailing content in included file"
}
}

declare_lint! {
pub DEPRECATED_IN_FUTURE,
Allow,
Expand Down Expand Up @@ -520,8 +497,8 @@ declare_lint_pass! {
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
MACRO_USE_EXTERN_CRATE,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
parser::ILL_FORMED_ATTRIBUTE_INPUT,
parser::META_VARIABLE_MISUSE,
ILL_FORMED_ATTRIBUTE_INPUT,
META_VARIABLE_MISUSE,
DEPRECATED_IN_FUTURE,
AMBIGUOUS_ASSOCIATED_ITEMS,
MUTABLE_BORROW_RESERVATION_CONFLICT,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lint/internal.rs
Expand Up @@ -9,6 +9,7 @@ use errors::Applicability;
use rustc_data_structures::fx::FxHashMap;
use syntax::ast::{Ident, Item, ItemKind};
use syntax::symbol::{sym, Symbol};
use rustc_session::declare_tool_lint;

declare_tool_lint! {
pub rustc::DEFAULT_HASH_TYPES,
Expand Down
18 changes: 1 addition & 17 deletions src/librustc/lint/levels.rs
Expand Up @@ -8,7 +8,7 @@ use crate::lint::{self, Lint, LintId, Level, LintSource};
use crate::session::Session;
use crate::util::nodemap::FxHashMap;
use errors::{Applicability, DiagnosticBuilder};
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use syntax::ast;
use syntax::attr;
use syntax::feature_gate;
Expand Down Expand Up @@ -566,19 +566,3 @@ impl<'a> HashStable<StableHashingContext<'a>> for LintLevelMap {
})
}
}

impl<HCX> HashStable<HCX> for LintId {
#[inline]
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
self.lint_name_raw().hash_stable(hcx, hasher);
}
}

impl<HCX> ToStableHashKey<HCX> for LintId {
type KeyType = &'static str;

#[inline]
fn to_stable_hash_key(&self, _: &HCX) -> &'static str {
self.lint_name_raw()
}
}
108 changes: 1 addition & 107 deletions src/librustc/lint/mod.rs
Expand Up @@ -32,7 +32,6 @@ use crate::ty::TyCtxt;
use crate::ty::query::Providers;
use crate::util::nodemap::NodeMap;
use errors::{DiagnosticBuilder, DiagnosticId};
use std::{hash, ptr};
use syntax::ast;
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
use syntax::symbol::Symbol;
Expand All @@ -43,72 +42,7 @@ pub use crate::lint::context::{LateContext, EarlyContext, LintContext, LintStore
check_crate, check_ast_crate, late_lint_mod, CheckLintNameResult,
BufferedEarlyLint,};

pub use rustc_session::lint::{Lint, Level, FutureIncompatibleInfo};

/// Declares a static item of type `&'static Lint`.
#[macro_export]
macro_rules! declare_lint {
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
declare_lint!(
$vis $NAME, $Level, $desc,
);
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
$(@future_incompatible = $fi:expr;)? $($v:ident),*) => (
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: stringify!($NAME),
default_level: $crate::lint::$Level,
desc: $desc,
edition_lint_opts: None,
is_plugin: false,
$($v: true,)*
$(future_incompatible: Some($fi),)*
..$crate::lint::Lint::default_fields_for_macro()
};
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
$lint_edition: expr => $edition_level: ident
) => (
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: stringify!($NAME),
default_level: $crate::lint::$Level,
desc: $desc,
edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)),
report_in_external_macro: false,
is_plugin: false,
};
);
}

#[macro_export]
macro_rules! declare_tool_lint {
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
) => (
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
);
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
report_in_external_macro: $rep:expr
) => (
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
);
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
$external:expr
) => (
$(#[$attr])*
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: &concat!(stringify!($tool), "::", stringify!($NAME)),
default_level: $crate::lint::$Level,
desc: $desc,
edition_lint_opts: None,
report_in_external_macro: $external,
future_incompatible: None,
is_plugin: true,
};
);
}
pub use rustc_session::lint::{Lint, LintId, Level, FutureIncompatibleInfo};

/// Declares a static `LintArray` and return it as an expression.
#[macro_export]
Expand Down Expand Up @@ -420,46 +354,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>;

/// Identifies a lint known to the compiler.
#[derive(Clone, Copy, Debug)]
pub struct LintId {
// Identity is based on pointer equality of this field.
lint: &'static Lint,
}

impl PartialEq for LintId {
fn eq(&self, other: &LintId) -> bool {
ptr::eq(self.lint, other.lint)
}
}

impl Eq for LintId { }

impl hash::Hash for LintId {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
let ptr = self.lint as *const Lint;
ptr.hash(state);
}
}

impl LintId {
/// Gets the `LintId` for a `Lint`.
pub fn of(lint: &'static Lint) -> LintId {
LintId {
lint,
}
}

pub fn lint_name_raw(&self) -> &'static str {
self.lint.name
}

/// Gets the name of the lint.
pub fn to_string(&self) -> String {
self.lint.name_lower()
}
}

/// How a lint level was set.
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
pub enum LintSource {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/config.rs
@@ -1,7 +1,7 @@
//! Contains infrastructure for configuring the compiler, including parsing
//! command-line options.

use crate::lint;
use rustc_session::lint;
use crate::middle::cstore;
use crate::session::{early_error, early_warn, Session};
use crate::session::search_paths::SearchPath;
Expand Down Expand Up @@ -2854,7 +2854,7 @@ impl PpMode {
/// we have an opt-in scheme here, so one is hopefully forced to think about
/// how the hash should be calculated when adding a new command-line argument.
mod dep_tracking {
use crate::lint;
use rustc_session::lint;
use crate::middle::cstore;
use std::collections::BTreeMap;
use std::hash::Hash;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Expand Up @@ -828,7 +828,7 @@ Available lint options:

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

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_interface/passes.rs
Expand Up @@ -439,8 +439,7 @@ fn configure_and_expand_inner<'a>(
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
info!("{} parse sess buffered_lints", buffered_lints.len());
for BufferedEarlyLint{id, span, msg, lint_id} in buffered_lints.drain(..) {
let lint = lint::Lint::from_parser_lint_id(lint_id);
resolver.lint_buffer().buffer_lint(lint, id, span, &msg);
resolver.lint_buffer().buffer_lint(lint_id, id, span, &msg);
}
});

Expand Down
1 change: 1 addition & 0 deletions src/librustc_lint/Cargo.toml
Expand Up @@ -18,3 +18,4 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_feature = { path = "../librustc_feature" }
rustc_index = { path = "../librustc_index" }
rustc_error_codes = { path = "../librustc_error_codes" }
rustc_session = { path = "../librustc_session" }
2 changes: 2 additions & 0 deletions src/librustc_lint/lib.rs
Expand Up @@ -21,6 +21,8 @@

#[macro_use]
extern crate rustc;
#[macro_use]
extern crate rustc_session;

mod array_into_iter;
mod nonstandard_style;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_parse/validate_attr.rs
Expand Up @@ -4,7 +4,7 @@ use errors::{PResult, Applicability};
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP};
use syntax::ast::{self, Attribute, AttrKind, Ident, MacArgs, MetaItem, MetaItemKind};
use syntax::attr::mk_name_value_item_str;
use syntax::early_buffered_lints::BufferedEarlyLintId;
use syntax::early_buffered_lints::ILL_FORMED_ATTRIBUTE_INPUT;
use syntax::sess::ParseSess;
use syntax_pos::{Symbol, sym};

Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn check_builtin_attribute(
}
if should_warn(name) {
sess.buffer_lint(
BufferedEarlyLintId::IllFormedAttributeInput,
&ILL_FORMED_ATTRIBUTE_INPUT,
meta.span,
ast::CRATE_NODE_ID,
&msg,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_session/lib.rs
@@ -1,3 +1,4 @@
pub mod cgu_reuse_tracker;
pub mod utils;
#[macro_use]
pub mod lint;

0 comments on commit f03d8f3

Please sign in to comment.