Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -183,14 +183,26 @@ impl LanguageItemCollector {
}
}

pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
pub fn extract(_: Session, attrs: &[ast::Attribute]) -> Option<InternedString> {
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({})`",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be format!(" ... {0} ... {0}", *value) to avoid the repeat.

// *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;
Expand Down
27 changes: 22 additions & 5 deletions src/libsyntax/parse/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down