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 20, 2017
1 parent f4018a4 commit d1a3371
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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;
Expand Down Expand Up @@ -46,11 +46,17 @@ 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 meta = attr.meta();
if let Some(MetaItem { mut node, .. }) = meta {
if let MetaItemKind::NameValue(Spanned { node: Str(ref mut doc, _), .. }) = node {
*doc = Symbol::intern(&doc.as_str().replace("{}", &old_ident));
} else {
unreachable!();
}
} else {
unreachable!()
};
unreachable!();
}
}

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

0 comments on commit d1a3371

Please sign in to comment.