Skip to content

Commit d1a3371

Browse files
committed
Fix following removal of Attribute.value
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.
1 parent f4018a4 commit d1a3371

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/plugins/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ extern crate syntax;
77
use itertools::Itertools;
88
use rustc_plugin::Registry;
99
use syntax::ast::{self, Ident, TraitRef, Ty, TyKind};
10+
use syntax::ast::{MetaItem, MetaItemKind};
1011
use syntax::ast::LitKind::Str;
11-
use syntax::ast::MetaItemKind::NameValue;
1212
use syntax::codemap::Spanned;
1313
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
1414
use syntax::ext::quote::rt::Span;
@@ -46,11 +46,17 @@ fn snake_to_camel(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResul
4646
// (NameValues), filtering out non-doc attributes, and replacing any {} in the doc string with
4747
// the original, snake_case ident.
4848
for attr in item.attrs.iter_mut().filter(|attr| attr.is_sugared_doc) {
49-
if let NameValue(Spanned { node: Str(ref mut doc, _), .. }) = attr.value.node {
50-
*doc = Symbol::intern(&doc.as_str().replace("{}", &old_ident));
49+
// We need to extract the firsts element in the token stream.
50+
let meta = attr.meta();
51+
if let Some(MetaItem { mut node, .. }) = meta {
52+
if let MetaItemKind::NameValue(Spanned { node: Str(ref mut doc, _), .. }) = node {
53+
*doc = Symbol::intern(&doc.as_str().replace("{}", &old_ident));
54+
} else {
55+
unreachable!();
56+
}
5157
} else {
52-
unreachable!()
53-
};
58+
unreachable!();
59+
}
5460
}
5561

5662
MacEager::trait_items(SmallVector::one(item))

0 commit comments

Comments
 (0)