Allow to have any valid ident used as keyword in doc_keyword feature

This commit is contained in:
Guillaume Gomez 2020-11-27 14:27:59 +01:00
parent 53d19b37c5
commit f663093222

View File

@ -162,18 +162,30 @@ fn clean(&self, cx: &DocContext<'_>) -> ExternalCrate {
.collect()
};
let get_span =
|attr: &ast::NestedMetaItem| Some(attr.meta_item()?.name_value_literal()?.span);
let as_keyword = |res: Res| {
if let Res::Def(DefKind::Mod, def_id) = res {
let attrs = cx.tcx.get_attrs(def_id).clean(cx);
let mut keyword = None;
for attr in attrs.lists(sym::doc) {
if let Some(v) = attr.value_str() {
if attr.has_name(sym::keyword) {
if v.is_doc_keyword() {
keyword = Some(v.to_string());
break;
if attr.has_name(sym::keyword) {
if let Some(v) = attr.value_str() {
let k = v.to_string();
if !rustc_lexer::is_ident(&k) {
let sp = get_span(&attr).unwrap_or_else(|| attr.span());
cx.tcx
.sess
.struct_span_err(
sp,
&format!("`{}` is not a valid identifier", v),
)
.emit();
} else {
keyword = Some(k);
}
// FIXME: should warn on unknown keywords?
break;
}
}
}