diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 290e901d1a3f8..f44e6368d473a 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -114,7 +114,7 @@ struct LanguageItemVisitor<'a> { impl<'a> Visitor<()> for LanguageItemVisitor<'a> { fn visit_item(&mut self, item: &ast::Item, _: ()) { - match extract(item.attrs) { + match extract(self.this.session, item.attrs) { Some(value) => { let item_index = self.this.item_refs.find_equiv(&value).map(|x| *x); @@ -183,14 +183,26 @@ impl LanguageItemCollector { } } -pub fn extract(attrs: &[ast::Attribute]) -> Option { +pub fn extract(_: Session, attrs: &[ast::Attribute]) -> Option { for attribute in attrs.iter() { match attribute.name_str_pair() { Some((ref key, ref value)) if key.equiv(&("lang")) => { + // Raise error after snapshot landed + //session.err(format!("`lang = {}` was replaced by `lang({})`", + // *value, *value)); return Some((*value).clone()); } Some(..) | None => {} } + + if attribute.name().equiv(&("lang")) { + match attribute.meta_item_list() { + Some(ref l) if l.len() == 1 => { + return Some(l[0].name().clone()); + } + _ => {} + } + } } return None; diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index c9bea78d02db5..f7d0149ff951f 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -9,7 +9,7 @@ // except according to those terms. use ast; -use codemap::{spanned, Spanned, mk_sp}; +use codemap::{spanned, Spanned, mk_sp, Span}; use parse::common::*; //resolve bug? use parse::token; use parse::parser::Parser; @@ -156,10 +156,22 @@ impl ParserAttr for Parser { // | IDENT meta_seq fn parse_meta_item(&mut self) -> @ast::MetaItem { let lo = self.span.lo; - let ident = self.parse_ident(); - let name = self.id_to_interned_str(ident); + + let (ident, name) = match self.parse_optional_str() { + Some((s, _)) => (None, s), + None => { + let ident = self.parse_ident(); + (Some(self.id_to_interned_str(ident)), self.id_to_interned_str(ident)) + } + }; + match self.token { token::EQ => { + if ident.is_none() { + self.span_fatal( + Span { lo: lo, hi: self.span.hi, expn_info: self.span.expn_info }, + "expected ident but found string"); + } self.bump(); let lit = self.parse_lit(); // FIXME #623 Non-string meta items are not serialized correctly; @@ -173,12 +185,17 @@ impl ParserAttr for Parser { } } let hi = self.span.hi; - @spanned(lo, hi, ast::MetaNameValue(name, lit)) + @spanned(lo, hi, ast::MetaNameValue(ident.unwrap(), lit)) } token::LPAREN => { + if ident.is_none() { + self.span_fatal( + Span { lo: lo, hi: self.span.hi, expn_info: self.span.expn_info }, + "expected ident but found string"); + } let inner_items = self.parse_meta_seq(); let hi = self.span.hi; - @spanned(lo, hi, ast::MetaList(name, inner_items)) + @spanned(lo, hi, ast::MetaList(ident.unwrap(), inner_items)) } _ => { let hi = self.last_span.hi;