summary refs log tree commit diff
path: root/src/libsyntax/ext/tt
diff options
context:
space:
mode:
authorOliver Schneider <git-spam9815368754983@oli-obk.de>2015-07-28 18:07:20 +0200
committerOliver Schneider <git-spam9815368754983@oli-obk.de>2015-07-28 18:07:20 +0200
commit00a5e66f818ad9d79cc4425f5564c7b07e3213a6 (patch)
treef97ac3137f954aaf4866484a7de6f420280b9125 /src/libsyntax/ext/tt
parent9ca511cf63c3611ffae9218945724c1b32025688 (diff)
downloadrust-00a5e66f818ad9d79cc4425f5564c7b07e3213a6.tar.gz
rust-00a5e66f818ad9d79cc4425f5564c7b07e3213a6.zip
remove `get_ident` and `get_name`, make `as_str` sound
Diffstat (limited to 'src/libsyntax/ext/tt')
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs12
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs19
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs10
3 files changed, 17 insertions, 24 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index 5b3887e76b4..4556bd5f8e5 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -223,11 +223,10 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc<NamedMatch>])
                         *idx += 1;
                     }
                     Occupied(..) => {
-                        let string = token::get_ident(bind_name);
                         panic!(p_s.span_diagnostic
                            .span_fatal(sp,
                                        &format!("duplicated bind name: {}",
-                                               &string)))
+                                               bind_name)))
                     }
                 }
             }
@@ -460,9 +459,7 @@ pub fn parse(sess: &ParseSess,
                 let nts = bb_eis.iter().map(|ei| {
                     match ei.top_elts.get_tt(ei.idx) {
                       TtToken(_, MatchNt(bind, name, _, _)) => {
-                        (format!("{} ('{}')",
-                                token::get_ident(name),
-                                token::get_ident(bind))).to_string()
+                        format!("{} ('{}')", name, bind)
                       }
                       _ => panic!()
                     } }).collect::<Vec<String>>().join(" or ");
@@ -484,11 +481,10 @@ pub fn parse(sess: &ParseSess,
 
                 let mut ei = bb_eis.pop().unwrap();
                 match ei.top_elts.get_tt(ei.idx) {
-                  TtToken(span, MatchNt(_, name, _, _)) => {
-                    let name_string = token::get_ident(name);
+                  TtToken(span, MatchNt(_, ident, _, _)) => {
                     let match_cur = ei.match_cur;
                     (&mut ei.matches[match_cur]).push(Rc::new(MatchedNonterminal(
-                        parse_nt(&mut rust_parser, span, &name_string))));
+                        parse_nt(&mut rust_parser, span, &ident.name.as_str()))));
                     ei.idx += 1;
                     ei.match_cur += 1;
                   }
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index e29e0ab54d1..adc88c329a3 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -56,10 +56,9 @@ impl<'a> ParserAnyMacro<'a> {
             let span = parser.span;
             parser.span_err(span, &msg[..]);
 
-            let name = token::get_ident(self.macro_ident);
             let msg = format!("caused by the macro expansion here; the usage \
                                of `{}` is likely invalid in this context",
-                               name);
+                               self.macro_ident);
             parser.span_note(self.site_span, &msg[..]);
         }
     }
@@ -154,7 +153,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
                           -> Box<MacResult+'cx> {
     if cx.trace_macros() {
         println!("{}! {{ {} }}",
-                 token::get_ident(name),
+                 name,
                  print::pprust::tts_to_string(arg));
     }
 
@@ -326,7 +325,7 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
             TtToken(sp, MatchNt(ref name, ref frag_spec, _, _)) => {
                 // ii. If T is a simple NT, look ahead to the next token T' in
                 // M. If T' is in the set FOLLOW(NT), continue. Else; reject.
-                if can_be_followed_by_any(frag_spec.as_str()) {
+                if can_be_followed_by_any(&frag_spec.name.as_str()) {
                     continue
                 } else {
                     let next_token = match tokens.peek() {
@@ -340,13 +339,13 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
                             // possibility that the sequence occurred
                             // zero times (in which case we need to
                             // look at the token that follows the
-                            // sequence, which may itself a sequence,
+                            // sequence, which may itself be a sequence,
                             // and so on).
                             cx.span_err(sp,
                                         &format!("`${0}:{1}` is followed by a \
                                                   sequence repetition, which is not \
                                                   allowed for `{1}` fragments",
-                                                 name.as_str(), frag_spec.as_str())
+                                                 name, frag_spec)
                                         );
                             Eof
                         },
@@ -359,7 +358,7 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
                     let tok = if let TtToken(_, ref tok) = *token { tok } else { unreachable!() };
 
                     // If T' is in the set FOLLOW(NT), continue. Else, reject.
-                    match (&next_token, is_in_follow(cx, &next_token, frag_spec.as_str())) {
+                    match (&next_token, is_in_follow(cx, &next_token, &frag_spec.name.as_str())) {
                         (_, Err(msg)) => {
                             cx.span_err(sp, &msg);
                             continue
@@ -369,7 +368,7 @@ fn check_matcher<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token)
                         (next, Ok(false)) => {
                             cx.span_err(sp, &format!("`${0}:{1}` is followed by `{2}`, which \
                                                       is not allowed for `{1}` fragments",
-                                                     name.as_str(), frag_spec.as_str(),
+                                                     name, frag_spec,
                                                      token_to_string(next)));
                             continue
                         },
@@ -495,14 +494,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.as_str() == "if" || i.as_str() == "in" => Ok(true),
+                    Ident(i, _) if i.name == "if" || i.name == "in" => Ok(true),
                     _ => Ok(false)
                 }
             },
             "path" | "ty" => {
                 match *tok {
                     Comma | FatArrow | Colon | Eq | Gt | Semi => Ok(true),
-                    Ident(i, _) if i.as_str() == "as" => Ok(true),
+                    Ident(i, _) if i.name == "as" => Ok(true),
                     _ => Ok(false)
                 }
             },
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index 368a9f0c27e..0ca755c97b1 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -140,11 +140,9 @@ impl Add for LockstepIterSize {
                 LisContradiction(_) => other,
                 LisConstraint(r_len, _) if l_len == r_len => self.clone(),
                 LisConstraint(r_len, r_id) => {
-                    let l_n = token::get_ident(l_id.clone());
-                    let r_n = token::get_ident(r_id);
                     LisContradiction(format!("inconsistent lockstep iteration: \
-                                              '{:?}' has {} items, but '{:?}' has {}",
-                                              l_n, l_len, r_n, r_len).to_string())
+                                              '{}' has {} items, but '{}' has {}",
+                                              l_id, l_len, r_id, r_len))
                 }
             },
         }
@@ -308,8 +306,8 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
                             MatchedSeq(..) => {
                                 panic!(r.sp_diag.span_fatal(
                                     r.cur_span, /* blame the macro writer */
-                                    &format!("variable '{:?}' is still repeating at this depth",
-                                            token::get_ident(ident))));
+                                    &format!("variable '{}' is still repeating at this depth",
+                                            ident)));
                             }
                         }
                     }