Skip to content

Commit

Permalink
Fix following removal of Attribute.value
Browse files Browse the repository at this point in the history
Since rust-lang/rust#40346 has now been merged, Attribute no longer has
a .value field. Instead, we must follow the token stream and modify the
tokens directly. For Docstring attributes, there should only be one
token, the docstring value.
  • Loading branch information
jonhoo committed Mar 21, 2017
1 parent f4018a4 commit f0c9aa3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ extern crate syntax;
use itertools::Itertools;
use rustc_plugin::Registry;
use syntax::ast::{self, Ident, TraitRef, Ty, TyKind};
use syntax::ast::{MetaItem, MetaItemKind};
use syntax::ast::LitKind::Str;
use syntax::ast::MetaItemKind::NameValue;
use syntax::codemap::Spanned;
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::quote::rt::Span;
use syntax::parse::{self, token, PResult};
use syntax::parse::{self, token, str_lit, PResult};
use syntax::parse::parser::{Parser, PathStyle};
use syntax::symbol::Symbol;
use syntax::ptr::P;
Expand Down Expand Up @@ -46,11 +46,18 @@ fn snake_to_camel(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResul
// (NameValues), filtering out non-doc attributes, and replacing any {} in the doc string with
// the original, snake_case ident.
for attr in item.attrs.iter_mut().filter(|attr| attr.is_sugared_doc) {
if let NameValue(Spanned { node: Str(ref mut doc, _), .. }) = attr.value.node {
*doc = Symbol::intern(&doc.as_str().replace("{}", &old_ident));
// We need to extract the firsts element in the token stream.
let mut tokens = attr.tokens.trees();
if let Some(TokenTree::Token(_, token::Eq)) = tokens.next() {
let mut docstr = tokens.next().expect("Docstrings must have literal docstring");
if let TokenTree::Token(_, token::Literal(token::Str_(ref mut doc), _)) = docstr {
*doc = Symbol::intern(&str_lit(&doc.as_str()).replace("{}", &old_ident));
} else {
unreachable!();
}
} else {
unreachable!()
};
unreachable!();
}
}

MacEager::trait_items(SmallVector::one(item))
Expand Down

0 comments on commit f0c9aa3

Please sign in to comment.