Skip to content

Commit 817d1ae

Browse files
Move BufferedEarlyLint to librustc_session
1 parent 2731075 commit 817d1ae

File tree

7 files changed

+61
-59
lines changed

7 files changed

+61
-59
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,6 +3895,7 @@ dependencies = [
38953895
"log",
38963896
"rustc_data_structures",
38973897
"rustc_errors",
3898+
"rustc_index",
38983899
"serialize",
38993900
"syntax_pos",
39003901
]

src/librustc_session/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ rustc_errors = { path = "../librustc_errors" }
1414
rustc_serialize = { path = "../libserialize", package = "serialize" }
1515
rustc_data_structures = { path = "../librustc_data_structures" }
1616
syntax_pos = { path = "../libsyntax_pos" }
17+
rustc_index = { path = "../librustc_index" }

src/librustc_session/lib.rs

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

src/librustc_session/lint.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use syntax_pos::{Symbol, sym};
1+
use syntax_pos::{MultiSpan, Symbol, sym};
22
use syntax_pos::edition::Edition;
33
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
44
pub use self::Level::*;
5+
use crate::node_id::NodeId;
56

67
/// Setting for how to handle a lint.
78
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
@@ -172,6 +173,21 @@ impl<HCX> ToStableHashKey<HCX> for LintId {
172173
}
173174
}
174175

176+
/// Stores buffered lint info which can later be passed to `librustc`.
177+
pub struct BufferedEarlyLint {
178+
/// The span of code that we are linting on.
179+
pub span: MultiSpan,
180+
181+
/// The lint message.
182+
pub msg: String,
183+
184+
/// The `NodeId` of the AST node that generated the lint.
185+
pub id: NodeId,
186+
187+
/// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`.
188+
pub lint_id: &'static Lint,
189+
}
190+
175191
/// Declares a static item of type `&'static Lint`.
176192
#[macro_export]
177193
macro_rules! declare_lint {

src/librustc_session/node_id.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::fmt;
2+
use rustc_index::vec::Idx;
3+
use rustc_serialize::{Encoder, Decoder};
4+
use syntax_pos::ExpnId;
5+
6+
rustc_index::newtype_index! {
7+
pub struct NodeId {
8+
ENCODABLE = custom
9+
DEBUG_FORMAT = "NodeId({})"
10+
}
11+
}
12+
13+
impl NodeId {
14+
pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
15+
NodeId::from_u32(expn_id.as_u32())
16+
}
17+
18+
pub fn placeholder_to_expn_id(self) -> ExpnId {
19+
ExpnId::from_u32(self.as_u32())
20+
}
21+
}
22+
23+
impl fmt::Display for NodeId {
24+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25+
fmt::Display::fmt(&self.as_u32(), f)
26+
}
27+
}
28+
29+
impl rustc_serialize::UseSpecializedEncodable for NodeId {
30+
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
31+
s.emit_u32(self.as_u32())
32+
}
33+
}
34+
35+
impl rustc_serialize::UseSpecializedDecodable for NodeId {
36+
fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
37+
d.read_u32().map(NodeId::from_u32)
38+
}
39+
}

src/libsyntax/ast.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::token::{self, DelimToken};
3030
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
3131

3232
use syntax_pos::symbol::{kw, sym, Symbol};
33-
use syntax_pos::{Span, DUMMY_SP, ExpnId};
33+
use syntax_pos::{Span, DUMMY_SP};
3434

3535
use rustc_data_structures::fx::FxHashSet;
3636
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -268,46 +268,7 @@ impl ParenthesizedArgs {
268268
}
269269
}
270270

271-
// hack to ensure that we don't try to access the private parts of `NodeId` in this module
272-
mod node_id_inner {
273-
use rustc_index::vec::Idx;
274-
rustc_index::newtype_index! {
275-
pub struct NodeId {
276-
ENCODABLE = custom
277-
DEBUG_FORMAT = "NodeId({})"
278-
}
279-
}
280-
}
281-
282-
pub use node_id_inner::NodeId;
283-
284-
impl NodeId {
285-
pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self {
286-
NodeId::from_u32(expn_id.as_u32())
287-
}
288-
289-
pub fn placeholder_to_expn_id(self) -> ExpnId {
290-
ExpnId::from_u32(self.as_u32())
291-
}
292-
}
293-
294-
impl fmt::Display for NodeId {
295-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
296-
fmt::Display::fmt(&self.as_u32(), f)
297-
}
298-
}
299-
300-
impl rustc_serialize::UseSpecializedEncodable for NodeId {
301-
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
302-
s.emit_u32(self.as_u32())
303-
}
304-
}
305-
306-
impl rustc_serialize::UseSpecializedDecodable for NodeId {
307-
fn default_decode<D: Decoder>(d: &mut D) -> Result<NodeId, D::Error> {
308-
d.read_u32().map(NodeId::from_u32)
309-
}
310-
}
271+
pub use rustc_session::node_id::NodeId;
311272

312273
/// `NodeId` used to represent the root of the crate.
313274
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32_const(0);

src/libsyntax/early_buffered_lints.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//! Since we cannot have a dependency on `librustc`, we implement some types here that are somewhat
44
//! redundant. Later, these types can be converted to types for use by the rest of the compiler.
55
6-
use crate::ast::NodeId;
7-
use syntax_pos::MultiSpan;
86
use rustc_session::lint::FutureIncompatibleInfo;
97
use rustc_session::declare_lint;
108
pub use rustc_session::lint::BufferedEarlyLint;
@@ -30,18 +28,3 @@ declare_lint! {
3028
Deny,
3129
"trailing content in included file"
3230
}
33-
34-
/// Stores buffered lint info which can later be passed to `librustc`.
35-
pub struct BufferedEarlyLint {
36-
/// The span of code that we are linting on.
37-
pub span: MultiSpan,
38-
39-
/// The lint message.
40-
pub msg: String,
41-
42-
/// The `NodeId` of the AST node that generated the lint.
43-
pub id: NodeId,
44-
45-
/// A lint Id that can be passed to `rustc::lint::Lint::from_parser_lint_id`.
46-
pub lint_id: &'static rustc_session::lint::Lint,
47-
}

0 commit comments

Comments
 (0)