File tree 4 files changed +15
-4
lines changed
compiler/rustc_lint_defs/src
4 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -2101,6 +2101,7 @@ dependencies = [
2101
2101
name = " lint-docs"
2102
2102
version = " 0.1.0"
2103
2103
dependencies = [
2104
+ " rustc-literal-escaper" ,
2104
2105
" serde_json" ,
2105
2106
" tempfile" ,
2106
2107
" walkdir" ,
Original file line number Diff line number Diff line change 7
7
//! When removing a lint, make sure to also add a call to `register_removed` in
8
8
//! compiler/rustc_lint/src/lib.rs.
9
9
10
- #![ allow( text_direction_codepoint_in_literal) ]
11
-
12
10
use rustc_span:: edition:: Edition ;
13
11
14
12
use crate :: { FutureIncompatibilityReason , declare_lint, declare_lint_pass} ;
@@ -3795,7 +3793,7 @@ declare_lint! {
3795
3793
/// ```rust,compile_fail
3796
3794
/// #![deny(text_direction_codepoint_in_comment)]
3797
3795
/// fn main() {
3798
- /// println!("{:?}"); // ' ');
3796
+ # [ doc = " println!(\ " {:?}\ " ); // '\u{202E} ');" ]
3799
3797
/// }
3800
3798
/// ```
3801
3799
///
@@ -3833,7 +3831,7 @@ declare_lint! {
3833
3831
/// ```rust,compile_fail
3834
3832
/// #![deny(text_direction_codepoint_in_literal)]
3835
3833
/// fn main() {
3836
- /// println!("{:?}", ' ');
3834
+ # [ doc = " println!(\ " {:?}\ " , '\u{202E} ');" ]
3837
3835
/// }
3838
3836
/// ```
3839
3837
///
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ description = "A script to extract the lint documentation for the rustc book."
7
7
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
8
9
9
[dependencies ]
10
+ rustc-literal-escaper = " 0.0.2"
10
11
serde_json = " 1.0.57"
11
12
tempfile = " 3.1.0"
12
13
walkdir = " 2.3.1"
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use std::fs;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
use std:: process:: Command ;
6
6
7
+ use rustc_literal_escaper:: { Mode , unescape_unicode} ;
7
8
use walkdir:: WalkDir ;
8
9
9
10
mod groups;
@@ -214,6 +215,16 @@ impl<'a> LintExtractor<'a> {
214
215
let line = line. trim ( ) ;
215
216
if let Some ( text) = line. strip_prefix ( "/// " ) {
216
217
doc_lines. push ( text. to_string ( ) ) ;
218
+ } else if let Some ( text) = line. strip_prefix ( "#[doc = \" " ) {
219
+ let escaped = text. strip_suffix ( "\" ]" ) . unwrap ( ) ;
220
+ let mut buf = String :: new ( ) ;
221
+ unescape_unicode ( escaped, Mode :: Str , & mut |_, c| match c {
222
+ Ok ( c) => buf. push ( c) ,
223
+ Err ( err) => {
224
+ assert ! ( !err. is_fatal( ) , "failed to unescape string literal" )
225
+ }
226
+ } ) ;
227
+ doc_lines. push ( buf) ;
217
228
} else if line == "///" {
218
229
doc_lines. push ( "" . to_string ( ) ) ;
219
230
} else if line. starts_with ( "// " ) {
You can’t perform that action at this time.
0 commit comments