Skip to content

Commit f9f99c5

Browse files
committed
Make metavariables hygienic.
1 parent 444ff9f commit f9f99c5

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/libsyntax/ext/tt/macro_parser.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub use self::ParseResult::*;
7979
use self::TokenTreeOrTokenTreeVec::*;
8080

8181
use ast;
82-
use ast::{Name, Ident};
82+
use ast::Ident;
8383
use syntax_pos::{self, BytePos, mk_sp, Span};
8484
use codemap::Spanned;
8585
use errors::FatalError;
@@ -202,9 +202,9 @@ pub enum NamedMatch {
202202
}
203203

204204
pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc<NamedMatch>])
205-
-> ParseResult<HashMap<Name, Rc<NamedMatch>>> {
205+
-> ParseResult<HashMap<Ident, Rc<NamedMatch>>> {
206206
fn n_rec(p_s: &ParseSess, m: &TokenTree, res: &[Rc<NamedMatch>],
207-
ret_val: &mut HashMap<Name, Rc<NamedMatch>>, idx: &mut usize)
207+
ret_val: &mut HashMap<Ident, Rc<NamedMatch>>, idx: &mut usize)
208208
-> Result<(), (syntax_pos::Span, String)> {
209209
match *m {
210210
TokenTree::Sequence(_, ref seq) => {
@@ -218,7 +218,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc<NamedMatch>])
218218
}
219219
}
220220
TokenTree::Token(sp, MatchNt(bind_name, _)) => {
221-
match ret_val.entry(bind_name.name) {
221+
match ret_val.entry(bind_name) {
222222
Vacant(spot) => {
223223
spot.insert(res[*idx].clone());
224224
*idx += 1;
@@ -257,7 +257,7 @@ pub enum ParseResult<T> {
257257
Error(syntax_pos::Span, String)
258258
}
259259

260-
pub type NamedParseResult = ParseResult<HashMap<Name, Rc<NamedMatch>>>;
260+
pub type NamedParseResult = ParseResult<HashMap<Ident, Rc<NamedMatch>>>;
261261
pub type PositionalParseResult = ParseResult<Vec<Rc<NamedMatch>>>;
262262

263263
/// Perform a token equality check, ignoring syntax context (that is, an

src/libsyntax/ext/tt/macro_rules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
302302
let mut valid = true;
303303

304304
// Extract the arguments:
305-
let lhses = match **argument_map.get(&lhs_nm.name).unwrap() {
305+
let lhses = match **argument_map.get(&lhs_nm).unwrap() {
306306
MatchedSeq(ref s, _) => {
307307
s.iter().map(|m| match **m {
308308
MatchedNonterminal(NtTT(ref tt)) => {
@@ -315,7 +315,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
315315
_ => cx.span_bug(def.span, "wrong-structured lhs")
316316
};
317317

318-
let rhses = match **argument_map.get(&rhs_nm.name).unwrap() {
318+
let rhses = match **argument_map.get(&rhs_nm).unwrap() {
319319
MatchedSeq(ref s, _) => {
320320
s.iter().map(|m| match **m {
321321
MatchedNonterminal(NtTT(ref tt)) => (**tt).clone(),

src/libsyntax/ext/tt/transcribe.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010
use self::LockstepIterSize::*;
1111

12-
use ast::{Ident, Name};
12+
use ast::Ident;
1313
use syntax_pos::{Span, DUMMY_SP};
1414
use errors::{Handler, DiagnosticBuilder};
1515
use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal};
@@ -38,7 +38,7 @@ pub struct TtReader<'a> {
3838
/// the unzipped tree:
3939
stack: Vec<TtFrame>,
4040
/* for MBE-style macro transcription */
41-
interpolations: HashMap<Name, Rc<NamedMatch>>,
41+
interpolations: HashMap<Ident, Rc<NamedMatch>>,
4242
imported_from: Option<Ident>,
4343

4444
// Some => return imported_from as the next token
@@ -57,7 +57,7 @@ pub struct TtReader<'a> {
5757
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
5858
/// (and should) be None.
5959
pub fn new_tt_reader(sp_diag: &Handler,
60-
interp: Option<HashMap<Name, Rc<NamedMatch>>>,
60+
interp: Option<HashMap<Ident, Rc<NamedMatch>>>,
6161
imported_from: Option<Ident>,
6262
src: Vec<tokenstream::TokenTree>)
6363
-> TtReader {
@@ -71,7 +71,7 @@ pub fn new_tt_reader(sp_diag: &Handler,
7171
/// `src` contains no `TokenTree::Sequence`s, `MatchNt`s or `SubstNt`s, `interp` can
7272
/// (and should) be None.
7373
pub fn new_tt_reader_with_doc_flag(sp_diag: &Handler,
74-
interp: Option<HashMap<Name, Rc<NamedMatch>>>,
74+
interp: Option<HashMap<Ident, Rc<NamedMatch>>>,
7575
imported_from: Option<Ident>,
7676
src: Vec<tokenstream::TokenTree>,
7777
desugar_doc_comments: bool)
@@ -119,7 +119,7 @@ fn lookup_cur_matched_by_matched(r: &TtReader, start: Rc<NamedMatch>) -> Rc<Name
119119
}
120120

121121
fn lookup_cur_matched(r: &TtReader, name: Ident) -> Option<Rc<NamedMatch>> {
122-
let matched_opt = r.interpolations.get(&name.name).cloned();
122+
let matched_opt = r.interpolations.get(&name).cloned();
123123
matched_opt.map(|s| lookup_cur_matched_by_matched(r, s))
124124
}
125125

0 commit comments

Comments
 (0)