Skip to content

Commit f0c9aa3

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 f0c9aa3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/plugins/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ 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;
15-
use syntax::parse::{self, token, PResult};
15+
use syntax::parse::{self, token, str_lit, PResult};
1616
use syntax::parse::parser::{Parser, PathStyle};
1717
use syntax::symbol::Symbol;
1818
use syntax::ptr::P;
@@ -46,11 +46,18 @@ 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 mut tokens = attr.tokens.trees();
51+
if let Some(TokenTree::Token(_, token::Eq)) = tokens.next() {
52+
let mut docstr = tokens.next().expect("Docstrings must have literal docstring");
53+
if let TokenTree::Token(_, token::Literal(token::Str_(ref mut doc), _)) = docstr {
54+
*doc = Symbol::intern(&str_lit(&doc.as_str()).replace("{}", &old_ident));
55+
} else {
56+
unreachable!();
57+
}
5158
} else {
52-
unreachable!()
53-
};
59+
unreachable!();
60+
}
5461
}
5562

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

0 commit comments

Comments
 (0)