@@ -45,16 +45,22 @@ impl Level {
45
45
}
46
46
}
47
47
48
+ #[ derive( Copy , Clone ) ]
49
+ pub struct Rustc < ' a > {
50
+ pub path : & ' a Path ,
51
+ pub target : & ' a str ,
52
+ }
53
+
48
54
/// Collects all lints, and writes the markdown documentation at the given directory.
49
55
pub fn extract_lint_docs (
50
56
src_path : & Path ,
51
57
out_path : & Path ,
52
- rustc_path : & Path ,
58
+ rustc : Rustc < ' _ > ,
53
59
verbose : bool ,
54
60
) -> Result < ( ) , Box < dyn Error > > {
55
61
let mut lints = gather_lints ( src_path) ?;
56
62
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| {
58
64
format ! (
59
65
"failed to test example in lint docs for `{}` in {}:{}: {}" ,
60
66
lint. name,
@@ -65,7 +71,7 @@ pub fn extract_lint_docs(
65
71
} ) ?;
66
72
}
67
73
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) ?;
69
75
Ok ( ( ) )
70
76
}
71
77
@@ -208,7 +214,7 @@ fn lint_name(line: &str) -> Result<String, &'static str> {
208
214
/// actual output from the compiler.
209
215
fn generate_output_example (
210
216
lint : & mut Lint ,
211
- rustc_path : & Path ,
217
+ rustc : Rustc < ' _ > ,
212
218
verbose : bool ,
213
219
) -> Result < ( ) , Box < dyn Error > > {
214
220
// Explicit list of lints that are allowed to not have an example. Please
@@ -230,7 +236,7 @@ fn generate_output_example(
230
236
// separate test suite, and use an include mechanism such as mdbook's
231
237
// `{{#rustdoc_include}}`.
232
238
if !lint. is_ignored ( ) {
233
- replace_produces ( lint, rustc_path , verbose) ?;
239
+ replace_produces ( lint, rustc , verbose) ?;
234
240
}
235
241
Ok ( ( ) )
236
242
}
@@ -261,7 +267,7 @@ fn check_style(lint: &Lint) -> Result<(), Box<dyn Error>> {
261
267
/// output from the compiler.
262
268
fn replace_produces (
263
269
lint : & mut Lint ,
264
- rustc_path : & Path ,
270
+ rustc : Rustc < ' _ > ,
265
271
verbose : bool ,
266
272
) -> Result < ( ) , Box < dyn Error > > {
267
273
let mut lines = lint. doc . iter_mut ( ) ;
@@ -302,7 +308,7 @@ fn replace_produces(
302
308
Some ( line) if line. is_empty ( ) => { }
303
309
Some ( line) if line == "{{produces}}" => {
304
310
let output =
305
- generate_lint_output ( & lint. name , & example, & options, rustc_path , verbose) ?;
311
+ generate_lint_output ( & lint. name , & example, & options, rustc , verbose) ?;
306
312
line. replace_range (
307
313
..,
308
314
& format ! (
@@ -329,7 +335,7 @@ fn generate_lint_output(
329
335
name : & str ,
330
336
example : & [ & mut String ] ,
331
337
options : & [ & str ] ,
332
- rustc_path : & Path ,
338
+ rustc : Rustc < ' _ > ,
333
339
verbose : bool ,
334
340
) -> Result < String , Box < dyn Error > > {
335
341
if verbose {
@@ -364,13 +370,14 @@ fn generate_lint_output(
364
370
}
365
371
fs:: write ( & tempfile, source)
366
372
. 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 ) ;
368
374
if options. contains ( & "edition2015" ) {
369
375
cmd. arg ( "--edition=2015" ) ;
370
376
} else {
371
377
cmd. arg ( "--edition=2018" ) ;
372
378
}
373
379
cmd. arg ( "--error-format=json" ) ;
380
+ cmd. arg ( "--target" ) . arg ( rustc. target ) ;
374
381
if options. contains ( & "test" ) {
375
382
cmd. arg ( "--test" ) ;
376
383
}
0 commit comments