@@ -59,6 +59,8 @@ pub struct LintExtractor<'a> {
5959 pub rustc_target : & ' a str ,
6060 /// The target linker overriding `rustc`'s default
6161 pub rustc_linker : Option < & ' a str > ,
62+ /// Stage of the compiler that builds the docs (the stage of `rustc_path`).
63+ pub build_rustc_stage : u32 ,
6264 /// Verbose output.
6365 pub verbose : bool ,
6466 /// Validate the style and the code example.
@@ -216,14 +218,7 @@ impl<'a> LintExtractor<'a> {
216218 if let Some ( text) = line. strip_prefix ( "/// " ) {
217219 doc_lines. push ( text. to_string ( ) ) ;
218220 } else if let Some ( text) = line. strip_prefix ( "#[doc = \" " ) {
219- let escaped = text. strip_suffix ( "\" ]" ) . unwrap ( ) ;
220- let mut buf = String :: new ( ) ;
221- unescape_str ( escaped, |_, res| match res {
222- Ok ( c) => buf. push ( c) ,
223- Err ( err) => {
224- assert ! ( !err. is_fatal( ) , "failed to unescape string literal" )
225- }
226- } ) ;
221+ let buf = parse_doc_string ( text) ;
227222 doc_lines. push ( buf) ;
228223 } else if line == "///" {
229224 doc_lines. push ( "" . to_string ( ) ) ;
@@ -234,6 +229,20 @@ impl<'a> LintExtractor<'a> {
234229 // Ignore allow of lints (useful for
235230 // invalid_rust_codeblocks).
236231 continue ;
232+ } else if let Some ( text) =
233+ line. strip_prefix ( "#[cfg_attr(not(bootstrap), doc = \" " )
234+ {
235+ if self . build_rustc_stage >= 1 {
236+ let buf = parse_doc_string ( text) ;
237+ doc_lines. push ( buf) ;
238+ }
239+ } else if let Some ( text) =
240+ line. strip_prefix ( "#[cfg_attr(bootstrap, doc = \" " )
241+ {
242+ if self . build_rustc_stage == 0 {
243+ let buf = parse_doc_string ( text) ;
244+ doc_lines. push ( buf) ;
245+ }
237246 } else {
238247 let name = lint_name ( line) . map_err ( |e| {
239248 format ! (
@@ -580,6 +589,23 @@ impl<'a> LintExtractor<'a> {
580589 }
581590}
582591
592+ /// Parses a doc string that follows `#[doc = "`.
593+ fn parse_doc_string ( text : & str ) -> String {
594+ let escaped = text. strip_suffix ( "]" ) . unwrap_or ( text) ;
595+ let escaped = escaped. strip_suffix ( ")" ) . unwrap_or ( escaped) . strip_suffix ( "\" " ) ;
596+ let Some ( escaped) = escaped else {
597+ panic ! ( "Cannot extract docstring content from {text}" ) ;
598+ } ;
599+ let mut buf = String :: new ( ) ;
600+ unescape_str ( escaped, |_, res| match res {
601+ Ok ( c) => buf. push ( c) ,
602+ Err ( err) => {
603+ assert ! ( !err. is_fatal( ) , "failed to unescape string literal" )
604+ }
605+ } ) ;
606+ buf
607+ }
608+
583609/// Adds `Lint`s that have been renamed.
584610fn add_renamed_lints ( lints : & mut Vec < Lint > ) {
585611 for ( level, names) in RENAMES {
0 commit comments