File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,8 @@ passes_doc_keyword_only_impl =
214
214
passes_doc_test_takes_list =
215
215
`#[doc(test(...)]` takes a list of attributes
216
216
217
+ passes_doc_test_literal = `#![doc(test(...)]` does not take a literal
218
+
217
219
passes_doc_test_unknown =
218
220
unknown `doc(test)` attribute `{ $path } `
219
221
Original file line number Diff line number Diff line change @@ -944,21 +944,28 @@ impl CheckAttrVisitor<'_> {
944
944
let mut is_valid = true ;
945
945
if let Some ( metas) = meta. meta_item_list ( ) {
946
946
for i_meta in metas {
947
- match i_meta. name_or_empty ( ) {
948
- sym:: attr | sym:: no_crate_inject => { }
949
- _ => {
947
+ match ( i_meta. name_or_empty ( ) , i_meta . meta_item ( ) ) {
948
+ ( sym:: attr | sym:: no_crate_inject, _ ) => { }
949
+ ( _ , Some ( m ) ) => {
950
950
self . tcx . emit_spanned_lint (
951
951
INVALID_DOC_ATTRIBUTES ,
952
952
hir_id,
953
953
i_meta. span ( ) ,
954
954
errors:: DocTestUnknown {
955
- path : rustc_ast_pretty:: pprust:: path_to_string (
956
- & i_meta. meta_item ( ) . unwrap ( ) . path ,
957
- ) ,
955
+ path : rustc_ast_pretty:: pprust:: path_to_string ( & m. path ) ,
958
956
} ,
959
957
) ;
960
958
is_valid = false ;
961
959
}
960
+ ( _, None ) => {
961
+ self . tcx . emit_spanned_lint (
962
+ INVALID_DOC_ATTRIBUTES ,
963
+ hir_id,
964
+ i_meta. span ( ) ,
965
+ errors:: DocTestLiteral ,
966
+ ) ;
967
+ is_valid = false ;
968
+ }
962
969
}
963
970
}
964
971
} else {
Original file line number Diff line number Diff line change @@ -281,6 +281,10 @@ pub struct DocTestUnknown {
281
281
pub path : String ,
282
282
}
283
283
284
+ #[ derive( LintDiagnostic ) ]
285
+ #[ diag( passes_doc_test_literal) ]
286
+ pub struct DocTestLiteral ;
287
+
284
288
#[ derive( LintDiagnostic ) ]
285
289
#[ diag( passes_doc_test_takes_list) ]
286
290
pub struct DocTestTakesList ;
You can’t perform that action at this time.
0 commit comments