@@ -292,6 +292,45 @@ impl ToolchainComponents {
292
292
}
293
293
}
294
294
295
+ #[ derive( Clone , Copy ) ]
296
+ pub struct ToolchainConfig < ' a > {
297
+ rustdoc : Option < & ' a Path > ,
298
+ clippy : Option < & ' a Path > ,
299
+ cargo : Option < & ' a Path > ,
300
+ id : Option < & ' a str > ,
301
+ }
302
+
303
+ impl < ' a > ToolchainConfig < ' a > {
304
+ pub fn default ( ) -> Self {
305
+ Self {
306
+ rustdoc : None ,
307
+ clippy : None ,
308
+ cargo : None ,
309
+ id : None
310
+ }
311
+ }
312
+
313
+ pub fn rustdoc ( & mut self , rustdoc : Option < & ' a Path > ) -> & mut Self {
314
+ self . rustdoc = rustdoc;
315
+ self
316
+ }
317
+
318
+ pub fn clippy ( & mut self , clippy : Option < & ' a Path > ) -> & mut Self {
319
+ self . clippy = clippy;
320
+ self
321
+ }
322
+
323
+ pub fn cargo ( & mut self , cargo : Option < & ' a Path > ) -> & mut Self {
324
+ self . cargo = cargo;
325
+ self
326
+ }
327
+
328
+ pub fn id ( & mut self , id : Option < & ' a str > ) -> & mut Self {
329
+ self . id = id;
330
+ self
331
+ }
332
+ }
333
+
295
334
/// Get a toolchain from the input.
296
335
/// - `rustc`: check if the given one is acceptable.
297
336
/// - `rustdoc`: if one is given, check if it is acceptable. Otherwise, if
@@ -301,10 +340,7 @@ impl ToolchainComponents {
301
340
pub fn get_local_toolchain (
302
341
profiles : & [ Profile ] ,
303
342
rustc : & str ,
304
- rustdoc : Option < & Path > ,
305
- clippy : Option < & Path > ,
306
- cargo : Option < & Path > ,
307
- id : Option < & str > ,
343
+ toolchain_config : ToolchainConfig < ' _ > ,
308
344
id_suffix : & str ,
309
345
target_triple : String ,
310
346
) -> anyhow:: Result < Toolchain > {
@@ -359,7 +395,7 @@ pub fn get_local_toolchain(
359
395
debug ! ( "found rustc: {:?}" , & rustc) ;
360
396
361
397
// When the id comes from a +toolchain, the suffix is *not* added.
362
- let id = if let Some ( id) = id {
398
+ let id = if let Some ( id) = toolchain_config . id {
363
399
let mut id = id. to_owned ( ) ;
364
400
id. push_str ( id_suffix) ;
365
401
id
@@ -374,7 +410,7 @@ pub fn get_local_toolchain(
374
410
375
411
// When specifying rustc via a path, the suffix is always added to the
376
412
// id.
377
- let mut id = if let Some ( id) = id {
413
+ let mut id = if let Some ( id) = toolchain_config . id {
378
414
id. to_owned ( )
379
415
} else {
380
416
"Id" . to_string ( )
@@ -385,7 +421,7 @@ pub fn get_local_toolchain(
385
421
} ;
386
422
387
423
let rustdoc =
388
- if let Some ( rustdoc) = & rustdoc {
424
+ if let Some ( rustdoc) = & toolchain_config . rustdoc {
389
425
Some ( rustdoc. canonicalize ( ) . with_context ( || {
390
426
format ! ( "failed to canonicalize rustdoc executable {:?}" , rustdoc)
391
427
} ) ?)
@@ -406,7 +442,7 @@ pub fn get_local_toolchain(
406
442
} ;
407
443
408
444
let clippy =
409
- if let Some ( clippy) = & clippy {
445
+ if let Some ( clippy) = & toolchain_config . clippy {
410
446
Some ( clippy. canonicalize ( ) . with_context ( || {
411
447
format ! ( "failed to canonicalize clippy executable {:?}" , clippy)
412
448
} ) ?)
@@ -425,7 +461,7 @@ pub fn get_local_toolchain(
425
461
// No `clippy` provided, but none needed.
426
462
None
427
463
} ;
428
- let cargo = if let Some ( cargo) = & cargo {
464
+ let cargo = if let Some ( cargo) = & toolchain_config . cargo {
429
465
cargo
430
466
. canonicalize ( )
431
467
. with_context ( || format ! ( "failed to canonicalize cargo executable {:?}" , cargo) ) ?
0 commit comments