@@ -45,16 +45,22 @@ impl Level {
4545 }
4646}
4747
48+ #[ derive( Copy , Clone ) ]
49+ pub struct Rustc < ' a > {
50+ pub path : & ' a Path ,
51+ pub target : & ' a str ,
52+ }
53+
4854/// Collects all lints, and writes the markdown documentation at the given directory.
4955pub fn extract_lint_docs (
5056 src_path : & Path ,
5157 out_path : & Path ,
52- rustc_path : & Path ,
58+ rustc : Rustc < ' _ > ,
5359 verbose : bool ,
5460) -> Result < ( ) , Box < dyn Error > > {
5561 let mut lints = gather_lints ( src_path) ?;
5662 for lint in & mut lints {
57- generate_output_example ( lint, rustc_path , verbose) . map_err ( |e| {
63+ generate_output_example ( lint, rustc , verbose) . map_err ( |e| {
5864 format ! (
5965 "failed to test example in lint docs for `{}` in {}:{}: {}" ,
6066 lint. name,
@@ -65,7 +71,7 @@ pub fn extract_lint_docs(
6571 } ) ?;
6672 }
6773 save_lints_markdown ( & lints, & out_path. join ( "listing" ) ) ?;
68- groups:: generate_group_docs ( & lints, rustc_path , out_path) ?;
74+ groups:: generate_group_docs ( & lints, rustc , out_path) ?;
6975 Ok ( ( ) )
7076}
7177
@@ -208,7 +214,7 @@ fn lint_name(line: &str) -> Result<String, &'static str> {
208214/// actual output from the compiler.
209215fn generate_output_example (
210216 lint : & mut Lint ,
211- rustc_path : & Path ,
217+ rustc : Rustc < ' _ > ,
212218 verbose : bool ,
213219) -> Result < ( ) , Box < dyn Error > > {
214220 // Explicit list of lints that are allowed to not have an example. Please
@@ -230,7 +236,7 @@ fn generate_output_example(
230236 // separate test suite, and use an include mechanism such as mdbook's
231237 // `{{#rustdoc_include}}`.
232238 if !lint. is_ignored ( ) {
233- replace_produces ( lint, rustc_path , verbose) ?;
239+ replace_produces ( lint, rustc , verbose) ?;
234240 }
235241 Ok ( ( ) )
236242}
@@ -261,7 +267,7 @@ fn check_style(lint: &Lint) -> Result<(), Box<dyn Error>> {
261267/// output from the compiler.
262268fn replace_produces (
263269 lint : & mut Lint ,
264- rustc_path : & Path ,
270+ rustc : Rustc < ' _ > ,
265271 verbose : bool ,
266272) -> Result < ( ) , Box < dyn Error > > {
267273 let mut lines = lint. doc . iter_mut ( ) ;
@@ -302,7 +308,7 @@ fn replace_produces(
302308 Some ( line) if line. is_empty ( ) => { }
303309 Some ( line) if line == "{{produces}}" => {
304310 let output =
305- generate_lint_output ( & lint. name , & example, & options, rustc_path , verbose) ?;
311+ generate_lint_output ( & lint. name , & example, & options, rustc , verbose) ?;
306312 line. replace_range (
307313 ..,
308314 & format ! (
@@ -329,7 +335,7 @@ fn generate_lint_output(
329335 name : & str ,
330336 example : & [ & mut String ] ,
331337 options : & [ & str ] ,
332- rustc_path : & Path ,
338+ rustc : Rustc < ' _ > ,
333339 verbose : bool ,
334340) -> Result < String , Box < dyn Error > > {
335341 if verbose {
@@ -364,13 +370,14 @@ fn generate_lint_output(
364370 }
365371 fs:: write ( & tempfile, source)
366372 . map_err ( |e| format ! ( "failed to write {}: {}" , tempfile. display( ) , e) ) ?;
367- let mut cmd = Command :: new ( rustc_path ) ;
373+ let mut cmd = Command :: new ( rustc . path ) ;
368374 if options. contains ( & "edition2015" ) {
369375 cmd. arg ( "--edition=2015" ) ;
370376 } else {
371377 cmd. arg ( "--edition=2018" ) ;
372378 }
373379 cmd. arg ( "--error-format=json" ) ;
380+ cmd. arg ( "--target" ) . arg ( rustc. target ) ;
374381 if options. contains ( & "test" ) {
375382 cmd. arg ( "--test" ) ;
376383 }
0 commit comments