diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/attr.rs | 46 | ||||
| -rw-r--r-- | src/libsyntax/diagnostics/plugin.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 47 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 64 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/symbol.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/tokenstream.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/util/lev_distance.rs | 11 |
17 files changed, 139 insertions, 185 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a001985ded9..8a238a11281 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -23,7 +23,7 @@ use abi::Abi; use ext::hygiene::SyntaxContext; use print::pprust; use ptr::P; -use symbol::{Symbol, keywords, InternedString}; +use symbol::{Symbol, keywords}; use tokenstream::{TokenTree}; use std::collections::HashSet; @@ -451,7 +451,7 @@ pub struct WhereEqPredicate { /// The set of MetaItems that define the compilation environment of the crate, /// used to drive conditional compilation -pub type CrateConfig = HashSet<(Name, Option<InternedString>)>; +pub type CrateConfig = HashSet<(Name, Option<Symbol>)>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Crate { @@ -1098,7 +1098,7 @@ pub enum LitIntType { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum LitKind { /// A string literal (`"foo"`) - Str(InternedString, StrStyle), + Str(Symbol, StrStyle), /// A byte string (`b"foo"`) ByteStr(Rc<Vec<u8>>), /// A byte char (`b'f'`) @@ -1108,9 +1108,9 @@ pub enum LitKind { /// An integer literal (`1`) Int(u64, LitIntType), /// A float literal (`1f64` or `1E10f64`) - Float(InternedString, FloatTy), + Float(Symbol, FloatTy), /// A float literal without a suffix (`1.0 or 1.0E10`) - FloatUnsuffixed(InternedString), + FloatUnsuffixed(Symbol), /// A boolean literal Bool(bool), } @@ -1442,7 +1442,7 @@ pub enum AsmDialect { /// E.g. `"={eax}"(result)` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct InlineAsmOutput { - pub constraint: InternedString, + pub constraint: Symbol, pub expr: P<Expr>, pub is_rw: bool, pub is_indirect: bool, @@ -1453,11 +1453,11 @@ pub struct InlineAsmOutput { /// E.g. `asm!("NOP");` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct InlineAsm { - pub asm: InternedString, + pub asm: Symbol, pub asm_str_style: StrStyle, pub outputs: Vec<InlineAsmOutput>, - pub inputs: Vec<(InternedString, P<Expr>)>, - pub clobbers: Vec<InternedString>, + pub inputs: Vec<(Symbol, P<Expr>)>, + pub clobbers: Vec<Symbol>, pub volatile: bool, pub alignstack: bool, pub dialect: AsmDialect, diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 4fce739efe2..45c120e0b95 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -25,7 +25,7 @@ use feature_gate::{Features, GatedCfg}; use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; use parse::ParseSess; use ptr::P; -use symbol::{self, Symbol, InternedString}; +use symbol::Symbol; use util::ThinVec; use std::cell::{RefCell, Cell}; @@ -140,7 +140,7 @@ impl NestedMetaItem { /// Gets the string value if self is a MetaItem and the MetaItem is a /// MetaItemKind::NameValue variant containing a string, otherwise None. - pub fn value_str(&self) -> Option<InternedString> { + pub fn value_str(&self) -> Option<Symbol> { self.meta_item().and_then(|meta_item| meta_item.value_str()) } @@ -195,7 +195,7 @@ impl Attribute { pub fn name(&self) -> Name { self.meta().name() } - pub fn value_str(&self) -> Option<InternedString> { + pub fn value_str(&self) -> Option<Symbol> { self.meta().value_str() } @@ -222,7 +222,7 @@ impl MetaItem { self.name } - pub fn value_str(&self) -> Option<InternedString> { + pub fn value_str(&self) -> Option<Symbol> { match self.node { MetaItemKind::NameValue(ref v) => { match v.node { @@ -279,8 +279,7 @@ impl Attribute { let comment = self.value_str().unwrap(); let meta = mk_name_value_item_str( Symbol::intern("doc"), - symbol::intern_and_get_ident(&strip_doc_comment_decoration( - &comment))); + Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))); if self.style == ast::AttrStyle::Outer { f(&mk_attr_outer(self.id, meta)) } else { @@ -294,7 +293,7 @@ impl Attribute { /* Constructors */ -pub fn mk_name_value_item_str(name: Name, value: InternedString) -> MetaItem { +pub fn mk_name_value_item_str(name: Name, value: Symbol) -> MetaItem { let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked)); mk_spanned_name_value_item(DUMMY_SP, name, value_lit) } @@ -383,9 +382,9 @@ pub fn mk_doc_attr_outer(id: AttrId, item: MetaItem, is_sugared_doc: bool) -> At } } -pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: BytePos) +pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, lo: BytePos, hi: BytePos) -> Attribute { - let style = doc_comment_style(&text); + let style = doc_comment_style(&text.as_str()); let lit = spanned(lo, hi, ast::LitKind::Str(text, ast::StrStyle::Cooked)); Attribute { id: id, @@ -416,14 +415,13 @@ pub fn contains_name(attrs: &[Attribute], name: &str) -> bool { }) } -pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) - -> Option<InternedString> { +pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) -> Option<Symbol> { attrs.iter() .find(|at| at.check_name(name)) .and_then(|at| at.value_str()) } -pub fn last_meta_item_value_str_by_name(items: &[MetaItem], name: &str) -> Option<InternedString> { +pub fn last_meta_item_value_str_by_name(items: &[MetaItem], name: &str) -> Option<Symbol> { items.iter() .rev() .find(|mi| mi.check_name(name)) @@ -432,12 +430,12 @@ pub fn last_meta_item_value_str_by_name(items: &[MetaItem], name: &str) -> Optio /* Higher-level applications */ -pub fn find_crate_name(attrs: &[Attribute]) -> Option<InternedString> { +pub fn find_crate_name(attrs: &[Attribute]) -> Option<Symbol> { first_attr_value_str_by_name(attrs, "crate_name") } /// Find the value of #[export_name=*] attribute and check its validity. -pub fn find_export_name_attr(diag: &Handler, attrs: &[Attribute]) -> Option<InternedString> { +pub fn find_export_name_attr(diag: &Handler, attrs: &[Attribute]) -> Option<Symbol> { attrs.iter().fold(None, |ia,attr| { if attr.check_name("export_name") { if let s@Some(_) = attr.value_str() { @@ -555,7 +553,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat #[derive(RustcEncodable, RustcDecodable, Clone, Debug, PartialEq, Eq, Hash)] pub struct Stability { pub level: StabilityLevel, - pub feature: InternedString, + pub feature: Symbol, pub rustc_depr: Option<RustcDeprecation>, } @@ -563,20 +561,20 @@ pub struct Stability { #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)] pub enum StabilityLevel { // Reason for the current stability level and the relevant rust-lang issue - Unstable { reason: Option<InternedString>, issue: u32 }, - Stable { since: InternedString }, + Unstable { reason: Option<Symbol>, issue: u32 }, + Stable { since: Symbol }, } #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)] pub struct RustcDeprecation { - pub since: InternedString, - pub reason: InternedString, + pub since: Symbol, + pub reason: Symbol, } #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)] pub struct Deprecation { - pub since: Option<InternedString>, - pub note: Option<InternedString>, + pub since: Option<Symbol>, + pub note: Option<Symbol>, } impl StabilityLevel { @@ -602,7 +600,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, mark_used(attr); if let Some(metas) = attr.meta_item_list() { - let get = |meta: &MetaItem, item: &mut Option<InternedString>| { + let get = |meta: &MetaItem, item: &mut Option<Symbol>| { if item.is_some() { handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name())); return false @@ -693,7 +691,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, level: Unstable { reason: reason, issue: { - if let Ok(issue) = issue.parse() { + if let Ok(issue) = issue.as_str().parse() { issue } else { span_err!(diagnostic, attr.span(), E0545, @@ -804,7 +802,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler, } depr = if let Some(metas) = attr.meta_item_list() { - let get = |meta: &MetaItem, item: &mut Option<InternedString>| { + let get = |meta: &MetaItem, item: &mut Option<Symbol>| { if item.is_some() { handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name())); return false diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index aa81d7afcb3..fe5cb87ad59 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -195,11 +195,11 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, let (count, expr) = with_registered_diagnostics(|diagnostics| { let descriptions: Vec<P<ast::Expr>> = - diagnostics.iter().filter_map(|(code, info)| { + diagnostics.iter().filter_map(|(&code, info)| { info.description.map(|description| { ecx.expr_tuple(span, vec![ - ecx.expr_str(span, code.as_str()), - ecx.expr_str(span, description.as_str()) + ecx.expr_str(span, code), + ecx.expr_str(span, description) ]) }) }).collect(); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 0fd360ba2e4..1dda5e3ba06 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -21,7 +21,7 @@ use fold::{self, Folder}; use parse::{self, parser}; use parse::token; use ptr::P; -use symbol::{Symbol, InternedString}; +use symbol::Symbol; use util::small_vector::SmallVector; use std::path::PathBuf; @@ -754,7 +754,7 @@ impl<'a> ExtCtxt<'a> { /// emitting `err_msg` if `expr` is not a string literal. This does not stop /// compilation on error, merely emits a non-fatal error and returns None. pub fn expr_to_spanned_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str) - -> Option<Spanned<(InternedString, ast::StrStyle)>> { + -> Option<Spanned<(Symbol, ast::StrStyle)>> { // Update `expr.span`'s expn_id now in case expr is an `include!` macro invocation. let expr = expr.map(|mut expr| { expr.span.expn_id = cx.backtrace(); @@ -765,7 +765,7 @@ pub fn expr_to_spanned_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &st let expr = cx.expander().fold_expr(expr); match expr.node { ast::ExprKind::Lit(ref l) => match l.node { - ast::LitKind::Str(ref s, style) => return Some(respan(expr.span, (s.clone(), style))), + ast::LitKind::Str(s, style) => return Some(respan(expr.span, (s, style))), _ => cx.span_err(l.span, err_msg) }, _ => cx.span_err(expr.span, err_msg) @@ -774,7 +774,7 @@ pub fn expr_to_spanned_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &st } pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str) - -> Option<(InternedString, ast::StrStyle)> { + -> Option<(Symbol, ast::StrStyle)> { expr_to_spanned_string(cx, expr, err_msg).map(|s| s.node) } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index b96a4624508..324afc20051 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -15,7 +15,7 @@ use syntax_pos::{Span, DUMMY_SP, Pos}; use codemap::{dummy_spanned, respan, Spanned}; use ext::base::ExtCtxt; use ptr::P; -use symbol::{intern_and_get_ident, keywords, InternedString}; +use symbol::{Symbol, keywords}; // Transitional reexports so qquote can find the paths it is looking for mod syntax { @@ -149,7 +149,7 @@ pub trait AstBuilder { fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>; fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr>; fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>; - fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr>; + fn expr_str(&self, sp: Span, s: Symbol) -> P<ast::Expr>; fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr>; fn expr_none(&self, sp: Span) -> P<ast::Expr>; @@ -158,7 +158,7 @@ pub trait AstBuilder { fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>; - fn expr_fail(&self, span: Span, msg: InternedString) -> P<ast::Expr>; + fn expr_fail(&self, span: Span, msg: Symbol) -> P<ast::Expr>; fn expr_unreachable(&self, span: Span) -> P<ast::Expr>; fn expr_ok(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr>; @@ -755,7 +755,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> { self.expr_addr_of(sp, self.expr_vec(sp, exprs)) } - fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr> { + fn expr_str(&self, sp: Span, s: Symbol) -> P<ast::Expr> { self.expr_lit(sp, ast::LitKind::Str(s, ast::StrStyle::Cooked)) } @@ -785,9 +785,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(sp, ast::ExprKind::Tup(exprs)) } - fn expr_fail(&self, span: Span, msg: InternedString) -> P<ast::Expr> { + fn expr_fail(&self, span: Span, msg: Symbol) -> P<ast::Expr> { let loc = self.codemap().lookup_char_pos(span.lo); - let expr_file = self.expr_str(span, intern_and_get_ident(&loc.file.name)); + let expr_file = self.expr_str(span, Symbol::intern(&loc.file.name)); let expr_line = self.expr_u32(span, loc.line as u32); let expr_file_line_tuple = self.expr_tuple(span, vec![expr_file, expr_line]); let expr_file_line_ptr = self.expr_addr_of(span, expr_file_line_tuple); @@ -800,9 +800,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_unreachable(&self, span: Span) -> P<ast::Expr> { - self.expr_fail(span, - InternedString::new( - "internal error: entered unreachable code")) + self.expr_fail(span, Symbol::intern("internal error: entered unreachable code")) } fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index f033b3400d0..844fb77e29d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -780,7 +780,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { if inline_module { if let Some(path) = attr::first_attr_value_str_by_name(&item.attrs, "path") { self.cx.current_expansion.no_noninline_mod = false; - module.directory.push(&*path); + module.directory.push(&*path.as_str()); } else { module.directory.push(&*item.ident.name.as_str()); } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 0bd018603d2..aa777a19a9b 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -33,7 +33,7 @@ pub mod rt { use parse::{self, token, classify}; use ptr::P; use std::rc::Rc; - use symbol; + use symbol::Symbol; use tokenstream::{self, TokenTree}; @@ -239,8 +239,7 @@ pub mod rt { impl ToTokens for str { fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { - let lit = ast::LitKind::Str( - symbol::intern_and_get_ident(self), ast::StrStyle::Cooked); + let lit = ast::LitKind::Str(Symbol::intern(self), ast::StrStyle::Cooked); dummy_spanned(lit).to_tokens(cx) } } @@ -538,7 +537,7 @@ fn id_ext(s: &str) -> ast::Ident { // Lift an ident to the expr that evaluates to that ident. fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> P<ast::Expr> { - let e_str = cx.expr_str(sp, ident.name.as_str()); + let e_str = cx.expr_str(sp, ident.name); cx.expr_method_call(sp, cx.expr_ident(sp, id_ext("ext_cx")), id_ext("ident_of"), @@ -547,7 +546,7 @@ fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> P<ast::Expr> { // Lift a name to the expr that evaluates to that name fn mk_name(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> P<ast::Expr> { - let e_str = cx.expr_str(sp, ident.name.as_str()); + let e_str = cx.expr_str(sp, ident.name); cx.expr_method_call(sp, cx.expr_ident(sp, id_ext("ext_cx")), id_ext("name_of"), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 7893ad839ea..320d49b6463 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -17,7 +17,7 @@ use parse::token; use parse; use print::pprust; use ptr::P; -use symbol; +use symbol::Symbol; use tokenstream; use util::small_vector::SmallVector; @@ -61,14 +61,13 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) let topmost = cx.expansion_cause(); let loc = cx.codemap().lookup_char_pos(topmost.lo); - let filename = symbol::intern_and_get_ident(&loc.file.name); - base::MacEager::expr(cx.expr_str(topmost, filename)) + base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name))) } pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) -> Box<base::MacResult+'static> { let s = pprust::tts_to_string(tts); - base::MacEager::expr(cx.expr_str(sp, symbol::intern_and_get_ident(&s))) + base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s))) } pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) @@ -77,7 +76,7 @@ pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) let mod_path = &cx.current_expansion.module.mod_path; let string = mod_path.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("::"); - base::MacEager::expr(cx.expr_str(sp, symbol::intern_and_get_ident(&string))) + base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&string))) } /// include! : parse the given file as an expr @@ -142,10 +141,9 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT // Add this input file to the code map to make it available as // dependency information let filename = format!("{}", file.display()); - let interned = symbol::intern_and_get_ident(&src); cx.codemap().new_filemap_and_lines(&filename, None, &src); - base::MacEager::expr(cx.expr_str(sp, interned)) + base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&src))) } Err(_) => { cx.span_err(sp, diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 0f94018997c..680896e599b 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -33,7 +33,7 @@ use syntax_pos::Span; use errors::{DiagnosticBuilder, Handler}; use visit::{self, FnKind, Visitor}; use parse::ParseSess; -use symbol::InternedString; +use symbol::Symbol; use std::ascii::AsciiExt; use std::env; @@ -59,9 +59,9 @@ macro_rules! declare_features { /// A set of features to be used by later passes. pub struct Features { /// #![feature] attrs for stable language features, for error reporting - pub declared_stable_lang_features: Vec<(InternedString, Span)>, + pub declared_stable_lang_features: Vec<(Symbol, Span)>, /// #![feature] attrs for non-language (library) features - pub declared_lib_features: Vec<(InternedString, Span)>, + pub declared_lib_features: Vec<(Symbol, Span)>, $(pub $feature: bool),+ } @@ -1121,9 +1121,8 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { } fn visit_foreign_item(&mut self, i: &ast::ForeignItem) { - let links_to_llvm = match attr::first_attr_value_str_by_name(&i.attrs, - "link_name") { - Some(val) => val.starts_with("llvm."), + let links_to_llvm = match attr::first_attr_value_str_by_name(&i.attrs, "link_name") { + Some(val) => val.as_str().starts_with("llvm."), _ => false }; if links_to_llvm { @@ -1351,7 +1350,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> F Some(list) => { for mi in list { let name = if let Some(word) = mi.word() { - word.name().as_str() + word.name() } else { span_err!(span_handler, mi.span, E0556, "malformed feature, expected just one word"); diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index a6e40d70e2f..ded676da3c6 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -48,12 +48,8 @@ impl<'a> Parser<'a> { just_parsed_doc_comment = false; } token::DocComment(s) => { - let attr = ::attr::mk_sugared_doc_attr( - attr::mk_attr_id(), - self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)), - self.span.lo, - self.span.hi - ); + let Span { lo, hi, .. } = self.span; + let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, lo, hi); if attr.style != ast::AttrStyle::Outer { let mut err = self.fatal("expected outer doc comment"); err.note("inner doc comments like this (starting with \ @@ -175,8 +171,7 @@ impl<'a> Parser<'a> { token::DocComment(s) => { // we need to get the position of this token before we bump. let Span { lo, hi, .. } = self.span; - let str = self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)); - let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), str, lo, hi); + let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), s, lo, hi); if attr.style == ast::AttrStyle::Inner { attrs.push(attr); self.bump(); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a44f78b3c3a..c811514c307 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -18,7 +18,7 @@ use feature_gate::UnstableFeatures; use parse::parser::Parser; use ptr::P; use str::char_at; -use symbol::{self, InternedString}; +use symbol::Symbol; use tokenstream; use std::cell::RefCell; @@ -372,13 +372,18 @@ fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool { s[1..].chars().all(|c| '0' <= c && c <= '9') } -fn filtered_float_lit(data: InternedString, suffix: Option<&str>, - sd: &Handler, sp: Span) -> ast::LitKind { +fn filtered_float_lit(data: Symbol, suffix: Option<Symbol>, sd: &Handler, sp: Span) + -> ast::LitKind { debug!("filtered_float_lit: {}, {:?}", data, suffix); - match suffix.as_ref().map(|s| &**s) { - Some("f32") => ast::LitKind::Float(data, ast::FloatTy::F32), - Some("f64") => ast::LitKind::Float(data, ast::FloatTy::F64), - Some(suf) => { + let suffix = match suffix { + Some(suffix) => suffix, + None => return ast::LitKind::FloatUnsuffixed(data), + }; + + match &*suffix.as_str() { + "f32" => ast::LitKind::Float(data, ast::FloatTy::F32), + "f64" => ast::LitKind::Float(data, ast::FloatTy::F64), + suf => { if suf.len() >= 2 && looks_like_width_suffix(&['f'], suf) { // if it looks like a width, lets try to be helpful. sd.struct_span_err(sp, &format!("invalid width `{}` for float literal", &suf[1..])) @@ -392,16 +397,13 @@ fn filtered_float_lit(data: InternedString, suffix: Option<&str>, ast::LitKind::FloatUnsuffixed(data) } - None => ast::LitKind::FloatUnsuffixed(data) } } -pub fn float_lit(s: &str, suffix: Option<InternedString>, - sd: &Handler, sp: Span) -> ast::LitKind { +pub fn float_lit(s: &str, suffix: Option<Symbol>, sd: &Handler, sp: Span) -> ast::LitKind { debug!("float_lit: {:?}, {:?}", s, suffix); // FIXME #2252: bounds checking float literals is deferred until trans let s = s.chars().filter(|&c| c != '_').collect::<String>(); - let data = symbol::intern_and_get_ident(&s); - filtered_float_lit(data, suffix.as_ref().map(|s| &**s), sd, sp) + filtered_float_lit(Symbol::intern(&s), suffix, sd, sp) } /// Parse a string representing a byte literal into its final form. Similar to `char_lit` @@ -496,11 +498,7 @@ pub fn byte_str_lit(lit: &str) -> Rc<Vec<u8>> { Rc::new(res) } -pub fn integer_lit(s: &str, - suffix: Option<InternedString>, - sd: &Handler, - sp: Span) - -> ast::LitKind { +pub fn integer_lit(s: &str, suffix: Option<Symbol>, sd: &Handler, sp: Span) -> ast::LitKind { // s can only be ascii, byte indexing is fine let s2 = s.chars().filter(|&c| c != '_').collect::<String>(); @@ -522,16 +520,15 @@ pub fn integer_lit(s: &str, } // 1f64 and 2f32 etc. are valid float literals. - if let Some(ref suf) = suffix { - if looks_like_width_suffix(&['f'], suf) { + if let Some(suf) = suffix { + if looks_like_width_suffix(&['f'], &suf.as_str()) { match base { 16 => sd.span_err(sp, "hexadecimal float literal is not supported"), 8 => sd.span_err(sp, "octal float literal is not supported"), 2 => sd.span_err(sp, "binary float literal is not supported"), _ => () } - let ident = symbol::intern_and_get_ident(&s); - return filtered_float_lit(ident, Some(&suf), sd, sp) + return filtered_float_lit(Symbol::intern(&s), Some(suf), sd, sp) } } @@ -539,9 +536,9 @@ pub fn integer_lit(s: &str, s = &s[2..]; } - if let Some(ref suf) = suffix { - if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")} - ty = match &**suf { + if let Some(suf) = suffix { + if suf.as_str().is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")} + ty = match &*suf.as_str() { "isize" => ast::LitIntType::Signed(ast::IntTy::Is), "i8" => ast::LitIntType::Signed(ast::IntTy::I8), "i16" => ast::LitIntType::Signed(ast::IntTy::I16), @@ -552,7 +549,7 @@ pub fn integer_lit(s: &str, "u16" => ast::LitIntType::Unsigned(ast::UintTy::U16), "u32" => ast::LitIntType::Unsigned(ast::UintTy::U32), "u64" => ast::LitIntType::Unsigned(ast::UintTy::U64), - _ => { + suf => { // i<digits> and u<digits> look like widths, so lets // give an error message along those lines if looks_like_width_suffix(&['i', 'u'], suf) { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 13c701795a8..be1abf9cc83 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -55,7 +55,7 @@ use print::pprust; use ptr::P; use parse::PResult; use tokenstream::{self, Delimited, SequenceRepetition, TokenTree}; -use symbol::{self, Symbol, keywords, InternedString}; +use symbol::{Symbol, keywords}; use util::ThinVec; use std::collections::HashSet; @@ -999,10 +999,6 @@ impl<'a> Parser<'a> { &self.sess.span_diagnostic } - pub fn id_to_interned_str(&mut self, id: Ident) -> InternedString { - id.name.as_str() - } - /// Is the current token one of the keywords that signals a bare function /// type? pub fn token_is_bare_fn_keyword(&mut self) -> bool { @@ -1524,34 +1520,28 @@ impl<'a> Parser<'a> { // float literals, so all the handling is done // internally. token::Integer(s) => { - (false, parse::integer_lit(&s.as_str(), - suf.as_ref().map(|s| s.as_str()), - &self.sess.span_diagnostic, - self.span)) + let diag = &self.sess.span_diagnostic; + (false, parse::integer_lit(&s.as_str(), suf, diag, self.span)) } token::Float(s) => { - (false, parse::float_lit(&s.as_str(), - suf.as_ref().map(|s| s.as_str()), - &self.sess.span_diagnostic, - self.span)) + let diag = &self.sess.span_diagnostic; + (false, parse::float_lit(&s.as_str(), suf, diag, self.span)) } token::Str_(s) => { - (true, - LitKind::Str(symbol::intern_and_get_ident(&parse::str_lit(&s.as_str())), - ast::StrStyle::Cooked)) + let s = Symbol::intern(&parse::str_lit(&s.as_str())); + (true, LitKind::Str(s, ast::StrStyle::Cooked)) } token::StrRaw(s, n) => { - (true, - LitKind::Str( - symbol::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())), - ast::StrStyle::Raw(n))) + let s = Symbol::intern(&parse::raw_str_lit(&s.as_str())); + (true, LitKind::Str(s, ast::StrStyle::Raw(n))) + } + token::ByteStr(i) => { + (true, LitKind::ByteStr(parse::byte_str_lit(&i.as_str()))) + } + token::ByteStrRaw(i, _) => { + (true, LitKind::ByteStr(Rc::new(i.to_string().into_bytes()))) } - token::ByteStr(i) => - (true, LitKind::ByteStr(parse::byte_str_lit(&i.as_str()))), - token::ByteStrRaw(i, _) => - (true, - LitKind::ByteStr(Rc::new(i.to_string().into_bytes()))), }; if suffix_illegal { @@ -5303,17 +5293,16 @@ impl<'a> Parser<'a> { fn push_directory(&mut self, id: Ident, attrs: &[Attribute]) -> Restrictions { if let Some(path) = ::attr::first_attr_value_str_by_name(attrs, "path") { - self.directory.push(&*path); + self.directory.push(&*path.as_str()); self.restrictions - Restrictions::NO_NONINLINE_MOD } else { - let default_path = self.id_to_interned_str(id); - self.directory.push(&*default_path); + self.directory.push(&*id.name.as_str()); self.restrictions } } pub fn submod_path_from_attr(attrs: &[ast::Attribute], dir_path: &Path) -> Option<PathBuf> { - ::attr::first_attr_value_str_by_name(attrs, "path").map(|d| dir_path.join(&*d)) + ::attr::first_attr_value_str_by_name(attrs, "path").map(|d| dir_path.join(&*d.as_str())) } /// Returns either a path to a module, or . @@ -6127,26 +6116,17 @@ impl<'a> Parser<'a> { }) } - pub fn parse_optional_str(&mut self) - -> Option<(InternedString, - ast::StrStyle, - Option<ast::Name>)> { + pub fn parse_optional_str(&mut self) -> Option<(Symbol, ast::StrStyle, Option<ast::Name>)> { let ret = match self.token { - token::Literal(token::Str_(s), suf) => { - let s = self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)); - (s, ast::StrStyle::Cooked, suf) - } - token::Literal(token::StrRaw(s, n), suf) => { - let s = self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)); - (s, ast::StrStyle::Raw(n), suf) - } + token::Literal(token::Str_(s), suf) => (s, ast::StrStyle::Cooked, suf), + token::Literal(token::StrRaw(s, n), suf) => (s, ast::StrStyle::Raw(n), suf), _ => return None }; self.bump(); Some(ret) } - pub fn parse_str(&mut self) -> PResult<'a, (InternedString, StrStyle)> { + pub fn parse_str(&mut self) -> PResult<'a, (Symbol, StrStyle)> { match self.parse_optional_str() { Some((s, style, suf)) => { let sp = self.prev_span; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 52ff17d1c12..544b431e61c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -630,7 +630,7 @@ pub trait PrintState<'a> { _ => () } match lit.node { - ast::LitKind::Str(ref st, style) => self.print_string(&st, style), + ast::LitKind::Str(st, style) => self.print_string(&st.as_str(), style), ast::LitKind::Byte(byte) => { let mut res = String::from("b'"); res.extend(ascii::escape_default(byte).map(|c| c as char)); @@ -664,7 +664,7 @@ pub trait PrintState<'a> { &f, t.ty_to_string())) } - ast::LitKind::FloatUnsuffixed(ref f) => word(self.writer(), &f[..]), + ast::LitKind::FloatUnsuffixed(ref f) => word(self.writer(), &f.as_str()), ast::LitKind::Bool(val) => { if val { word(self.writer(), "true") } else { word(self.writer(), "false") } } @@ -752,7 +752,7 @@ pub trait PrintState<'a> { } try!(self.maybe_print_comment(attr.span.lo)); if attr.is_sugared_doc { - try!(word(self.writer(), &attr.value_str().unwrap())); + try!(word(self.writer(), &attr.value_str().unwrap().as_str())); hardbreak(self.writer()) } else { match attr.style { @@ -2220,19 +2220,18 @@ impl<'a> State<'a> { ast::ExprKind::InlineAsm(ref a) => { try!(word(&mut self.s, "asm!")); try!(self.popen()); - try!(self.print_string(&a.asm, a.asm_str_style)); + try!(self.print_string(&a.asm.as_str(), a.asm_str_style)); try!(self.word_space(":")); - try!(self.commasep(Inconsistent, &a.outputs, - |s, out| { - let mut ch = out.constraint.chars(); + try!(self.commasep(Inconsistent, &a.outputs, |s, out| { + let constraint = out.constraint.as_str(); + let mut ch = constraint.chars(); match ch.next() { Some('=') if out.is_rw => { try!(s.print_string(&format!("+{}", ch.as_str()), ast::StrStyle::Cooked)) } - _ => try!(s.print_string(&out.constraint, - ast::StrStyle::Cooked)) + _ => try!(s.print_string(&constraint, ast::StrStyle::Cooked)) } try!(s.popen()); try!(s.print_expr(&out.expr)); @@ -2242,9 +2241,8 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.word_space(":")); - try!(self.commasep(Inconsistent, &a.inputs, - |s, &(ref co, ref o)| { - try!(s.print_string(&co, ast::StrStyle::Cooked)); + try!(self.commasep(Inconsistent, &a.inputs, |s, &(co, ref o)| { + try!(s.print_string(&co.as_str(), ast::StrStyle::Cooked)); try!(s.popen()); try!(s.print_expr(&o)); try!(s.pclose()); @@ -2255,7 +2253,7 @@ impl<'a> State<'a> { try!(self.commasep(Inconsistent, &a.clobbers, |s, co| { - try!(s.print_string(&co, ast::StrStyle::Cooked)); + try!(s.print_string(&co.as_str(), ast::StrStyle::Cooked)); Ok(()) })); diff --git a/src/libsyntax/symbol.rs b/src/libsyntax/symbol.rs index 9620b8412b4..4095845f8d9 100644 --- a/src/libsyntax/symbol.rs +++ b/src/libsyntax/symbol.rs @@ -305,13 +305,6 @@ impl Encodable for InternedString { } } -/// Interns and returns the string contents of an identifier, using the -/// thread-local interner. -#[inline] -pub fn intern_and_get_ident(s: &str) -> InternedString { - Symbol::intern(s).as_str() -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 271de16e7ac..4de3baf7d14 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -38,12 +38,12 @@ use parse::{token, ParseSess}; use print::pprust; use ast::{self, Ident}; use ptr::P; -use symbol::{self, Symbol, keywords, InternedString}; +use symbol::{self, Symbol, keywords}; use util::small_vector::SmallVector; enum ShouldPanic { No, - Yes(Option<InternedString>), + Yes(Option<Symbol>), } struct Test { @@ -60,7 +60,7 @@ struct TestCtxt<'a> { path: Vec<Ident>, ext_cx: ExtCtxt<'a>, testfns: Vec<Test>, - reexport_test_harness_main: Option<InternedString>, + reexport_test_harness_main: Option<Symbol>, is_test_crate: bool, // top-level re-export submodule, filled out after folding is finished @@ -267,7 +267,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt, fn generate_test_harness(sess: &ParseSess, resolver: &mut Resolver, - reexport_test_harness_main: Option<InternedString>, + reexport_test_harness_main: Option<Symbol>, krate: ast::Crate, sd: &errors::Handler) -> ast::Crate { // Remove the entry points @@ -548,9 +548,9 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) { vis: ast::Visibility::Public, span: DUMMY_SP, })).pop().unwrap(); - let reexport = cx.reexport_test_harness_main.as_ref().map(|s| { + let reexport = cx.reexport_test_harness_main.map(|s| { // building `use <ident> = __test::main` - let reexport_ident = Ident::from_str(&s); + let reexport_ident = Ident::with_empty_ctxt(s); let use_path = nospan(ast::ViewPathSimple(reexport_ident, @@ -618,7 +618,7 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> { fn is_test_crate(krate: &ast::Crate) -> bool { match attr::find_crate_name(&krate.attrs) { - Some(ref s) if "test" == &s[..] => true, + Some(s) if "test" == &*s.as_str() => true, _ => false } } @@ -664,7 +664,7 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> { // path to the #[test] function: "foo::bar::baz" let path_string = path_name_i(&path[..]); - let name_expr = ecx.expr_str(span, symbol::intern_and_get_ident(&path_string[..])); + let name_expr = ecx.expr_str(span, Symbol::intern(&path_string)); // self::test::StaticTestName($name_expr) let name_expr = ecx.expr_call(span, @@ -677,10 +677,10 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> { }; let fail_expr = match test.should_panic { ShouldPanic::No => ecx.expr_path(should_panic_path("No")), - ShouldPanic::Yes(ref msg) => { - match *msg { - Some(ref msg) => { - let msg = ecx.expr_str(span, msg.clone()); + ShouldPanic::Yes(msg) => { + match msg { + Some(msg) => { + let msg = ecx.expr_str(span, msg); let path = should_panic_path("YesWithMessage"); ecx.expr_call(span, ecx.expr_path(path), vec![msg]) } diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 7ca4650a3ae..ee0c2f80891 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -34,7 +34,7 @@ use parse::lexer; use parse; use parse::token::{self, Token, Lit, Nonterminal}; use print::pprust; -use symbol::{self, Symbol}; +use symbol::Symbol; use std::fmt; use std::iter::*; @@ -296,7 +296,7 @@ impl TokenTree { pub fn maybe_str(&self) -> Option<ast::Lit> { match *self { TokenTree::Token(sp, Token::Literal(Lit::Str_(s), _)) => { - let l = LitKind::Str(symbol::intern_and_get_ident(&parse::str_lit(&s.as_str())), + let l = LitKind::Str(Symbol::intern(&parse::str_lit(&s.as_str())), ast::StrStyle::Cooked); Some(Spanned { node: l, @@ -304,7 +304,7 @@ impl TokenTree { }) } TokenTree::Token(sp, Token::Literal(Lit::StrRaw(s, n), _)) => { - let l = LitKind::Str(symbol::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())), + let l = LitKind::Str(Symbol::intern(&parse::raw_str_lit(&s.as_str())), ast::StrStyle::Raw(n)); Some(Spanned { node: l, diff --git a/src/libsyntax/util/lev_distance.rs b/src/libsyntax/util/lev_distance.rs index 0d6df2cfcb6..a6fff2d7074 100644 --- a/src/libsyntax/util/lev_distance.rs +++ b/src/libsyntax/util/lev_distance.rs @@ -8,9 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::Name; use std::cmp; -use symbol::InternedString; +use symbol::Symbol; /// To find the Levenshtein distance between two strings pub fn lev_distance(a: &str, b: &str) -> usize { @@ -48,14 +47,14 @@ pub fn lev_distance(a: &str, b: &str) -> usize { /// to one-third of the given word pub fn find_best_match_for_name<'a, T>(iter_names: T, lookup: &str, - dist: Option<usize>) -> Option<InternedString> - where T: Iterator<Item = &'a Name> { + dist: Option<usize>) -> Option<Symbol> + where T: Iterator<Item = &'a Symbol> { let max_dist = dist.map_or_else(|| cmp::max(lookup.len(), 3) / 3, |d| d); iter_names - .filter_map(|name| { + .filter_map(|&name| { let dist = lev_distance(lookup, &name.as_str()); match dist <= max_dist { // filter the unwanted cases - true => Some((name.as_str(), dist)), + true => Some((name, dist)), false => None, } }) |
