Skip to content

Commit 48794b3

Browse files
authored
Rollup merge of rust-lang#74148 - GuillaumeGomez:doc-alias-check, r=Manishearth
Move #[doc(alias)] check in rustc Part of rust-lang#73721. r? @ollie27
2 parents ec4f4e1 + b0884c0 commit 48794b3

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

src/librustc_passes/check_attr.rs

+30
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ impl CheckAttrVisitor<'tcx> {
7070
self.check_target_feature(attr, span, target)
7171
} else if attr.check_name(sym::track_caller) {
7272
self.check_track_caller(&attr.span, attrs, span, target)
73+
} else if attr.check_name(sym::doc) {
74+
self.check_doc_alias(attr)
7375
} else {
7476
true
7577
};
@@ -216,6 +218,34 @@ impl CheckAttrVisitor<'tcx> {
216218
}
217219
}
218220

221+
fn check_doc_alias(&self, attr: &Attribute) -> bool {
222+
if let Some(mi) = attr.meta() {
223+
if let Some(list) = mi.meta_item_list() {
224+
for meta in list {
225+
if meta.check_name(sym::alias) {
226+
if !meta.is_value_str()
227+
|| meta
228+
.value_str()
229+
.map(|s| s.to_string())
230+
.unwrap_or_else(String::new)
231+
.is_empty()
232+
{
233+
self.tcx
234+
.sess
235+
.struct_span_err(
236+
meta.span(),
237+
"doc alias attribute expects a string: #[doc(alias = \"0\")]",
238+
)
239+
.emit();
240+
return false;
241+
}
242+
}
243+
}
244+
}
245+
}
246+
true
247+
}
248+
219249
/// Checks if the `#[repr]` attributes on `item` are valid.
220250
fn check_repr(
221251
&self,

src/librustdoc/clean/types.rs

-28
Original file line numberDiff line numberDiff line change
@@ -486,33 +486,6 @@ impl Attributes {
486486
})
487487
}
488488

489-
/// Enforce the format of attributes inside `#[doc(...)]`.
490-
pub fn check_doc_attributes(
491-
diagnostic: &::rustc_errors::Handler,
492-
mi: &ast::MetaItem,
493-
) -> Option<(String, String)> {
494-
mi.meta_item_list().and_then(|list| {
495-
for meta in list {
496-
if meta.check_name(sym::alias) {
497-
if !meta.is_value_str()
498-
|| meta
499-
.value_str()
500-
.map(|s| s.to_string())
501-
.unwrap_or_else(String::new)
502-
.is_empty()
503-
{
504-
diagnostic.span_err(
505-
meta.span(),
506-
"doc alias attribute expects a string: #[doc(alias = \"0\")]",
507-
);
508-
}
509-
}
510-
}
511-
512-
None
513-
})
514-
}
515-
516489
pub fn has_doc_flag(&self, flag: Symbol) -> bool {
517490
for attr in &self.other_attrs {
518491
if !attr.check_name(sym::doc) {
@@ -556,7 +529,6 @@ impl Attributes {
556529
} else {
557530
if attr.check_name(sym::doc) {
558531
if let Some(mi) = attr.meta() {
559-
Attributes::check_doc_attributes(&diagnostic, &mi);
560532
if let Some(cfg_mi) = Attributes::extract_cfg(&mi) {
561533
// Extracted #[doc(cfg(...))]
562534
match Cfg::parse(cfg_mi) {

src/test/rustdoc-ui/check-doc-alias-attr.rs src/test/ui/check-doc-alias-attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![crate_type = "lib"]
12
#![feature(doc_alias)]
23

34
#[doc(alias = "foo")] // ok!

src/test/rustdoc-ui/check-doc-alias-attr.stderr src/test/ui/check-doc-alias-attr.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: doc alias attribute expects a string: #[doc(alias = "0")]
2-
--> $DIR/check-doc-alias-attr.rs:6:7
2+
--> $DIR/check-doc-alias-attr.rs:7:7
33
|
44
LL | #[doc(alias)]
55
| ^^^^^
66

77
error: doc alias attribute expects a string: #[doc(alias = "0")]
8-
--> $DIR/check-doc-alias-attr.rs:7:7
8+
--> $DIR/check-doc-alias-attr.rs:8:7
99
|
1010
LL | #[doc(alias = 0)]
1111
| ^^^^^^^^^
1212

1313
error: doc alias attribute expects a string: #[doc(alias = "0")]
14-
--> $DIR/check-doc-alias-attr.rs:8:7
14+
--> $DIR/check-doc-alias-attr.rs:9:7
1515
|
1616
LL | #[doc(alias("bar"))]
1717
| ^^^^^^^^^^^^

0 commit comments

Comments
 (0)