@@ -21,6 +21,10 @@ pub(crate) const CHECK_CUSTOM_CODE_CLASSES: Pass = Pass {
21
21
} ;
22
22
23
23
pub ( crate ) fn check_custom_code_classes ( krate : Crate , cx : & mut DocContext < ' _ > ) -> Crate {
24
+ if cx. tcx . features ( ) . custom_code_classes_in_docs {
25
+ // Nothing to check here if the feature is enabled.
26
+ return krate;
27
+ }
24
28
let mut coll = CustomCodeClassLinter { cx } ;
25
29
26
30
coll. fold_crate ( krate)
@@ -40,49 +44,56 @@ impl<'a, 'tcx> DocFolder for CustomCodeClassLinter<'a, 'tcx> {
40
44
#[ derive( Debug ) ]
41
45
struct TestsWithCustomClasses {
42
46
custom_classes_found : Vec < String > ,
47
+ contains_dot : bool ,
43
48
}
44
49
45
50
impl crate :: doctest:: Tester for TestsWithCustomClasses {
46
51
fn add_test ( & mut self , _: String , config : LangString , _: usize ) {
52
+ self . contains_dot |= config. original . contains ( '.' ) ;
47
53
self . custom_classes_found . extend ( config. added_classes . into_iter ( ) ) ;
48
54
}
49
55
}
50
56
57
+ fn emit_warning ( cx : & DocContext < ' _ > , item : & Item , custom_classes : Option < & [ String ] > ) {
58
+ let span = item. attr_span ( cx. tcx ) ;
59
+ let sess = & cx. tcx . sess . parse_sess ;
60
+ let mut err = sess
61
+ . span_diagnostic
62
+ . struct_span_warn ( span, "custom classes in code blocks will change behaviour" ) ;
63
+ add_feature_diagnostics_for_issue (
64
+ & mut err,
65
+ sess,
66
+ sym:: custom_code_classes_in_docs,
67
+ GateIssue :: Language ,
68
+ false ,
69
+ ) ;
70
+
71
+ if let Some ( custom_classes) = custom_classes {
72
+ err. note (
73
+ // This will list the wrong items to make them more easily searchable.
74
+ // To ensure the most correct hits, it adds back the 'class:' that was stripped.
75
+ format ! ( "found these custom classes: class={}" , custom_classes. join( ",class=" ) ) ,
76
+ ) ;
77
+ }
78
+
79
+ // A later feature_err call can steal and cancel this warning.
80
+ err. stash ( span, StashKey :: EarlySyntaxWarning ) ;
81
+ }
82
+
51
83
pub ( crate ) fn look_for_custom_classes < ' tcx > ( cx : & DocContext < ' tcx > , item : & Item ) {
52
84
if !item. item_id . is_local ( ) {
53
85
// If non-local, no need to check anything.
54
86
return ;
55
87
}
56
88
57
- let mut tests = TestsWithCustomClasses { custom_classes_found : vec ! [ ] } ;
89
+ let mut tests = TestsWithCustomClasses { custom_classes_found : vec ! [ ] , contains_dot : false } ;
58
90
59
91
let dox = item. attrs . doc_value ( ) ;
60
92
find_codes ( & dox, & mut tests, ErrorCodes :: No , false , None , true , true ) ;
61
93
62
- if !tests. custom_classes_found . is_empty ( ) && !cx. tcx . features ( ) . custom_code_classes_in_docs {
63
- let span = item. attr_span ( cx. tcx ) ;
64
- let sess = & cx. tcx . sess . parse_sess ;
65
- let mut err = sess
66
- . span_diagnostic
67
- . struct_span_warn ( span, "custom classes in code blocks will change behaviour" ) ;
68
- add_feature_diagnostics_for_issue (
69
- & mut err,
70
- sess,
71
- sym:: custom_code_classes_in_docs,
72
- GateIssue :: Language ,
73
- false ,
74
- ) ;
75
-
76
- err. note (
77
- // This will list the wrong items to make them more easily searchable.
78
- // To ensure the most correct hits, it adds back the 'class:' that was stripped.
79
- format ! (
80
- "found these custom classes: class={}" ,
81
- tests. custom_classes_found. join( ",class=" )
82
- ) ,
83
- ) ;
84
-
85
- // A later feature_err call can steal and cancel this warning.
86
- err. stash ( span, StashKey :: EarlySyntaxWarning ) ;
94
+ if !tests. custom_classes_found . is_empty ( ) {
95
+ emit_warning ( cx, item, Some ( & tests. custom_classes_found ) ) ;
96
+ } else if tests. contains_dot {
97
+ emit_warning ( cx, item, None ) ;
87
98
}
88
99
}
0 commit comments