Skip to content

Commit b97487b

Browse files
Add check for doc alias attribute format
1 parent 698c5c6 commit b97487b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/librustdoc/clean/types.rs

+28
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,33 @@ impl Attributes {
481481
})
482482
}
483483

484+
/// Enforce the format of attributes inside `#[doc(...)]`.
485+
pub fn check_doc_attributes(
486+
diagnostic: &::rustc_errors::Handler,
487+
mi: &ast::MetaItem,
488+
) -> Option<(String, String)> {
489+
mi.meta_item_list().and_then(|list| {
490+
for meta in list {
491+
if meta.check_name(sym::alias) {
492+
if !meta.is_value_str()
493+
|| meta
494+
.value_str()
495+
.map(|s| s.to_string())
496+
.unwrap_or_else(String::new)
497+
.is_empty()
498+
{
499+
diagnostic.span_err(
500+
meta.span(),
501+
"doc alias attribute expects a string: #[doc(alias = \"0\")]",
502+
);
503+
}
504+
}
505+
}
506+
507+
None
508+
})
509+
}
510+
484511
pub fn has_doc_flag(&self, flag: Symbol) -> bool {
485512
for attr in &self.other_attrs {
486513
if !attr.check_name(sym::doc) {
@@ -524,6 +551,7 @@ impl Attributes {
524551
} else {
525552
if attr.check_name(sym::doc) {
526553
if let Some(mi) = attr.meta() {
554+
Attributes::check_doc_attributes(&diagnostic, &mi);
527555
if let Some(cfg_mi) = Attributes::extract_cfg(&mi) {
528556
// Extracted #[doc(cfg(...))]
529557
match Cfg::parse(cfg_mi) {

0 commit comments

Comments
 (0)