File tree Expand file tree Collapse file tree 4 files changed +17
-6
lines changed
compiler/rustc_lint_defs/src Expand file tree Collapse file tree 4 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -2101,6 +2101,7 @@ dependencies = [
21012101name = " lint-docs"
21022102version = " 0.1.0"
21032103dependencies = [
2104+ " rustc-literal-escaper" ,
21042105 " serde_json" ,
21052106 " tempfile" ,
21062107 " walkdir" ,
Original file line number Diff line number Diff line change 77//! When removing a lint, make sure to also add a call to `register_removed` in
88//! compiler/rustc_lint/src/lib.rs.
99
10- #![ allow( text_direction_codepoint_in_literal) ]
11-
1210use rustc_span:: edition:: Edition ;
1311
1412use crate :: { FutureIncompatibilityReason , declare_lint, declare_lint_pass} ;
@@ -3795,7 +3793,7 @@ declare_lint! {
37953793 /// ```rust,compile_fail
37963794 /// #![deny(text_direction_codepoint_in_comment)]
37973795 /// fn main() {
3798- /// println!("{:?}"); // ' ');
3796+ # [ doc = " println!(\ " {:?}\ " ); // '\u{202E} ');" ]
37993797 /// }
38003798 /// ```
38013799 ///
@@ -3830,12 +3828,12 @@ declare_lint! {
38303828 ///
38313829 /// ### Example
38323830 ///
3833- /// ```rust,compile_fail
3831+ /// ```` rust,compile_fail
38343832 /// #![deny(text_direction_codepoint_in_literal)]
38353833 /// fn main() {
3836- /// println!("{:?}", ' ');
3834+ # [ doc = " println!(\ " {:?}\ " , '\u{202E} ');" ]
38373835 /// }
3838- /// ```
3836+ /// ````
38393837 ///
38403838 /// {{produces}}
38413839 ///
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."
77# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88
99[dependencies ]
10+ rustc-literal-escaper = " 0.0.2"
1011serde_json = " 1.0.57"
1112tempfile = " 3.1.0"
1213walkdir = " 2.3.1"
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use std::fs;
44use std:: path:: { Path , PathBuf } ;
55use std:: process:: Command ;
66
7+ use rustc_literal_escaper:: { Mode , unescape_unicode} ;
78use walkdir:: WalkDir ;
89
910mod groups;
@@ -214,6 +215,16 @@ impl<'a> LintExtractor<'a> {
214215 let line = line. trim ( ) ;
215216 if let Some ( text) = line. strip_prefix ( "/// " ) {
216217 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) ;
217228 } else if line == "///" {
218229 doc_lines. push ( "" . to_string ( ) ) ;
219230 } else if line. starts_with ( "// " ) {
You can’t perform that action at this time.
0 commit comments