Rollup merge of #72780 - GuillaumeGomez:enforce-doc-alias-check, r=ollie27
Enforce doc alias check Part of #50146. r? @ollie27
This commit is contained in:
commit
7d2fba1bd2
@ -486,6 +486,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) {
|
||||
@ -529,6 +556,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) {
|
||||
|
9
src/test/rustdoc-ui/check-doc-alias-attr.rs
Normal file
9
src/test/rustdoc-ui/check-doc-alias-attr.rs
Normal file
@ -0,0 +1,9 @@
|
||||
#![feature(doc_alias)]
|
||||
|
||||
#[doc(alias = "foo")] // ok!
|
||||
pub struct Bar;
|
||||
|
||||
#[doc(alias)] //~ ERROR
|
||||
#[doc(alias = 0)] //~ ERROR
|
||||
#[doc(alias("bar"))] //~ ERROR
|
||||
pub struct Foo;
|
20
src/test/rustdoc-ui/check-doc-alias-attr.stderr
Normal file
20
src/test/rustdoc-ui/check-doc-alias-attr.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: doc alias attribute expects a string: #[doc(alias = "0")]
|
||||
--> $DIR/check-doc-alias-attr.rs:6:7
|
||||
|
|
||||
LL | #[doc(alias)]
|
||||
| ^^^^^
|
||||
|
||||
error: doc alias attribute expects a string: #[doc(alias = "0")]
|
||||
--> $DIR/check-doc-alias-attr.rs:7:7
|
||||
|
|
||||
LL | #[doc(alias = 0)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: doc alias attribute expects a string: #[doc(alias = "0")]
|
||||
--> $DIR/check-doc-alias-attr.rs:8:7
|
||||
|
|
||||
LL | #[doc(alias("bar"))]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user