diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-09-24 23:05:02 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-09-24 23:05:02 +0300 |
| commit | f284cbc7af06a941de0cdd06291dc78d37268b9f (patch) | |
| tree | 94b287ceb5755130191c61dbefd317da66ccd4be /src/libsyntax/ext/tt | |
| parent | 40ce80484c636e525ac796a81f38a96c0ca8bf09 (diff) | |
Cleanup interfaces of Name, SyntaxContext and Ident
Make sure Name, SyntaxContext and Ident are passed by value Make sure Idents don't serve as keys (or parts of keys) in maps, Ident comparison is not well defined
Diffstat (limited to 'src/libsyntax/ext/tt')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 10 |
3 files changed, 14 insertions, 14 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index f6513cc3e25..01fd4608ecb 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -79,7 +79,7 @@ pub use self::ParseResult::*; use self::TokenTreeOrTokenTreeVec::*; use ast; -use ast::{TokenTree, Ident}; +use ast::{TokenTree, Name}; use ast::{TtDelimited, TtSequence, TtToken}; use codemap::{BytePos, mk_sp, Span}; use codemap; @@ -202,9 +202,9 @@ pub enum NamedMatch { } pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc<NamedMatch>]) - -> HashMap<Ident, Rc<NamedMatch>> { + -> HashMap<Name, Rc<NamedMatch>> { fn n_rec(p_s: &ParseSess, m: &TokenTree, res: &[Rc<NamedMatch>], - ret_val: &mut HashMap<Ident, Rc<NamedMatch>>, idx: &mut usize) { + ret_val: &mut HashMap<Name, Rc<NamedMatch>>, idx: &mut usize) { match m { &TtSequence(_, ref seq) => { for next_m in &seq.tts { @@ -217,7 +217,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc<NamedMatch>]) } } &TtToken(sp, MatchNt(bind_name, _, _, _)) => { - match ret_val.entry(bind_name) { + match ret_val.entry(bind_name.name) { Vacant(spot) => { spot.insert(res[*idx].clone()); *idx += 1; @@ -246,7 +246,7 @@ pub enum ParseResult<T> { Error(codemap::Span, String) } -pub type NamedParseResult = ParseResult<HashMap<Ident, Rc<NamedMatch>>>; +pub type NamedParseResult = ParseResult<HashMap<Name, Rc<NamedMatch>>>; pub type PositionalParseResult = ParseResult<Vec<Rc<NamedMatch>>>; /// Perform a token equality check, ignoring syntax context (that is, an diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index d728fa59bd1..0a95f24a721 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -282,7 +282,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, }; // Extract the arguments: - let lhses = match **argument_map.get(&lhs_nm).unwrap() { + let lhses = match **argument_map.get(&lhs_nm.name).unwrap() { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(def.span, "wrong-structured lhs") }; @@ -291,7 +291,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, check_lhs_nt_follows(cx, &**lhs, def.span); } - let rhses = match **argument_map.get(&rhs_nm).unwrap() { + let rhses = match **argument_map.get(&rhs_nm.name).unwrap() { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(def.span, "wrong-structured rhs") }; @@ -510,14 +510,14 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result<bool, String> { "pat" => { match *tok { FatArrow | Comma | Eq => Ok(true), - Ident(i, _) if i.name == "if" || i.name == "in" => Ok(true), + Ident(i, _) if i.name.as_str() == "if" || i.name.as_str() == "in" => Ok(true), _ => Ok(false) } }, "path" | "ty" => { match *tok { Comma | FatArrow | Colon | Eq | Gt | Semi => Ok(true), - Ident(i, _) if i.name == "as" => Ok(true), + Ident(i, _) if i.name.as_str() == "as" => Ok(true), _ => Ok(false) } }, diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index b07bd099638..d1e48eda4ff 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -10,7 +10,7 @@ use self::LockstepIterSize::*; use ast; -use ast::{TokenTree, TtDelimited, TtToken, TtSequence, Ident}; +use ast::{TokenTree, TtDelimited, TtToken, TtSequence, Ident, Name}; use codemap::{Span, DUMMY_SP}; use diagnostic::SpanHandler; use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; @@ -38,7 +38,7 @@ pub struct TtReader<'a> { /// the unzipped tree: stack: Vec<TtFrame>, /* for MBE-style macro transcription */ - interpolations: HashMap<Ident, Rc<NamedMatch>>, + interpolations: HashMap<Name, Rc<NamedMatch>>, imported_from: Option<Ident>, // Some => return imported_from as the next token @@ -56,7 +56,7 @@ pub struct TtReader<'a> { /// `src` contains no `TtSequence`s, `MatchNt`s or `SubstNt`s, `interp` can /// (and should) be None. pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, - interp: Option<HashMap<Ident, Rc<NamedMatch>>>, + interp: Option<HashMap<Name, Rc<NamedMatch>>>, imported_from: Option<Ident>, src: Vec<ast::TokenTree>) -> TtReader<'a> { @@ -70,7 +70,7 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, /// `src` contains no `TtSequence`s, `MatchNt`s or `SubstNt`s, `interp` can /// (and should) be None. pub fn new_tt_reader_with_doc_flag<'a>(sp_diag: &'a SpanHandler, - interp: Option<HashMap<Ident, Rc<NamedMatch>>>, + interp: Option<HashMap<Name, Rc<NamedMatch>>>, imported_from: Option<Ident>, src: Vec<ast::TokenTree>, desugar_doc_comments: bool) @@ -117,7 +117,7 @@ fn lookup_cur_matched_by_matched(r: &TtReader, start: Rc<NamedMatch>) -> Rc<Name } fn lookup_cur_matched(r: &TtReader, name: Ident) -> Option<Rc<NamedMatch>> { - let matched_opt = r.interpolations.get(&name).cloned(); + let matched_opt = r.interpolations.get(&name.name).cloned(); matched_opt.map(|s| lookup_cur_matched_by_matched(r, s)) } |
