Fix fallout in rustdoc and tests.

This commit is contained in:
Jeffrey Seyfried 2016-11-17 14:04:36 +00:00
parent c9935e4a37
commit a8e86f0f81
30 changed files with 120 additions and 130 deletions

View file

@ -1764,9 +1764,7 @@ mod tests {
use std::rc::Rc; use std::rc::Rc;
use super::{OutputType, OutputTypes, Externs}; use super::{OutputType, OutputTypes, Externs};
use rustc_back::PanicStrategy; use rustc_back::PanicStrategy;
use syntax::{ast, attr}; use syntax::symbol::Symbol;
use syntax::parse::token::InternedString;
use syntax::codemap::dummy_spanned;
fn optgroups() -> Vec<OptGroup> { fn optgroups() -> Vec<OptGroup> {
super::rustc_optgroups().into_iter() super::rustc_optgroups().into_iter()
@ -1795,9 +1793,7 @@ mod tests {
let (sessopts, cfg) = build_session_options_and_crate_config(matches); let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore)); let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore));
let cfg = build_configuration(&sess, cfg); let cfg = build_configuration(&sess, cfg);
assert!(attr::contains(&cfg, &dummy_spanned(ast::MetaItemKind::Word({ assert!(cfg.contains(&(Symbol::intern("test"), None)));
InternedString::new("test")
}))));
} }
// When the user supplies --test and --cfg test, don't implicitly add // When the user supplies --test and --cfg test, don't implicitly add
@ -1818,7 +1814,7 @@ mod tests {
let sess = build_session(sessopts, &dep_graph, None, registry, let sess = build_session(sessopts, &dep_graph, None, registry,
Rc::new(DummyCrateStore)); Rc::new(DummyCrateStore));
let cfg = build_configuration(&sess, cfg); let cfg = build_configuration(&sess, cfg);
let mut test_items = cfg.iter().filter(|m| m.name() == "test"); let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
assert!(test_items.next().is_some()); assert!(test_items.next().is_some());
assert!(test_items.next().is_none()); assert!(test_items.next().is_none());
} }

View file

@ -54,7 +54,7 @@ use syntax::{ast, diagnostics, visit};
use syntax::attr; use syntax::attr;
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
use syntax::parse::{self, PResult}; use syntax::parse::{self, PResult};
use syntax::symbol::{self, Symbol}; use syntax::symbol::Symbol;
use syntax::util::node_count::NodeCounter; use syntax::util::node_count::NodeCounter;
use syntax; use syntax;
use syntax_ext; use syntax_ext;

View file

@ -34,8 +34,8 @@ use syntax::codemap::CodeMap;
use errors; use errors;
use errors::emitter::Emitter; use errors::emitter::Emitter;
use errors::{Level, DiagnosticBuilder}; use errors::{Level, DiagnosticBuilder};
use syntax::parse::token;
use syntax::feature_gate::UnstableFeatures; use syntax::feature_gate::UnstableFeatures;
use syntax::symbol::Symbol;
use rustc::hir; use rustc::hir;
@ -288,11 +288,11 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
pub fn t_param(&self, index: u32) -> Ty<'tcx> { pub fn t_param(&self, index: u32) -> Ty<'tcx> {
let name = format!("T{}", index); let name = format!("T{}", index);
self.infcx.tcx.mk_param(index, token::intern(&name[..])) self.infcx.tcx.mk_param(index, Symbol::intern(&name[..]))
} }
pub fn re_early_bound(&self, index: u32, name: &'static str) -> &'tcx ty::Region { pub fn re_early_bound(&self, index: u32, name: &'static str) -> &'tcx ty::Region {
let name = token::intern(name); let name = Symbol::intern(name);
self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
index: index, index: index,
name: name, name: name,

View file

@ -24,9 +24,9 @@ use syntax::abi::Abi;
use syntax::ast; use syntax::ast;
use syntax::attr; use syntax::attr;
use syntax::codemap::Spanned; use syntax::codemap::Spanned;
use syntax::parse::token::keywords;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::print::pprust as syntax_pprust; use syntax::print::pprust as syntax_pprust;
use syntax::symbol::keywords;
use syntax_pos::{self, DUMMY_SP, Pos}; use syntax_pos::{self, DUMMY_SP, Pos};
use rustc_trans::back::link; use rustc_trans::back::link;
@ -242,7 +242,7 @@ impl Clean<ExternalCrate> for CrateNum {
} }
}); });
ExternalCrate { ExternalCrate {
name: (&cx.sess().cstore.crate_name(self.0)[..]).to_owned(), name: cx.sess().cstore.crate_name(self.0).to_string(),
attrs: cx.sess().cstore.item_attrs(root).clean(cx), attrs: cx.sess().cstore.item_attrs(root).clean(cx),
primitives: primitives, primitives: primitives,
} }
@ -2577,7 +2577,7 @@ impl Clean<Vec<Item>> for doctree::Import {
// #[doc(no_inline)] attribute is present. // #[doc(no_inline)] attribute is present.
// Don't inline doc(hidden) imports so they can be stripped at a later stage. // Don't inline doc(hidden) imports so they can be stripped at a later stage.
let denied = self.vis != hir::Public || self.attrs.iter().any(|a| { let denied = self.vis != hir::Public || self.attrs.iter().any(|a| {
&a.name()[..] == "doc" && match a.meta_item_list() { a.name() == "doc" && match a.meta_item_list() {
Some(l) => attr::list_contains_name(l, "no_inline") || Some(l) => attr::list_contains_name(l, "no_inline") ||
attr::list_contains_name(l, "hidden"), attr::list_contains_name(l, "hidden"),
None => false, None => false,

View file

@ -871,6 +871,7 @@ impl CodeMapper for CodeMap {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use symbol::keywords;
use std::rc::Rc; use std::rc::Rc;
#[test] #[test]
@ -1097,10 +1098,9 @@ mod tests {
#[test] #[test]
fn t11() { fn t11() {
// Test span_to_expanded_string works with expansion // Test span_to_expanded_string works with expansion
use ast::Name;
let cm = init_code_map(); let cm = init_code_map();
let root = Span { lo: BytePos(0), hi: BytePos(11), expn_id: NO_EXPANSION }; let root = Span { lo: BytePos(0), hi: BytePos(11), expn_id: NO_EXPANSION };
let format = ExpnFormat::MacroBang(Name(0u32)); let format = ExpnFormat::MacroBang(keywords::Invalid.name());
let callee = NameAndSpan { format: format, let callee = NameAndSpan { format: format,
allow_internal_unstable: false, allow_internal_unstable: false,
span: None }; span: None };
@ -1197,11 +1197,9 @@ mod tests {
fn init_expansion_chain(cm: &CodeMap) -> Span { fn init_expansion_chain(cm: &CodeMap) -> Span {
// Creates an expansion chain containing two recursive calls // Creates an expansion chain containing two recursive calls
// root -> expA -> expA -> expB -> expB -> end // root -> expA -> expA -> expB -> expB -> end
use ast::Name;
let root = Span { lo: BytePos(0), hi: BytePos(11), expn_id: NO_EXPANSION }; let root = Span { lo: BytePos(0), hi: BytePos(11), expn_id: NO_EXPANSION };
let format_root = ExpnFormat::MacroBang(Name(0u32)); let format_root = ExpnFormat::MacroBang(keywords::Invalid.name());
let callee_root = NameAndSpan { format: format_root, let callee_root = NameAndSpan { format: format_root,
allow_internal_unstable: false, allow_internal_unstable: false,
span: Some(root) }; span: Some(root) };
@ -1210,7 +1208,7 @@ mod tests {
let id_a1 = cm.record_expansion(info_a1); let id_a1 = cm.record_expansion(info_a1);
let span_a1 = Span { lo: BytePos(12), hi: BytePos(23), expn_id: id_a1 }; let span_a1 = Span { lo: BytePos(12), hi: BytePos(23), expn_id: id_a1 };
let format_a = ExpnFormat::MacroBang(Name(1u32)); let format_a = ExpnFormat::MacroBang(keywords::As.name());
let callee_a = NameAndSpan { format: format_a, let callee_a = NameAndSpan { format: format_a,
allow_internal_unstable: false, allow_internal_unstable: false,
span: Some(span_a1) }; span: Some(span_a1) };
@ -1223,7 +1221,7 @@ mod tests {
let id_b1 = cm.record_expansion(info_b1); let id_b1 = cm.record_expansion(info_b1);
let span_b1 = Span { lo: BytePos(25), hi: BytePos(36), expn_id: id_b1 }; let span_b1 = Span { lo: BytePos(25), hi: BytePos(36), expn_id: id_b1 };
let format_b = ExpnFormat::MacroBang(Name(2u32)); let format_b = ExpnFormat::MacroBang(keywords::Box.name());
let callee_b = NameAndSpan { format: format_b, let callee_b = NameAndSpan { format: format_b,
allow_internal_unstable: false, allow_internal_unstable: false,
span: None }; span: None };

View file

@ -1332,9 +1332,8 @@ pub fn noop_fold_vis<T: Folder>(vis: Visibility, folder: &mut T) -> Visibility {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::io; use std::io;
use ast; use ast::{self, Ident};
use util::parser_testing::{string_to_crate, matches_codepattern}; use util::parser_testing::{string_to_crate, matches_codepattern};
use parse::token;
use print::pprust; use print::pprust;
use fold; use fold;
use super::*; use super::*;
@ -1350,7 +1349,7 @@ mod tests {
impl Folder for ToZzIdentFolder { impl Folder for ToZzIdentFolder {
fn fold_ident(&mut self, _: ast::Ident) -> ast::Ident { fn fold_ident(&mut self, _: ast::Ident) -> ast::Ident {
token::str_to_ident("zz") Ident::from_str("zz")
} }
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
fold::noop_fold_mac(mac, self) fold::noop_fold_mac(mac, self)

View file

@ -1702,6 +1702,7 @@ mod tests {
use super::*; use super::*;
use ast::Ident; use ast::Ident;
use symbol::Symbol;
use syntax_pos::{BytePos, Span, NO_EXPANSION}; use syntax_pos::{BytePos, Span, NO_EXPANSION};
use codemap::CodeMap; use codemap::CodeMap;
use errors; use errors;
@ -1752,7 +1753,7 @@ mod tests {
// read another token: // read another token:
let tok3 = string_reader.next_token(); let tok3 = string_reader.next_token();
let tok4 = TokenAndSpan { let tok4 = TokenAndSpan {
tok: token::Ident(str_to_ident("main")), tok: token::Ident(Ident::from_str("main")),
sp: Span { sp: Span {
lo: BytePos(24), lo: BytePos(24),
hi: BytePos(28), hi: BytePos(28),
@ -1774,7 +1775,7 @@ mod tests {
// make the identifier by looking up the string in the interner // make the identifier by looking up the string in the interner
fn mk_ident(id: &str) -> token::Token { fn mk_ident(id: &str) -> token::Token {
token::Ident(str_to_ident(id)) token::Ident(Ident::from_str(id))
} }
#[test] #[test]
@ -1838,7 +1839,7 @@ mod tests {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sh(cm.clone());
assert_eq!(setup(&cm, &sh, "'abc".to_string()).next_token().tok, assert_eq!(setup(&cm, &sh, "'abc".to_string()).next_token().tok,
token::Lifetime(token::str_to_ident("'abc"))); token::Lifetime(Ident::from_str("'abc")));
} }
#[test] #[test]
@ -1848,7 +1849,7 @@ mod tests {
assert_eq!(setup(&cm, &sh, "r###\"\"#a\\b\x00c\"\"###".to_string()) assert_eq!(setup(&cm, &sh, "r###\"\"#a\\b\x00c\"\"###".to_string())
.next_token() .next_token()
.tok, .tok,
token::Literal(token::StrRaw(Symol::intern("\"#a\\b\x00c\""), 3), None)); token::Literal(token::StrRaw(Symbol::intern("\"#a\\b\x00c\""), 3), None));
} }
#[test] #[test]

View file

@ -597,12 +597,11 @@ mod tests {
use std::rc::Rc; use std::rc::Rc;
use syntax_pos::{self, Span, BytePos, Pos, NO_EXPANSION}; use syntax_pos::{self, Span, BytePos, Pos, NO_EXPANSION};
use codemap::Spanned; use codemap::Spanned;
use ast::{self, PatKind}; use ast::{self, Ident, PatKind};
use abi::Abi; use abi::Abi;
use attr::first_attr_value_str_by_name; use attr::first_attr_value_str_by_name;
use parse; use parse;
use parse::parser::Parser; use parse::parser::Parser;
use parse::token::{str_to_ident};
use print::pprust::item_to_string; use print::pprust::item_to_string;
use ptr::P; use ptr::P;
use tokenstream::{self, TokenTree}; use tokenstream::{self, TokenTree};
@ -624,7 +623,7 @@ mod tests {
global: false, global: false,
segments: vec![ segments: vec![
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("a"), identifier: Ident::from_str("a"),
parameters: ast::PathParameters::none(), parameters: ast::PathParameters::none(),
} }
], ],
@ -643,11 +642,11 @@ mod tests {
global: true, global: true,
segments: vec![ segments: vec![
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("a"), identifier: Ident::from_str("a"),
parameters: ast::PathParameters::none(), parameters: ast::PathParameters::none(),
}, },
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("b"), identifier: Ident::from_str("b"),
parameters: ast::PathParameters::none(), parameters: ast::PathParameters::none(),
} }
] ]
@ -676,8 +675,8 @@ mod tests {
Some(&TokenTree::Token(_, token::Ident(name_zip))), Some(&TokenTree::Token(_, token::Ident(name_zip))),
Some(&TokenTree::Delimited(_, ref macro_delimed)), Some(&TokenTree::Delimited(_, ref macro_delimed)),
) )
if name_macro_rules.name.as_str() == "macro_rules" if name_macro_rules.name == "macro_rules"
&& name_zip.name.as_str() == "zip" => { && name_zip.name == "zip" => {
let tts = &macro_delimed.tts[..]; let tts = &macro_delimed.tts[..];
match (tts.len(), tts.get(0), tts.get(1), tts.get(2)) { match (tts.len(), tts.get(0), tts.get(1), tts.get(2)) {
( (
@ -694,8 +693,7 @@ mod tests {
Some(&TokenTree::Token(_, token::Dollar)), Some(&TokenTree::Token(_, token::Dollar)),
Some(&TokenTree::Token(_, token::Ident(ident))), Some(&TokenTree::Token(_, token::Ident(ident))),
) )
if first_delimed.delim == token::Paren if first_delimed.delim == token::Paren && ident.name == "a" => {},
&& ident.name.as_str() == "a" => {},
_ => panic!("value 3: {:?}", **first_delimed), _ => panic!("value 3: {:?}", **first_delimed),
} }
let tts = &second_delimed.tts[..]; let tts = &second_delimed.tts[..];
@ -706,7 +704,7 @@ mod tests {
Some(&TokenTree::Token(_, token::Ident(ident))), Some(&TokenTree::Token(_, token::Ident(ident))),
) )
if second_delimed.delim == token::Paren if second_delimed.delim == token::Paren
&& ident.name.as_str() == "a" => {}, && ident.name == "a" => {},
_ => panic!("value 4: {:?}", **second_delimed), _ => panic!("value 4: {:?}", **second_delimed),
} }
}, },
@ -722,17 +720,17 @@ mod tests {
let tts = string_to_tts("fn a (b : i32) { b; }".to_string()); let tts = string_to_tts("fn a (b : i32) { b; }".to_string());
let expected = vec![ let expected = vec![
TokenTree::Token(sp(0, 2), token::Ident(str_to_ident("fn"))), TokenTree::Token(sp(0, 2), token::Ident(Ident::from_str("fn"))),
TokenTree::Token(sp(3, 4), token::Ident(str_to_ident("a"))), TokenTree::Token(sp(3, 4), token::Ident(Ident::from_str("a"))),
TokenTree::Delimited( TokenTree::Delimited(
sp(5, 14), sp(5, 14),
Rc::new(tokenstream::Delimited { Rc::new(tokenstream::Delimited {
delim: token::DelimToken::Paren, delim: token::DelimToken::Paren,
open_span: sp(5, 6), open_span: sp(5, 6),
tts: vec![ tts: vec![
TokenTree::Token(sp(6, 7), token::Ident(str_to_ident("b"))), TokenTree::Token(sp(6, 7), token::Ident(Ident::from_str("b"))),
TokenTree::Token(sp(8, 9), token::Colon), TokenTree::Token(sp(8, 9), token::Colon),
TokenTree::Token(sp(10, 13), token::Ident(str_to_ident("i32"))), TokenTree::Token(sp(10, 13), token::Ident(Ident::from_str("i32"))),
], ],
close_span: sp(13, 14), close_span: sp(13, 14),
})), })),
@ -742,7 +740,7 @@ mod tests {
delim: token::DelimToken::Brace, delim: token::DelimToken::Brace,
open_span: sp(15, 16), open_span: sp(15, 16),
tts: vec![ tts: vec![
TokenTree::Token(sp(17, 18), token::Ident(str_to_ident("b"))), TokenTree::Token(sp(17, 18), token::Ident(Ident::from_str("b"))),
TokenTree::Token(sp(18, 19), token::Semi), TokenTree::Token(sp(18, 19), token::Semi),
], ],
close_span: sp(20, 21), close_span: sp(20, 21),
@ -763,7 +761,7 @@ mod tests {
global: false, global: false,
segments: vec![ segments: vec![
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("d"), identifier: Ident::from_str("d"),
parameters: ast::PathParameters::none(), parameters: ast::PathParameters::none(),
} }
], ],
@ -786,7 +784,7 @@ mod tests {
global:false, global:false,
segments: vec![ segments: vec![
ast::PathSegment { ast::PathSegment {
identifier: str_to_ident("b"), identifier: Ident::from_str("b"),
parameters: ast::PathParameters::none(), parameters: ast::PathParameters::none(),
} }
], ],
@ -810,7 +808,7 @@ mod tests {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: PatKind::Ident(ast::BindingMode::ByValue(ast::Mutability::Immutable), node: PatKind::Ident(ast::BindingMode::ByValue(ast::Mutability::Immutable),
Spanned{ span:sp(0, 1), Spanned{ span:sp(0, 1),
node: str_to_ident("b") node: Ident::from_str("b")
}, },
None), None),
span: sp(0,1)})); span: sp(0,1)}));
@ -822,7 +820,7 @@ mod tests {
// this test depends on the intern order of "fn" and "i32" // this test depends on the intern order of "fn" and "i32"
assert_eq!(string_to_item("fn a (b : i32) { b; }".to_string()), assert_eq!(string_to_item("fn a (b : i32) { b; }".to_string()),
Some( Some(
P(ast::Item{ident:str_to_ident("a"), P(ast::Item{ident:Ident::from_str("a"),
attrs:Vec::new(), attrs:Vec::new(),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ItemKind::Fn(P(ast::FnDecl { node: ast::ItemKind::Fn(P(ast::FnDecl {
@ -833,8 +831,7 @@ mod tests {
global:false, global:false,
segments: vec![ segments: vec![
ast::PathSegment { ast::PathSegment {
identifier: identifier: Ident::from_str("i32"),
str_to_ident("i32"),
parameters: ast::PathParameters::none(), parameters: ast::PathParameters::none(),
} }
], ],
@ -847,7 +844,7 @@ mod tests {
ast::BindingMode::ByValue(ast::Mutability::Immutable), ast::BindingMode::ByValue(ast::Mutability::Immutable),
Spanned{ Spanned{
span: sp(6,7), span: sp(6,7),
node: str_to_ident("b")}, node: Ident::from_str("b")},
None None
), ),
span: sp(6,7) span: sp(6,7)
@ -882,9 +879,7 @@ mod tests {
global:false, global:false,
segments: vec![ segments: vec![
ast::PathSegment { ast::PathSegment {
identifier: identifier: Ident::from_str("b"),
str_to_ident(
"b"),
parameters: parameters:
ast::PathParameters::none(), ast::PathParameters::none(),
} }
@ -996,12 +991,12 @@ mod tests {
let item = parse_item_from_source_str(name.clone(), source, &sess) let item = parse_item_from_source_str(name.clone(), source, &sess)
.unwrap().unwrap(); .unwrap().unwrap();
let doc = first_attr_value_str_by_name(&item.attrs, "doc").unwrap(); let doc = first_attr_value_str_by_name(&item.attrs, "doc").unwrap();
assert_eq!(&doc[..], "/// doc comment"); assert_eq!(doc, "/// doc comment");
let source = "/// doc comment\r\n/// line 2\r\nfn foo() {}".to_string(); let source = "/// doc comment\r\n/// line 2\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name.clone(), source, &sess) let item = parse_item_from_source_str(name.clone(), source, &sess)
.unwrap().unwrap(); .unwrap().unwrap();
let docs = item.attrs.iter().filter(|a| &*a.name() == "doc") let docs = item.attrs.iter().filter(|a| a.name() == "doc")
.map(|a| a.value_str().unwrap().to_string()).collect::<Vec<_>>(); .map(|a| a.value_str().unwrap().to_string()).collect::<Vec<_>>();
let b: &[_] = &["/// doc comment".to_string(), "/// line 2".to_string()]; let b: &[_] = &["/// doc comment".to_string(), "/// line 2".to_string()];
assert_eq!(&docs[..], b); assert_eq!(&docs[..], b);
@ -1009,7 +1004,7 @@ mod tests {
let source = "/** doc comment\r\n * with CRLF */\r\nfn foo() {}".to_string(); let source = "/** doc comment\r\n * with CRLF */\r\nfn foo() {}".to_string();
let item = parse_item_from_source_str(name, source, &sess).unwrap().unwrap(); let item = parse_item_from_source_str(name, source, &sess).unwrap().unwrap();
let doc = first_attr_value_str_by_name(&item.attrs, "doc").unwrap(); let doc = first_attr_value_str_by_name(&item.attrs, "doc").unwrap();
assert_eq!(&doc[..], "/** doc comment\n * with CRLF */"); assert_eq!(doc, "/** doc comment\n * with CRLF */");
} }
#[test] #[test]

View file

@ -3080,12 +3080,11 @@ mod tests {
use ast; use ast;
use codemap; use codemap;
use parse::token;
use syntax_pos; use syntax_pos;
#[test] #[test]
fn test_fun_to_string() { fn test_fun_to_string() {
let abba_ident = token::str_to_ident("abba"); let abba_ident = ast::Ident::from_str("abba");
let decl = ast::FnDecl { let decl = ast::FnDecl {
inputs: Vec::new(), inputs: Vec::new(),
@ -3101,7 +3100,7 @@ mod tests {
#[test] #[test]
fn test_variant_to_string() { fn test_variant_to_string() {
let ident = token::str_to_ident("principal_skinner"); let ident = ast::Ident::from_str("principal_skinner");
let var = codemap::respan(syntax_pos::DUMMY_SP, ast::Variant_ { let var = codemap::respan(syntax_pos::DUMMY_SP, ast::Variant_ {
name: ident, name: ident,

View file

@ -872,8 +872,9 @@ impl Index<usize> for InternalTS {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use syntax::ast::Ident;
use syntax_pos::{Span, BytePos, NO_EXPANSION, DUMMY_SP}; use syntax_pos::{Span, BytePos, NO_EXPANSION, DUMMY_SP};
use parse::token::{self, str_to_ident, Token}; use parse::token::{self, Token};
use util::parser_testing::string_to_tts; use util::parser_testing::string_to_tts;
use std::rc::Rc; use std::rc::Rc;
@ -968,15 +969,17 @@ mod tests {
let test_res = TokenStream::from_tts(string_to_tts("foo::bar::baz".to_string())) let test_res = TokenStream::from_tts(string_to_tts("foo::bar::baz".to_string()))
.slice(2..3); .slice(2..3);
let test_eqs = TokenStream::from_tts(vec![TokenTree::Token(sp(5,8), let test_eqs = TokenStream::from_tts(vec![TokenTree::Token(sp(5,8),
token::Ident(str_to_ident("bar")))]); token::Ident(Ident::from_str("bar")))]);
assert_eq!(test_res, test_eqs) assert_eq!(test_res, test_eqs)
} }
#[test] #[test]
fn test_is_empty() { fn test_is_empty() {
let test0 = TokenStream::from_tts(Vec::new()); let test0 = TokenStream::from_tts(Vec::new());
let test1 = TokenStream::from_tts(vec![TokenTree::Token(sp(0, 1), let test1 = TokenStream::from_tts(
Token::Ident(str_to_ident("a")))]); vec![TokenTree::Token(sp(0, 1), Token::Ident(Ident::from_str("a")))]
);
let test2 = TokenStream::from_tts(string_to_tts("foo(bar::baz)".to_string())); let test2 = TokenStream::from_tts(string_to_tts("foo(bar::baz)".to_string()));
assert_eq!(test0.is_empty(), true); assert_eq!(test0.is_empty(), true);
@ -1036,20 +1039,20 @@ mod tests {
assert_eq!(test0, None); assert_eq!(test0, None);
let test1_expected = TokenStream::from_tts(vec![TokenTree::Token(sp(1, 4), let test1_expected = TokenStream::from_tts(vec![TokenTree::Token(sp(1, 4),
token::Ident(str_to_ident("bar"))), token::Ident(Ident::from_str("bar"))),
TokenTree::Token(sp(4, 6), token::ModSep), TokenTree::Token(sp(4, 6), token::ModSep),
TokenTree::Token(sp(6, 9), TokenTree::Token(sp(6, 9),
token::Ident(str_to_ident("baz")))]); token::Ident(Ident::from_str("baz")))]);
assert_eq!(test1, Some(test1_expected)); assert_eq!(test1, Some(test1_expected));
let test2_expected = TokenStream::from_tts(vec![TokenTree::Token(sp(1, 4), let test2_expected = TokenStream::from_tts(vec![TokenTree::Token(sp(1, 4),
token::Ident(str_to_ident("foo"))), token::Ident(Ident::from_str("foo"))),
TokenTree::Token(sp(4, 5), token::Comma), TokenTree::Token(sp(4, 5), token::Comma),
TokenTree::Token(sp(5, 8), TokenTree::Token(sp(5, 8),
token::Ident(str_to_ident("bar"))), token::Ident(Ident::from_str("bar"))),
TokenTree::Token(sp(8, 9), token::Comma), TokenTree::Token(sp(8, 9), token::Comma),
TokenTree::Token(sp(9, 12), TokenTree::Token(sp(9, 12),
token::Ident(str_to_ident("baz")))]); token::Ident(Ident::from_str("baz")))]);
assert_eq!(test2, Some(test2_expected)); assert_eq!(test2, Some(test2_expected));
assert_eq!(test3, None); assert_eq!(test3, None);
@ -1070,7 +1073,7 @@ mod tests {
assert_eq!(test0, None); assert_eq!(test0, None);
assert_eq!(test1, None); assert_eq!(test1, None);
assert_eq!(test2, Some(str_to_ident("foo"))); assert_eq!(test2, Some(Ident::from_str("foo")));
assert_eq!(test3, None); assert_eq!(test3, None);
assert_eq!(test4, None); assert_eq!(test4, None);
} }
@ -1080,9 +1083,9 @@ mod tests {
let test0 = as_paren_delimited_stream(string_to_tts("foo,bar,".to_string())); let test0 = as_paren_delimited_stream(string_to_tts("foo,bar,".to_string()));
let test1 = as_paren_delimited_stream(string_to_tts("baz(foo,bar)".to_string())); let test1 = as_paren_delimited_stream(string_to_tts("baz(foo,bar)".to_string()));
let test0_tts = vec![TokenTree::Token(sp(0, 3), token::Ident(str_to_ident("foo"))), let test0_tts = vec![TokenTree::Token(sp(0, 3), token::Ident(Ident::from_str("foo"))),
TokenTree::Token(sp(3, 4), token::Comma), TokenTree::Token(sp(3, 4), token::Comma),
TokenTree::Token(sp(4, 7), token::Ident(str_to_ident("bar"))), TokenTree::Token(sp(4, 7), token::Ident(Ident::from_str("bar"))),
TokenTree::Token(sp(7, 8), token::Comma)]; TokenTree::Token(sp(7, 8), token::Comma)];
let test0_stream = TokenStream::from_tts(vec![TokenTree::Delimited(sp(0, 8), let test0_stream = TokenStream::from_tts(vec![TokenTree::Delimited(sp(0, 8),
Rc::new(Delimited { Rc::new(Delimited {
@ -1095,11 +1098,11 @@ mod tests {
assert_eq!(test0, test0_stream); assert_eq!(test0, test0_stream);
let test1_tts = vec![TokenTree::Token(sp(4, 7), token::Ident(str_to_ident("foo"))), let test1_tts = vec![TokenTree::Token(sp(4, 7), token::Ident(Ident::from_str("foo"))),
TokenTree::Token(sp(7, 8), token::Comma), TokenTree::Token(sp(7, 8), token::Comma),
TokenTree::Token(sp(8, 11), token::Ident(str_to_ident("bar")))]; TokenTree::Token(sp(8, 11), token::Ident(Ident::from_str("bar")))];
let test1_parse = vec![TokenTree::Token(sp(0, 3), token::Ident(str_to_ident("baz"))), let test1_parse = vec![TokenTree::Token(sp(0, 3), token::Ident(Ident::from_str("baz"))),
TokenTree::Delimited(sp(3, 12), TokenTree::Delimited(sp(3, 12),
Rc::new(Delimited { Rc::new(Delimited {
delim: token::DelimToken::Paren, delim: token::DelimToken::Paren,

View file

@ -8,11 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use ast; use ast::{self, Ident};
use parse::{ParseSess,PResult,filemap_to_tts}; use parse::{ParseSess,PResult,filemap_to_tts};
use parse::{lexer, new_parser_from_source_str}; use parse::{lexer, new_parser_from_source_str};
use parse::parser::Parser; use parse::parser::Parser;
use parse::token;
use ptr::P; use ptr::P;
use tokenstream; use tokenstream;
use std::iter::Peekable; use std::iter::Peekable;
@ -78,9 +77,9 @@ pub fn string_to_pat(source_str: String) -> P<ast::Pat> {
}) })
} }
/// Convert a vector of strings to a vector of ast::Ident's /// Convert a vector of strings to a vector of Ident's
pub fn strs_to_idents(ids: Vec<&str> ) -> Vec<ast::Ident> { pub fn strs_to_idents(ids: Vec<&str> ) -> Vec<Ident> {
ids.iter().map(|u| token::str_to_ident(*u)).collect() ids.iter().map(|u| Ident::from_str(*u)).collect()
} }
/// Does the given string match the pattern? whitespace in the first string /// Does the given string match the pattern? whitespace in the first string

View file

@ -36,7 +36,7 @@ impl LintPass for Pass {
impl EarlyLintPass for Pass { impl EarlyLintPass for Pass {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
if it.ident.name.as_str() == "lintme" { if it.ident.name == "lintme" {
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
} }
} }

View file

@ -19,8 +19,9 @@ extern crate rustc_plugin;
use syntax::ast::{self, Item, MetaItem, ItemKind}; use syntax::ast::{self, Item, MetaItem, ItemKind};
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::parse::{self, token}; use syntax::parse;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol;
use syntax::tokenstream::TokenTree; use syntax::tokenstream::TokenTree;
use syntax_pos::Span; use syntax_pos::Span;
use rustc_plugin::Registry; use rustc_plugin::Registry;
@ -34,11 +35,11 @@ pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("make_a_1", expand_make_a_1); reg.register_macro("make_a_1", expand_make_a_1);
reg.register_macro("identity", expand_identity); reg.register_macro("identity", expand_identity);
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("into_multi_foo"), Symbol::intern("into_multi_foo"),
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
MultiModifier(Box::new(expand_into_foo_multi))); MultiModifier(Box::new(expand_into_foo_multi)));
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("duplicate"), Symbol::intern("duplicate"),
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
MultiDecorator(Box::new(expand_duplicate))); MultiDecorator(Box::new(expand_duplicate)));
} }
@ -102,9 +103,9 @@ fn expand_duplicate(cx: &mut ExtCtxt,
push: &mut FnMut(Annotatable)) push: &mut FnMut(Annotatable))
{ {
let copy_name = match mi.node { let copy_name = match mi.node {
ast::MetaItemKind::List(_, ref xs) => { ast::MetaItemKind::List(ref xs) => {
if let Some(word) = xs[0].word() { if let Some(word) = xs[0].word() {
token::str_to_ident(&word.name()) ast::Ident::with_empty_ctxt(word.name())
} else { } else {
cx.span_err(mi.span, "Expected word"); cx.span_err(mi.span, "Expected word");
return; return;

View file

@ -16,8 +16,8 @@ extern crate syntax;
extern crate syntax_pos; extern crate syntax_pos;
use syntax::ast; use syntax::ast;
use syntax::parse;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::symbol::Symbol;
use syntax_pos::DUMMY_SP; use syntax_pos::DUMMY_SP;
fn main() { fn main() {
@ -30,7 +30,7 @@ fn main() {
cx.bt_push(syntax::codemap::ExpnInfo { cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan { callee: syntax::codemap::NameAndSpan {
format: syntax::codemap::MacroBang(parse::token::intern("")), format: syntax::codemap::MacroBang(Symbol::intern("")),
allow_internal_unstable: false, allow_internal_unstable: false,
span: None, span: None,
} }

View file

@ -10,7 +10,7 @@
// compile-flags: -Z parse-only // compile-flags: -Z parse-only
// error-pattern:expected `]` // error-pattern:expected one of `=` or `]`
// asterisk is bogus // asterisk is bogus
#[attr*] #[attr*]

View file

@ -19,8 +19,8 @@ extern crate syntax_pos;
use syntax::ast; use syntax::ast;
use syntax::codemap; use syntax::codemap;
use syntax::parse;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::symbol::Symbol;
use syntax_pos::DUMMY_SP; use syntax_pos::DUMMY_SP;
fn main() { fn main() {
@ -33,7 +33,7 @@ fn main() {
cx.bt_push(syntax::codemap::ExpnInfo { cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan { callee: syntax::codemap::NameAndSpan {
format: syntax::codemap::MacroBang(parse::token::intern("")), format: syntax::codemap::MacroBang(Symbol::intern("")),
allow_internal_unstable: false, allow_internal_unstable: false,
span: None, span: None,
} }

View file

@ -25,6 +25,7 @@ use rustc_driver::driver::{compile_input, CompileController, anon_src};
use rustc_metadata::cstore::CStore; use rustc_metadata::cstore::CStore;
use rustc_errors::registry::Registry; use rustc_errors::registry::Registry;
use std::collections::HashSet;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
@ -65,7 +66,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
fn compile(code: String, output: PathBuf, sysroot: PathBuf) { fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
let (sess, cstore) = basic_sess(sysroot); let (sess, cstore) = basic_sess(sysroot);
let cfg = build_configuration(&sess, vec![]); let cfg = build_configuration(&sess, HashSet::new());
let control = CompileController::basic(); let control = CompileController::basic();
let input = Input::Str { name: anon_src(), input: code }; let input = Input::Str { name: anon_src(), input: code };
compile_input(&sess, &cstore, &input, &None, &Some(output), None, &control); compile_input(&sess, &cstore, &input, &None, &Some(output), None, &control);

View file

@ -20,10 +20,10 @@ extern crate syntax;
use proc_macro_tokens::build::ident_eq; use proc_macro_tokens::build::ident_eq;
use syntax::ast::Ident;
use syntax::ext::base::{ExtCtxt, MacResult}; use syntax::ext::base::{ExtCtxt, MacResult};
use syntax::ext::proc_macro_shim::build_block_emitter; use syntax::ext::proc_macro_shim::build_block_emitter;
use syntax::tokenstream::{TokenTree, TokenStream}; use syntax::tokenstream::{TokenTree, TokenStream};
use syntax::parse::token::str_to_ident;
use syntax::codemap::Span; use syntax::codemap::Span;
use rustc_plugin::Registry; use rustc_plugin::Registry;
@ -57,7 +57,7 @@ fn cond_rec(input: TokenStream) -> TokenStream {
let test: TokenStream = clause.slice(0..1); let test: TokenStream = clause.slice(0..1);
let rhs: TokenStream = clause.slice_from(1..); let rhs: TokenStream = clause.slice_from(1..);
if ident_eq(&test[0], str_to_ident("else")) || rest.is_empty() { if ident_eq(&test[0], Ident::from_str("else")) || rest.is_empty() {
qquote!({unquote(rhs)}) qquote!({unquote(rhs)})
} else { } else {
qquote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } }) qquote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } })

View file

@ -26,7 +26,7 @@ use syntax::ast::Ident;
use syntax::codemap::{DUMMY_SP, Span}; use syntax::codemap::{DUMMY_SP, Span};
use syntax::ext::proc_macro_shim::build_block_emitter; use syntax::ext::proc_macro_shim::build_block_emitter;
use syntax::ext::base::{ExtCtxt, MacResult}; use syntax::ext::base::{ExtCtxt, MacResult};
use syntax::parse::token::{self, Token, DelimToken, keywords, str_to_ident}; use syntax::parse::token::{self, Token, DelimToken};
use syntax::tokenstream::{TokenTree, TokenStream}; use syntax::tokenstream::{TokenTree, TokenStream};
#[plugin_registrar] #[plugin_registrar]
@ -58,7 +58,7 @@ fn cond_rec(input: TokenStream) -> TokenStream {
let test: TokenStream = clause.slice(0..1); let test: TokenStream = clause.slice(0..1);
let rhs: TokenStream = clause.slice_from(1..); let rhs: TokenStream = clause.slice_from(1..);
if ident_eq(&test[0], str_to_ident("else")) || rest.is_empty() { if ident_eq(&test[0], Ident::from_str("else")) || rest.is_empty() {
qquote!({unquote(rhs)}) qquote!({unquote(rhs)})
} else { } else {
qquote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } }) qquote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } })

View file

@ -52,7 +52,7 @@ fn cond_rec(input: TokenStream) -> TokenStream {
let test: TokenStream = clause.slice(0..1); let test: TokenStream = clause.slice(0..1);
let rhs: TokenStream = clause.slice_from(1..); let rhs: TokenStream = clause.slice_from(1..);
if ident_eq(&test[0], str_to_ident("else")) || rest.is_empty() { if ident_eq(&test[0], Ident::from_str("else")) || rest.is_empty() {
qquote!({unquote(rhs)}) qquote!({unquote(rhs)})
} else { } else {
qquote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } }) qquote!({if unquote(test) { unquote(rhs) } else { cond!(unquote(rest)) } })

View file

@ -25,12 +25,12 @@ use syntax::ast::*;
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token::{intern, InternedString}; use syntax::symbol::Symbol;
use syntax::ptr::P; use syntax::ptr::P;
#[plugin_registrar] #[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension(intern("derive_CustomPartialEq"), reg.register_syntax_extension(Symbol::intern("derive_CustomPartialEq"),
MultiDecorator(Box::new(expand_deriving_partial_eq))); MultiDecorator(Box::new(expand_deriving_partial_eq)));
} }
@ -52,7 +52,7 @@ fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, it
substr) substr)
} }
let inline = cx.meta_word(span, InternedString::new("inline")); let inline = cx.meta_word(span, Symbol::intern("inline"));
let attrs = vec![cx.attribute(span, inline)]; let attrs = vec![cx.attribute(span, inline)];
let methods = vec![MethodDef { let methods = vec![MethodDef {
name: "eq", name: "eq",

View file

@ -23,7 +23,7 @@ extern crate rustc_plugin;
use syntax::ast; use syntax::ast;
use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable}; use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token; use syntax::symbol::Symbol;
use syntax_ext::deriving::generic::{cs_fold, TraitDef, MethodDef, combine_substructure}; use syntax_ext::deriving::generic::{cs_fold, TraitDef, MethodDef, combine_substructure};
use syntax_ext::deriving::generic::ty::{Literal, LifetimeBounds, Path, borrowed_explicit_self}; use syntax_ext::deriving::generic::ty::{Literal, LifetimeBounds, Path, borrowed_explicit_self};
use syntax_pos::Span; use syntax_pos::Span;
@ -32,7 +32,7 @@ use rustc_plugin::Registry;
#[plugin_registrar] #[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("derive_TotalSum"), Symbol::intern("derive_TotalSum"),
MultiDecorator(box expand)); MultiDecorator(box expand));
} }
@ -66,7 +66,7 @@ fn expand(cx: &mut ExtCtxt,
|cx, span, subexpr, field, _| { |cx, span, subexpr, field, _| {
cx.expr_binary(span, ast::BinOpKind::Add, subexpr, cx.expr_binary(span, ast::BinOpKind::Add, subexpr,
cx.expr_method_call(span, field, cx.expr_method_call(span, field,
token::str_to_ident("total_sum"), vec![])) ast::Ident::from_str("total_sum"), vec![]))
}, },
zero, zero,
box |cx, span, _, _| { cx.span_bug(span, "wtf??"); }, box |cx, span, _, _| { cx.span_bug(span, "wtf??"); },

View file

@ -23,7 +23,7 @@ extern crate rustc_plugin;
use syntax::ast; use syntax::ast;
use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable}; use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse::token; use syntax::symbol::Symbol;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_ext::deriving::generic::{TraitDef, MethodDef, combine_substructure}; use syntax_ext::deriving::generic::{TraitDef, MethodDef, combine_substructure};
use syntax_ext::deriving::generic::{Substructure, Struct, EnumMatching}; use syntax_ext::deriving::generic::{Substructure, Struct, EnumMatching};
@ -34,7 +34,7 @@ use rustc_plugin::Registry;
#[plugin_registrar] #[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("derive_TotalSum"), Symbol::intern("derive_TotalSum"),
MultiDecorator(box expand)); MultiDecorator(box expand));
} }

View file

@ -36,7 +36,7 @@ impl LintPass for Pass {
impl EarlyLintPass for Pass { impl EarlyLintPass for Pass {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
if it.ident.name.as_str() == "lintme" { if it.ident.name == "lintme" {
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
} }
} }

View file

@ -23,6 +23,7 @@ use syntax::ext::base::*;
use syntax::ext::quote::rt::ToTokens; use syntax::ext::quote::rt::ToTokens;
use syntax::parse::{self, token}; use syntax::parse::{self, token};
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol;
use syntax::tokenstream::TokenTree; use syntax::tokenstream::TokenTree;
use syntax_pos::Span; use syntax_pos::Span;
use rustc_plugin::Registry; use rustc_plugin::Registry;
@ -36,15 +37,15 @@ pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("make_a_1", expand_make_a_1); reg.register_macro("make_a_1", expand_make_a_1);
reg.register_macro("identity", expand_identity); reg.register_macro("identity", expand_identity);
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("into_multi_foo"), Symbol::intern("into_multi_foo"),
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
MultiModifier(Box::new(expand_into_foo_multi))); MultiModifier(Box::new(expand_into_foo_multi)));
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("duplicate"), Symbol::intern("duplicate"),
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
MultiDecorator(Box::new(expand_duplicate))); MultiDecorator(Box::new(expand_duplicate)));
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("caller"), Symbol::intern("caller"),
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
MultiDecorator(Box::new(expand_caller))); MultiDecorator(Box::new(expand_caller)));
} }
@ -108,9 +109,9 @@ fn expand_duplicate(cx: &mut ExtCtxt,
it: &Annotatable, it: &Annotatable,
push: &mut FnMut(Annotatable)) { push: &mut FnMut(Annotatable)) {
let copy_name = match mi.node { let copy_name = match mi.node {
ast::MetaItemKind::List(_, ref xs) => { ast::MetaItemKind::List(ref xs) => {
if let Some(word) = xs[0].word() { if let Some(word) = xs[0].word() {
token::str_to_ident(&word.name()) ast::Ident::with_empty_ctxt(word.name())
} else { } else {
cx.span_err(mi.span, "Expected word"); cx.span_err(mi.span, "Expected word");
return; return;
@ -179,7 +180,7 @@ fn expand_caller(cx: &mut ExtCtxt,
} }
let fn_name = match list[0].name() { let fn_name = match list[0].name() {
Some(name) => token::str_to_ident(&name), Some(name) => ast::Ident::with_empty_ctxt(name),
None => cx.span_fatal(list[0].span(), "First parameter must be an ident.") None => cx.span_fatal(list[0].span(), "First parameter must be an ident.")
}; };

View file

@ -22,9 +22,9 @@ use std::borrow::ToOwned;
use syntax::ast; use syntax::ast;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager, NormalTT}; use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager, NormalTT};
use syntax::parse::token;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream; use syntax::tokenstream;
use rustc_plugin::Registry; use rustc_plugin::Registry;
@ -40,15 +40,14 @@ impl TTMacroExpander for Expander {
_: &[tokenstream::TokenTree]) -> Box<MacResult+'cx> { _: &[tokenstream::TokenTree]) -> Box<MacResult+'cx> {
let args = self.args.iter().map(|i| pprust::meta_list_item_to_string(i)) let args = self.args.iter().map(|i| pprust::meta_list_item_to_string(i))
.collect::<Vec<_>>().join(", "); .collect::<Vec<_>>().join(", ");
let interned = token::intern_and_get_ident(&args[..]); MacEager::expr(ecx.expr_str(sp, Symbol::intern(&args)))
MacEager::expr(ecx.expr_str(sp, interned))
} }
} }
#[plugin_registrar] #[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
let args = reg.args().to_owned(); let args = reg.args().to_owned();
reg.register_syntax_extension(token::intern("plugin_args"), reg.register_syntax_extension(Symbol::intern("plugin_args"),
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
NormalTT(Box::new(Expander { args: args, }), None, false)); NormalTT(Box::new(Expander { args: args, }), None, false));
} }

View file

@ -18,18 +18,19 @@ use proc_macro_tokens::prelude::*;
use rustc_plugin::Registry; use rustc_plugin::Registry;
use syntax::ext::base::SyntaxExtension; use syntax::ext::base::SyntaxExtension;
use syntax::ext::proc_macro_shim::prelude::*; use syntax::ext::proc_macro_shim::prelude::*;
use syntax::symbol::Symbol;
#[plugin_registrar] #[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension(token::intern("attr_tru"), reg.register_syntax_extension(Symbol::intern("attr_tru"),
SyntaxExtension::AttrProcMacro(Box::new(attr_tru))); SyntaxExtension::AttrProcMacro(Box::new(attr_tru)));
reg.register_syntax_extension(token::intern("attr_identity"), reg.register_syntax_extension(Symbol::intern("attr_identity"),
SyntaxExtension::AttrProcMacro(Box::new(attr_identity))); SyntaxExtension::AttrProcMacro(Box::new(attr_identity)));
reg.register_syntax_extension(token::intern("tru"), reg.register_syntax_extension(Symbol::intern("tru"),
SyntaxExtension::ProcMacro(Box::new(tru))); SyntaxExtension::ProcMacro(Box::new(tru)));
reg.register_syntax_extension(token::intern("ret_tru"), reg.register_syntax_extension(Symbol::intern("ret_tru"),
SyntaxExtension::ProcMacro(Box::new(ret_tru))); SyntaxExtension::ProcMacro(Box::new(ret_tru)));
reg.register_syntax_extension(token::intern("identity"), reg.register_syntax_extension(Symbol::intern("identity"),
SyntaxExtension::ProcMacro(Box::new(identity))); SyntaxExtension::ProcMacro(Box::new(identity)));
} }

View file

@ -18,8 +18,8 @@ extern crate syntax_pos;
extern crate rustc; extern crate rustc;
extern crate rustc_plugin; extern crate rustc_plugin;
use syntax::parse::token::{str_to_ident, NtExpr, NtPat}; use syntax::parse::token::{NtExpr, NtPat};
use syntax::ast::{Pat}; use syntax::ast::{Ident, Pat};
use syntax::tokenstream::{TokenTree}; use syntax::tokenstream::{TokenTree};
use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; use syntax::ext::base::{ExtCtxt, MacResult, MacEager};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
@ -44,12 +44,12 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, _: Span, args: &[TokenTree])
} }
}; };
let matched_nt = match *map[&str_to_ident("matched")] { let matched_nt = match *map[&Ident::from_str("matched")] {
MatchedNonterminal(ref nt) => nt.clone(), MatchedNonterminal(ref nt) => nt.clone(),
_ => unreachable!(), _ => unreachable!(),
}; };
let mac_expr = match (&*matched_nt, &*map[&str_to_ident("pat")]) { let mac_expr = match (&*matched_nt, &*map[&Ident::from_str("pat")]) {
(&NtExpr(ref matched_expr), &MatchedSeq(ref pats, seq_sp)) => { (&NtExpr(ref matched_expr), &MatchedSeq(ref pats, seq_sp)) => {
let pats: Vec<P<Pat>> = pats.iter().map(|pat_nt| { let pats: Vec<P<Pat>> = pats.iter().map(|pat_nt| {
match **pat_nt { match **pat_nt {

View file

@ -18,9 +18,6 @@ extern crate proc_macro_tokens;
use proc_macro_tokens::prelude::*; use proc_macro_tokens::prelude::*;
extern crate syntax; extern crate syntax;
use syntax::ast::Ident;
use syntax::codemap::DUMMY_SP;
use syntax::parse::token::{self, Token, keywords, str_to_ident};
fn main() { fn main() {
let lex_true = lex("true"); let lex_true = lex("true");

View file

@ -16,7 +16,7 @@ extern crate syntax;
extern crate syntax_pos; extern crate syntax_pos;
use syntax::print::pprust::*; use syntax::print::pprust::*;
use syntax::parse::token::intern; use syntax::symbol::Symbol;
use syntax_pos::DUMMY_SP; use syntax_pos::DUMMY_SP;
fn main() { fn main() {
@ -29,7 +29,7 @@ fn main() {
cx.bt_push(syntax::codemap::ExpnInfo { cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan { callee: syntax::codemap::NameAndSpan {
format: syntax::codemap::MacroBang(intern("")), format: syntax::codemap::MacroBang(Symbol::intern("")),
allow_internal_unstable: false, allow_internal_unstable: false,
span: None, span: None,
} }
@ -97,7 +97,7 @@ fn main() {
// quote_meta_item! // quote_meta_item!
let meta = quote_meta_item!(cx, cfg(foo = "bar")); let meta = quote_meta_item!(cx, cfg(foo = "bar"));
check!(meta_item_to_string, meta, *quote_meta_item!(cx, $meta); r#"cfg(foo = "bar")"#); check!(meta_item_to_string, meta, quote_meta_item!(cx, $meta); r#"cfg(foo = "bar")"#);
let attr = quote_attr!(cx, #![$meta]); let attr = quote_attr!(cx, #![$meta]);
check!(attribute_to_string, attr; r#"#![cfg(foo = "bar")]"#); check!(attribute_to_string, attr; r#"#![cfg(foo = "bar")]"#);