@@ -59,6 +59,8 @@ pub struct LintExtractor<'a> {
59
59
pub rustc_target : & ' a str ,
60
60
/// The target linker overriding `rustc`'s default
61
61
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 ,
62
64
/// Verbose output.
63
65
pub verbose : bool ,
64
66
/// Validate the style and the code example.
@@ -216,14 +218,7 @@ impl<'a> LintExtractor<'a> {
216
218
if let Some ( text) = line. strip_prefix ( "/// " ) {
217
219
doc_lines. push ( text. to_string ( ) ) ;
218
220
} 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) ;
227
222
doc_lines. push ( buf) ;
228
223
} else if line == "///" {
229
224
doc_lines. push ( "" . to_string ( ) ) ;
@@ -234,6 +229,20 @@ impl<'a> LintExtractor<'a> {
234
229
// Ignore allow of lints (useful for
235
230
// invalid_rust_codeblocks).
236
231
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
+ }
237
246
} else {
238
247
let name = lint_name ( line) . map_err ( |e| {
239
248
format ! (
@@ -580,6 +589,23 @@ impl<'a> LintExtractor<'a> {
580
589
}
581
590
}
582
591
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
+
583
609
/// Adds `Lint`s that have been renamed.
584
610
fn add_renamed_lints ( lints : & mut Vec < Lint > ) {
585
611
for ( level, names) in RENAMES {
0 commit comments