Skip to content

Commit 4f797fb

Browse files
committed
Move syntax::ext::hygiene to syntax_pos::hygiene.
1 parent ccce2c6 commit 4f797fb

File tree

8 files changed

+24
-18
lines changed

8 files changed

+24
-18
lines changed

src/librustc/hir/map/def_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a> DefCollector<'a> {
9292
fn visit_macro_invoc(&mut self, id: NodeId, const_expr: bool) {
9393
if let Some(ref mut visit) = self.visit_macro_invoc {
9494
visit(MacroInvocationData {
95-
mark: Mark::from_placeholder_id(id),
95+
mark: id.placeholder_to_mark(),
9696
const_expr: const_expr,
9797
def_index: self.parent_def.unwrap(),
9898
})

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
680680

681681
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
682682
fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
683-
let mark = Mark::from_placeholder_id(id);
683+
let mark = id.placeholder_to_mark();
684684
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
685685
let invocation = self.resolver.invocations[&mark];
686686
invocation.module.set(self.resolver.current_module);

src/libsyntax/ast.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use util::ThinVec;
2020
use syntax_pos::{mk_sp, BytePos, Span, DUMMY_SP, ExpnId};
2121
use codemap::{respan, Spanned};
2222
use abi::Abi;
23-
use ext::hygiene::SyntaxContext;
23+
use ext::hygiene::{Mark, SyntaxContext};
2424
use print::pprust;
2525
use ptr::P;
2626
use rustc_data_structures::indexed_vec;
@@ -256,6 +256,14 @@ impl NodeId {
256256
pub fn as_u32(&self) -> u32 {
257257
self.0
258258
}
259+
260+
pub fn placeholder_from_mark(mark: Mark) -> Self {
261+
NodeId(mark.as_u32())
262+
}
263+
264+
pub fn placeholder_to_mark(self) -> Mark {
265+
Mark::from_u32(self.0)
266+
}
259267
}
260268

261269
impl fmt::Display for NodeId {

src/libsyntax/ext/expand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use ast::{self, Block, Ident, PatKind, Path};
11+
use ast::{self, Block, Ident, NodeId, PatKind, Path};
1212
use ast::{MacStmtStyle, StmtKind, ItemKind};
1313
use attr::{self, HasAttrs};
1414
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
@@ -321,7 +321,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
321321
while let Some(expansions) = expansions.pop() {
322322
for (mark, expansion) in expansions.into_iter().rev() {
323323
let derives = derives.remove(&mark).unwrap_or_else(Vec::new);
324-
placeholder_expander.add(mark.as_placeholder_id(), expansion, derives);
324+
placeholder_expander.add(NodeId::placeholder_from_mark(mark), expansion, derives);
325325
}
326326
}
327327

@@ -703,7 +703,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
703703
..self.cx.current_expansion.clone()
704704
},
705705
});
706-
placeholder(expansion_kind, mark.as_placeholder_id())
706+
placeholder(expansion_kind, NodeId::placeholder_from_mark(mark))
707707
}
708708

709709
fn collect_bang(&mut self, mac: ast::Mac, span: Span, kind: ExpansionKind) -> Expansion {

src/libsyntax/ext/placeholders.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use ast;
11+
use ast::{self, NodeId};
1212
use codemap::{DUMMY_SP, dummy_spanned};
1313
use ext::base::ExtCtxt;
1414
use ext::expand::{Expansion, ExpansionKind};
@@ -88,7 +88,7 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
8888
let mut expansion = expansion.fold_with(self);
8989
if let Expansion::Items(mut items) = expansion {
9090
for derive in derives {
91-
match self.remove(derive.as_placeholder_id()) {
91+
match self.remove(NodeId::placeholder_from_mark(derive)) {
9292
Expansion::Items(derived_items) => items.extend(derived_items),
9393
_ => unreachable!(),
9494
}

src/libsyntax/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ pub mod print {
136136
}
137137

138138
pub mod ext {
139+
pub use syntax_pos::hygiene;
139140
pub mod base;
140141
pub mod build;
141142
pub mod derive;
142143
pub mod expand;
143144
pub mod placeholders;
144-
pub mod hygiene;
145145
pub mod quote;
146146
pub mod source_util;
147147

src/libsyntax/ext/hygiene.rs renamed to src/libsyntax_pos/hygiene.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
1616
//! DOI=10.1017/S0956796812000093 http://dx.doi.org/10.1017/S0956796812000093
1717
18-
use ast::NodeId;
1918
use std::cell::RefCell;
2019
use std::collections::HashMap;
2120
use std::fmt;
@@ -47,17 +46,13 @@ impl Mark {
4746
Mark(0)
4847
}
4948

50-
pub fn from_placeholder_id(id: NodeId) -> Self {
51-
Mark(id.as_u32())
52-
}
53-
54-
pub fn as_placeholder_id(self) -> NodeId {
55-
NodeId::from_u32(self.0)
56-
}
57-
5849
pub fn as_u32(self) -> u32 {
5950
self.0
6051
}
52+
53+
pub fn from_u32(raw: u32) -> Mark {
54+
Mark(raw)
55+
}
6156
}
6257

6358
struct HygieneData {

src/libsyntax_pos/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
html_root_url = "https://doc.rust-lang.org/nightly/")]
2424
#![deny(warnings)]
2525

26+
#![feature(const_fn)]
2627
#![feature(custom_attribute)]
2728
#![allow(unused_attributes)]
2829
#![feature(rustc_private)]
@@ -41,6 +42,8 @@ use serialize::{Encodable, Decodable, Encoder, Decoder};
4142
extern crate serialize;
4243
extern crate serialize as rustc_serialize; // used by deriving
4344

45+
pub mod hygiene;
46+
4447
pub type FileName = String;
4548

4649
/// Spans represent a region of code, used for error reporting. Positions in spans

0 commit comments

Comments
 (0)