Add check for doc alias attribute format

This commit is contained in:
Guillaume Gomez 2020-05-30 15:36:42 +02:00
parent 698c5c6d95
commit b97487bad8

View file

@ -481,6 +481,33 @@ impl Attributes {
})
}
/// Enforce the format of attributes inside `#[doc(...)]`.
pub fn check_doc_attributes(
diagnostic: &::rustc_errors::Handler,
mi: &ast::MetaItem,
) -> Option<(String, String)> {
mi.meta_item_list().and_then(|list| {
for meta in list {
if meta.check_name(sym::alias) {
if !meta.is_value_str()
|| meta
.value_str()
.map(|s| s.to_string())
.unwrap_or_else(String::new)
.is_empty()
{
diagnostic.span_err(
meta.span(),
"doc alias attribute expects a string: #[doc(alias = \"0\")]",
);
}
}
}
None
})
}
pub fn has_doc_flag(&self, flag: Symbol) -> bool {
for attr in &self.other_attrs {
if !attr.check_name(sym::doc) {
@ -524,6 +551,7 @@ impl Attributes {
} else {
if attr.check_name(sym::doc) {
if let Some(mi) = attr.meta() {
Attributes::check_doc_attributes(&diagnostic, &mi);
if let Some(cfg_mi) = Attributes::extract_cfg(&mi) {
// Extracted #[doc(cfg(...))]
match Cfg::parse(cfg_mi) {