File tree 3 files changed +57
-0
lines changed
3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -486,6 +486,33 @@ impl Attributes {
486
486
} )
487
487
}
488
488
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
+
489
516
pub fn has_doc_flag ( & self , flag : Symbol ) -> bool {
490
517
for attr in & self . other_attrs {
491
518
if !attr. check_name ( sym:: doc) {
@@ -529,6 +556,7 @@ impl Attributes {
529
556
} else {
530
557
if attr. check_name ( sym:: doc) {
531
558
if let Some ( mi) = attr. meta ( ) {
559
+ Attributes :: check_doc_attributes ( & diagnostic, & mi) ;
532
560
if let Some ( cfg_mi) = Attributes :: extract_cfg ( & mi) {
533
561
// Extracted #[doc(cfg(...))]
534
562
match Cfg :: parse ( cfg_mi) {
Original file line number Diff line number Diff line change
1
+ #![ feature( doc_alias) ]
2
+
3
+ #[ doc( alias = "foo" ) ] // ok!
4
+ pub struct Bar ;
5
+
6
+ #[ doc( alias) ] //~ ERROR
7
+ #[ doc( alias = 0 ) ] //~ ERROR
8
+ #[ doc( alias( "bar" ) ) ] //~ ERROR
9
+ pub struct Foo ;
Original file line number Diff line number Diff line change
1
+ error: doc alias attribute expects a string: #[doc(alias = "0")]
2
+ --> $DIR/check-doc-alias-attr.rs:6:7
3
+ |
4
+ LL | #[doc(alias)]
5
+ | ^^^^^
6
+
7
+ error: doc alias attribute expects a string: #[doc(alias = "0")]
8
+ --> $DIR/check-doc-alias-attr.rs:7:7
9
+ |
10
+ LL | #[doc(alias = 0)]
11
+ | ^^^^^^^^^
12
+
13
+ error: doc alias attribute expects a string: #[doc(alias = "0")]
14
+ --> $DIR/check-doc-alias-attr.rs:8:7
15
+ |
16
+ LL | #[doc(alias("bar"))]
17
+ | ^^^^^^^^^^^^
18
+
19
+ error: aborting due to 3 previous errors
20
+
You can’t perform that action at this time.
0 commit comments