Skip to content

Commit

Permalink
make it compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed May 2, 2018
1 parent 24a6284 commit 121abd0
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {

fn check_used(&self, item: &hir::Item, target: Target) {
for attr in &item.attrs {
if attr.name().map(|name| name == "used").unwrap_or(false) && target != Target::Static {
if attr.name() == "used" && target != Target::Static {
self.tcx.sess
.span_err(attr.span, "attribute must be applied to a `static` variable");
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::Path {
hasher: &mut StableHasher<W>) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
segment.identifier.name.hash_stable(hcx, hasher);
segment.ident.name.hash_stable(hcx, hasher);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'a> LintLevelsBuilder<'a> {
continue
}
};
let name = word.ident.name;
let name = word.name();
match store.check_lint_name(&name.as_str()) {
CheckLintNameResult::Ok(ids) => {
let src = LintSource::Node(name, li.span);
Expand Down Expand Up @@ -260,7 +260,7 @@ impl<'a> LintLevelsBuilder<'a> {
Some(li.span.into()),
&msg);
if name.as_str().chars().any(|c| c.is_uppercase()) {
let name_lower = name.as_str().to_lowercase();
let name_lower = name.as_str().to_lowercase().to_string();
if let CheckLintNameResult::NoLint =
store.check_lint_name(&name_lower) {
db.emit();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
early_error(ErrorOutputType::default(), &msg)
}

(meta_item.ident.name, meta_item.value_str())
(meta_item.name(), meta_item.value_str())
})
.collect::<ast::CrateConfig>()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
for command in self.subcommands.iter().chain(Some(self)).rev() {
if let Some(ref condition) = command.condition {
if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| {
options.contains(&(c.ident.name.as_str().to_string(),
options.contains(&(c.name().as_str().to_string(),
match c.value_str().map(|s| s.as_str().to_string()) {
Some(s) => Some(s),
None => None
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ impl RustcDefaultCalls {
let mut cfgs = Vec::new();
for &(name, ref value) in sess.parse_sess.config.iter() {
let gated_cfg = GatedCfg::gate(&ast::MetaItem {
name: ast::Path::from_ident(DUMMY_SP, name.to_ident()),
ident: ast::Path::from_ident(name.to_ident()),
node: ast::MetaItemKind::Word,
span: DUMMY_SP,
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
for list_item in attr.meta_item_list().unwrap_or_default() {
match list_item.word() {
Some(word) if value.is_none() =>
value = Some(word.ident.name),
value = Some(word.name()),
_ =>
// FIXME better-encapsulate meta_item (don't directly access `node`)
span_bug!(list_item.span(), "unexpected meta-item {:?}", list_item.node),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<'a> Resolver<'a> {
match attr.meta_item_list() {
Some(names) => for attr in names {
if let Some(word) = attr.word() {
imports.imports.push((word.ident.name, attr.span()));
imports.imports.push((word.name(), attr.span()));
} else {
span_err!(self.session, attr.span(), E0466, "bad macro import");
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ mod test {

fn dummy_meta_item_word(name: &str) -> MetaItem {
MetaItem {
name: Path::from_ident(DUMMY_SP, Ident::from_str(name)),
ident: Path::from_ident(Ident::from_str(name)),
node: MetaItemKind::Word,
span: DUMMY_SP,
}
Expand All @@ -447,7 +447,7 @@ mod test {
macro_rules! dummy_meta_item_list {
($name:ident, [$($list:ident),* $(,)*]) => {
MetaItem {
name: Path::from_ident(DUMMY_SP, Ident::from_str(stringify!($name))),
ident: Path::from_ident(Ident::from_str(stringify!($name))),
node: MetaItemKind::List(vec![
$(
dummy_spanned(NestedMetaItemKind::MetaItem(
Expand All @@ -461,7 +461,7 @@ mod test {

($name:ident, [$($list:expr),* $(,)*]) => {
MetaItem {
name: Path::from_ident(DUMMY_SP, Ident::from_str(stringify!($name))),
ident: Path::from_ident(Ident::from_str(stringify!($name))),
node: MetaItemKind::List(vec![
$(
dummy_spanned(NestedMetaItemKind::MetaItem($list)),
Expand Down Expand Up @@ -601,7 +601,7 @@ mod test {
assert_eq!(Cfg::parse(&mi), Ok(word_cfg("all")));

let mi = MetaItem {
name: Path::from_ident(DUMMY_SP, Ident::from_str("all")),
ident: Path::from_ident(Ident::from_str("all")),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Str(
Symbol::intern("done"),
StrStyle::Cooked,
Expand Down Expand Up @@ -636,7 +636,7 @@ mod test {
fn test_parse_err() {
with_globals(|| {
let mi = MetaItem {
name: Path::from_ident(DUMMY_SP, Ident::from_str("foo")),
ident: Path::from_ident(Ident::from_str("foo")),
node: MetaItemKind::NameValue(dummy_spanned(LitKind::Bool(false))),
span: DUMMY_SP,
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}

fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
let name = attr.ident.name;
let name = attr.name();

if attr.is_word() {
Some(format!("{}", name))
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ pub enum NestedMetaItemKind {
/// E.g. `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct MetaItem {
pub name: Path,
pub ident: Path,
pub node: MetaItemKind,
pub span: Span,
}
Expand Down
83 changes: 32 additions & 51 deletions src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use ast;
use ast::{AttrId, Attribute, Name, Ident};
use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind};
use codemap::{Spanned, respan, dummy_spanned};
use codemap::{BytePos, Spanned, respan, dummy_spanned};
use syntax_pos::Span;
use errors::Handler;
use feature_gate::{Features, GatedCfg};
Expand Down Expand Up @@ -111,7 +111,7 @@ const RUST_KNOWN_TOOL: &[&str] = &["clippy", "rustfmt"];

pub fn is_known_tool(attr: &Attribute) -> bool {
let tool_name =
attr.path.segments.iter().next().expect("empty path in attribute").identifier.name;
attr.path.segments.iter().next().expect("empty path in attribute").ident.name;
RUST_KNOWN_TOOL.contains(&tool_name.as_str().as_ref())
}

Expand Down Expand Up @@ -213,7 +213,7 @@ impl NestedMetaItem {
}

fn name_from_path(path: &ast::Path) -> Name {
path.segments.last().expect("empty path in attribute").identifier.name
path.segments.last().expect("empty path in attribute").ident.name
}

impl Attribute {
Expand Down Expand Up @@ -266,7 +266,7 @@ impl Attribute {

impl MetaItem {
pub fn name(&self) -> Name {
name_from_path(&self.name)
name_from_path(&self.ident)
}

pub fn value_str(&self) -> Option<Symbol> {
Expand Down Expand Up @@ -315,7 +315,7 @@ impl Attribute {
pub fn meta(&self) -> Option<MetaItem> {
let mut tokens = self.tokens.trees().peekable();
Some(MetaItem {
name: self.path.clone(),
ident: self.path.clone(),
node: if let Some(node) = MetaItemKind::from_tokens(&mut tokens) {
if tokens.peek().is_some() {
return None;
Expand Down Expand Up @@ -361,7 +361,7 @@ impl Attribute {

pub fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> {
Ok(MetaItem {
name: self.path.clone(),
ident: self.path.clone(),
node: self.parse(sess, |parser| parser.parse_meta_item_kind())?,
span: self.span,
})
Expand Down Expand Up @@ -399,41 +399,19 @@ pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem
}

pub fn mk_name_value_item(span: Span, ident: Ident, value: ast::Lit) -> MetaItem {
MetaItem { ident, span, node: MetaItemKind::NameValue(value) }
MetaItem { ident: ast::Path::from_ident(ident), span, node: MetaItemKind::NameValue(value) }
}

pub fn mk_list_item(span: Span, ident: Ident, items: Vec<NestedMetaItem>) -> MetaItem {
MetaItem { ident, span, node: MetaItemKind::List(items) }
MetaItem { ident: ast::Path::from_ident(ident), span, node: MetaItemKind::List(items) }
}

pub fn mk_word_item(ident: Ident) -> MetaItem {
MetaItem { ident, span: ident.span, node: MetaItemKind::Word }
MetaItem { ident: ast::Path::from_ident(ident), span: ident.span, node: MetaItemKind::Word }
}

pub fn mk_word_item(name: Name) -> MetaItem {
mk_spanned_word_item(DUMMY_SP, name)
}

macro_rules! mk_spanned_meta_item {
($sp:ident, $name:ident, $node:expr) => {
MetaItem {
span: $sp,
name: ast::Path::from_ident($sp, ast::Ident::with_empty_ctxt($name)),
node: $node,
}
}
}

pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> MetaItem {
mk_spanned_meta_item!(sp, name, MetaItemKind::NameValue(value))
}

pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> MetaItem {
mk_spanned_meta_item!(sp, name, MetaItemKind::List(items))
}

pub fn mk_spanned_word_item(sp: Span, name: Name) -> MetaItem {
mk_spanned_meta_item!(sp, name, MetaItemKind::Word)
pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem {
respan(ident.span, NestedMetaItemKind::MetaItem(mk_word_item(ident)))
}

pub fn mk_attr_id() -> AttrId {
Expand All @@ -457,7 +435,7 @@ pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: MetaItem) -> Attribute
Attribute {
id,
style: ast::AttrStyle::Inner,
path: item.name,
path: item.ident,
tokens: item.node.tokens(item.span),
is_sugared_doc: false,
span: sp,
Expand All @@ -475,7 +453,7 @@ pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: MetaItem) -> Attribute
Attribute {
id,
style: ast::AttrStyle::Outer,
path: item.name,
path: item.ident,
tokens: item.node.tokens(item.span),
is_sugared_doc: false,
span: sp,
Expand Down Expand Up @@ -1082,7 +1060,7 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
}
} else {
if let Some(meta_item) = item.meta_item() {
if meta_item.ident.name == "align" {
if meta_item.name() == "align" {
if let MetaItemKind::NameValue(ref value) = meta_item.node {
recognised = true;
let mut err = struct_span_err!(diagnostic, item.span, E0693,
Expand Down Expand Up @@ -1165,14 +1143,17 @@ impl MetaItem {
let mut idents = vec![];
let mut last_pos = BytePos(0 as u32);
// FIXME: Share code with `parse_path`.
for (i, segment) in self.name.segments.iter().enumerate() {
for (i, segment) in self.ident.segments.iter().enumerate() {
let is_first = i == 0;
if !is_first {
let mod_sep_span = Span::new(last_pos, segment.span.lo(), segment.span.ctxt());
let mod_sep_span = Span::new(last_pos,
segment.ident.span.lo(),
segment.ident.span.ctxt());
idents.push(TokenTree::Token(mod_sep_span, Token::ModSep).into());
}
idents.push(TokenTree::Token(segment.span, Token::Ident(segment.identifier)).into());
last_pos = segment.span.hi();
idents.push(TokenTree::Token(segment.ident.span,
Token::from_ast_ident(segment.ident)).into());
last_pos = segment.ident.span.hi();
}
idents.push(self.node.tokens(self.span));
TokenStream::concat(idents)
Expand All @@ -1181,14 +1162,14 @@ impl MetaItem {
fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItem>
where I: Iterator<Item = TokenTree>,
{
let name = match tokens.next() {
Some(TokenTree::Token(span, Token::Ident(ident))) => {
let ident = match tokens.next() {
Some(TokenTree::Token(span, Token::Ident(ident, _))) => {
if let Some(TokenTree::Token(_, Token::ModSep)) = tokens.peek() {
tokens.next();
let mut segments = vec![];
loop {
if let Some(TokenTree::Token(span, Token::Ident(ident))) = tokens.next() {
segments.push(ast::PathSegment::from_ident(ident, span));
if let Some(TokenTree::Token(_, Token::Ident(ident, _))) = tokens.next() {
segments.push(ast::PathSegment::from_ident(ident));
} else {
return None;
}
Expand All @@ -1200,12 +1181,12 @@ impl MetaItem {
}
ast::Path { span, segments }
} else {
ast::Path::from_ident(span, ident)
ast::Path::from_ident(ident)
}
}
Some(TokenTree::Token(_, Token::Interpolated(ref nt))) => match nt.0 {
token::Nonterminal::NtIdent(ident) => {
ast::Path::from_ident(ident.span, ident.node)
token::Nonterminal::NtIdent(ident, _) => {
ast::Path::from_ident(ident)
}
token::Nonterminal::NtMeta(ref meta) => return Some(meta.clone()),
token::Nonterminal::NtPath(ref path) => path.clone(),
Expand All @@ -1217,11 +1198,11 @@ impl MetaItem {
let node = MetaItemKind::from_tokens(tokens)?;
let hi = match node {
MetaItemKind::NameValue(ref lit) => lit.span.hi(),
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(name.span.hi()),
_ => name.span.hi(),
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(ident.span.hi()),
_ => ident.span.hi(),
};
let span = name.span.with_hi(hi);
Some(MetaItem { name, node, span })
let span = ident.span.with_hi(hi);
Some(MetaItem { ident, node, span })
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
invoc.expansion_data.mark.set_expn_info(expn_info);
let span = span.with_ctxt(self.cx.backtrace());
let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this
name: Path::from_ident(DUMMY_SP, keywords::Invalid.ident()),
ident: Path::from_ident(keywords::Invalid.ident()),
span: DUMMY_SP,
node: ast::MetaItemKind::Word,
};
Expand Down
Loading

0 comments on commit 121abd0

Please sign in to comment.