Move BufferedEarlyLint to librustc_session

This commit is contained in:
Mark Rousskov 2019-11-29 15:41:22 -05:00
parent 2731075a6b
commit 817d1ae834
7 changed files with 61 additions and 59 deletions

View File

@ -3895,6 +3895,7 @@ dependencies = [
"log",
"rustc_data_structures",
"rustc_errors",
"rustc_index",
"serialize",
"syntax_pos",
]

View File

@ -14,3 +14,4 @@ rustc_errors = { path = "../librustc_errors" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
rustc_data_structures = { path = "../librustc_data_structures" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_index = { path = "../librustc_index" }

View File

@ -2,3 +2,4 @@ pub mod cgu_reuse_tracker;
pub mod utils;
#[macro_use]
pub mod lint;
pub mod node_id;

View File

@ -1,7 +1,8 @@
use syntax_pos::{Symbol, sym};
use syntax_pos::{MultiSpan, Symbol, sym};
use syntax_pos::edition::Edition;
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
pub use self::Level::*;
use crate::node_id::NodeId;
/// Setting for how to handle a lint.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
@ -172,6 +173,21 @@ impl<HCX> ToStableHashKey<HCX> for LintId {
}
}
/// Stores buffered lint info which can later be passed to `librustc`.
pub struct BufferedEarlyLint {
/// The span of code that we are linting on.
pub span: MultiSpan,
/// The lint message.
pub msg: String,
/// The `NodeId` of the AST node that generated the lint.
pub id: NodeId,
/// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`.
pub lint_id: &'static Lint,
}
/// Declares a static item of type `&'static Lint`.
#[macro_export]
macro_rules! declare_lint {

View File

@ -0,0 +1,39 @@
use std::fmt;
use rustc_index::vec::Idx;
use rustc_serialize::{Encoder, Decoder};
use syntax_pos::ExpnId;
rustc_index::newtype_index! {
pub struct NodeId {
ENCODABLE = custom
DEBUG_FORMAT = "NodeId({})"
}
}
impl NodeId {
pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
NodeId::from_u32(expn_id.as_u32())
}
pub fn placeholder_to_expn_id(self) -> ExpnId {
ExpnId::from_u32(self.as_u32())
}
}
impl fmt::Display for NodeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.as_u32(), f)
}
}
impl rustc_serialize::UseSpecializedEncodable for NodeId {
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_u32(self.as_u32())
}
}
impl rustc_serialize::UseSpecializedDecodable for NodeId {
fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
d.read_u32().map(NodeId::from_u32)
}
}

View File

@ -30,7 +30,7 @@ use crate::token::{self, DelimToken};
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
use syntax_pos::symbol::{kw, sym, Symbol};
use syntax_pos::{Span, DUMMY_SP, ExpnId};
use syntax_pos::{Span, DUMMY_SP};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@ -268,46 +268,7 @@ impl ParenthesizedArgs {
}
}
// hack to ensure that we don't try to access the private parts of `NodeId` in this module
mod node_id_inner {
use rustc_index::vec::Idx;
rustc_index::newtype_index! {
pub struct NodeId {
ENCODABLE = custom
DEBUG_FORMAT = "NodeId({})"
}
}
}
pub use node_id_inner::NodeId;
impl NodeId {
pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
NodeId::from_u32(expn_id.as_u32())
}
pub fn placeholder_to_expn_id(self) -> ExpnId {
ExpnId::from_u32(self.as_u32())
}
}
impl fmt::Display for NodeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.as_u32(), f)
}
}
impl rustc_serialize::UseSpecializedEncodable for NodeId {
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_u32(self.as_u32())
}
}
impl rustc_serialize::UseSpecializedDecodable for NodeId {
fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
d.read_u32().map(NodeId::from_u32)
}
}
pub use rustc_session::node_id::NodeId;
/// `NodeId` used to represent the root of the crate.
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32_const(0);

View File

@ -3,8 +3,6 @@
//! Since we cannot have a dependency on `librustc`, we implement some types here that are somewhat
//! redundant. Later, these types can be converted to types for use by the rest of the compiler.
use crate::ast::NodeId;
use syntax_pos::MultiSpan;
use rustc_session::lint::FutureIncompatibleInfo;
use rustc_session::declare_lint;
pub use rustc_session::lint::BufferedEarlyLint;
@ -30,18 +28,3 @@ declare_lint! {
Deny,
"trailing content in included file"
}
/// Stores buffered lint info which can later be passed to `librustc`.
pub struct BufferedEarlyLint {
/// The span of code that we are linting on.
pub span: MultiSpan,
/// The lint message.
pub msg: String,
/// The `NodeId` of the AST node that generated the lint.
pub id: NodeId,
/// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`.
pub lint_id: &'static rustc_session::lint::Lint,
}