File tree 1 file changed +43
-2
lines changed
compiler/rustc_passes/src
1 file changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -717,6 +717,42 @@ impl CheckAttrVisitor<'tcx> {
717
717
true
718
718
}
719
719
720
+ /// Checks that `doc(test(...))` attribute contains only valid attributes. Returns `true` if
721
+ /// valid.
722
+ fn check_test_attr ( & self , meta : & NestedMetaItem , hir_id : HirId ) -> bool {
723
+ let mut is_valid = true ;
724
+ if let Some ( metas) = meta. meta_item_list ( ) {
725
+ for i_meta in metas {
726
+ match i_meta. name_or_empty ( ) {
727
+ sym:: attr | sym:: no_crate_inject => { }
728
+ _ => {
729
+ self . tcx . struct_span_lint_hir (
730
+ INVALID_DOC_ATTRIBUTES ,
731
+ hir_id,
732
+ i_meta. span ( ) ,
733
+ |lint| {
734
+ lint. build ( & format ! (
735
+ "unknown `doc(test)` attribute `{}`" ,
736
+ rustc_ast_pretty:: pprust:: path_to_string(
737
+ & i_meta. meta_item( ) . unwrap( ) . path
738
+ ) ,
739
+ ) )
740
+ . emit ( ) ;
741
+ } ,
742
+ ) ;
743
+ is_valid = false ;
744
+ }
745
+ }
746
+ }
747
+ } else {
748
+ self . tcx . struct_span_lint_hir ( INVALID_DOC_ATTRIBUTES , hir_id, meta. span ( ) , |lint| {
749
+ lint. build ( "`#[doc(test(...)]` takes a list of attributes" ) . emit ( ) ;
750
+ } ) ;
751
+ is_valid = false ;
752
+ }
753
+ is_valid
754
+ }
755
+
720
756
/// Runs various checks on `#[doc]` attributes. Returns `true` if valid.
721
757
///
722
758
/// `specified_inline` should be initialized to `None` and kept for the scope
@@ -793,8 +829,13 @@ impl CheckAttrVisitor<'tcx> {
793
829
| sym:: no_inline
794
830
| sym:: notable_trait
795
831
| sym:: passes
796
- | sym:: plugins
797
- | sym:: test => { }
832
+ | sym:: plugins => { }
833
+
834
+ sym:: test => {
835
+ if !self . check_test_attr ( & meta, hir_id) {
836
+ is_valid = false ;
837
+ }
838
+ }
798
839
799
840
sym:: primitive => {
800
841
if !self . tcx . features ( ) . doc_primitive {
You can’t perform that action at this time.
0 commit comments