6
6
//! Since `cargo config get` is not stable as of Rust 1.61, nextest must do its own config file
7
7
//! search.
8
8
9
- use crate :: errors:: {
10
- CargoConfigSearchError , CargoConfigsConstructError , InvalidCargoCliConfigReason ,
11
- TargetTripleError ,
12
- } ;
9
+ use crate :: errors:: { CargoConfigError , InvalidCargoCliConfigReason , TargetTripleError } ;
13
10
use camino:: { Utf8Path , Utf8PathBuf } ;
14
11
use once_cell:: sync:: OnceCell ;
15
12
use serde:: Deserialize ;
@@ -162,13 +159,12 @@ impl CargoConfigs {
162
159
/// Discover Cargo config files using the same algorithm that Cargo uses.
163
160
pub fn new (
164
161
cli_configs : impl IntoIterator < Item = impl AsRef < str > > ,
165
- ) -> Result < Self , CargoConfigsConstructError > {
162
+ ) -> Result < Self , CargoConfigError > {
166
163
let cli_configs = parse_cli_configs ( cli_configs. into_iter ( ) ) ?;
167
164
let cwd = std:: env:: current_dir ( )
168
- . map_err ( CargoConfigsConstructError :: GetCurrentDir )
165
+ . map_err ( CargoConfigError :: GetCurrentDir )
169
166
. and_then ( |cwd| {
170
- Utf8PathBuf :: try_from ( cwd)
171
- . map_err ( CargoConfigsConstructError :: CurrentDirInvalidUtf8 )
167
+ Utf8PathBuf :: try_from ( cwd) . map_err ( CargoConfigError :: CurrentDirInvalidUtf8 )
172
168
} ) ?;
173
169
174
170
Ok ( Self {
@@ -187,7 +183,7 @@ impl CargoConfigs {
187
183
cli_configs : impl IntoIterator < Item = impl AsRef < str > > ,
188
184
cwd : & Utf8Path ,
189
185
terminate_search_at : & Utf8Path ,
190
- ) -> Result < Self , CargoConfigsConstructError > {
186
+ ) -> Result < Self , CargoConfigError > {
191
187
let cli_configs = parse_cli_configs ( cli_configs. into_iter ( ) ) ?;
192
188
193
189
Ok ( Self {
@@ -206,7 +202,7 @@ impl CargoConfigs {
206
202
& self ,
207
203
) -> Result <
208
204
impl Iterator < Item = & ( CargoConfigSource , CargoConfig ) > + DoubleEndedIterator + ' _ ,
209
- CargoConfigSearchError ,
205
+ CargoConfigError ,
210
206
> {
211
207
let cli_iter = self . cli_configs . iter ( ) ;
212
208
let file_iter = self
@@ -219,7 +215,7 @@ impl CargoConfigs {
219
215
220
216
fn parse_cli_configs (
221
217
cli_configs : impl Iterator < Item = impl AsRef < str > > ,
222
- ) -> Result < Vec < ( CargoConfigSource , CargoConfig ) > , CargoConfigsConstructError > {
218
+ ) -> Result < Vec < ( CargoConfigSource , CargoConfig ) > , CargoConfigError > {
223
219
cli_configs
224
220
. into_iter ( )
225
221
. map ( |config_str| {
@@ -231,7 +227,7 @@ fn parse_cli_configs(
231
227
. collect ( )
232
228
}
233
229
234
- fn parse_cli_config ( config_str : & str ) -> Result < CargoConfig , CargoConfigsConstructError > {
230
+ fn parse_cli_config ( config_str : & str ) -> Result < CargoConfig , CargoConfigError > {
235
231
// This implementation is copied over from https://github.com/rust-lang/cargo/pull/10176.
236
232
237
233
// We only want to allow "dotted key" (see https://toml.io/en/v1.0.0#keys)
@@ -242,7 +238,7 @@ fn parse_cli_config(config_str: &str) -> Result<CargoConfig, CargoConfigsConstru
242
238
let doc: toml_edit:: Document =
243
239
config_str
244
240
. parse ( )
245
- . map_err ( |error| CargoConfigsConstructError :: CliConfigParseError {
241
+ . map_err ( |error| CargoConfigError :: CliConfigParseError {
246
242
config_str : config_str. to_owned ( ) ,
247
243
error,
248
244
} ) ?;
@@ -267,22 +263,22 @@ fn parse_cli_config(config_str: &str) -> Result<CargoConfig, CargoConfigsConstru
267
263
if table. key_decor ( k) . map_or ( false , non_empty_decor)
268
264
|| non_empty_decor ( nt. decor ( ) )
269
265
{
270
- return Err ( CargoConfigsConstructError :: InvalidCliConfig {
266
+ return Err ( CargoConfigError :: InvalidCliConfig {
271
267
config_str : config_str. to_owned ( ) ,
272
268
reason : InvalidCargoCliConfigReason :: IncludesNonWhitespaceDecoration ,
273
269
} ) ?;
274
270
}
275
271
table = nt;
276
272
}
277
273
Item :: Value ( v) if v. is_inline_table ( ) => {
278
- return Err ( CargoConfigsConstructError :: InvalidCliConfig {
274
+ return Err ( CargoConfigError :: InvalidCliConfig {
279
275
config_str : config_str. to_owned ( ) ,
280
276
reason : InvalidCargoCliConfigReason :: SetsValueToInlineTable ,
281
277
} ) ?;
282
278
}
283
279
Item :: Value ( v) => {
284
280
if non_empty_decor ( v. decor ( ) ) {
285
- return Err ( CargoConfigsConstructError :: InvalidCliConfig {
281
+ return Err ( CargoConfigError :: InvalidCliConfig {
286
282
config_str : config_str. to_owned ( ) ,
287
283
reason : InvalidCargoCliConfigReason :: IncludesNonWhitespaceDecoration ,
288
284
} ) ?;
@@ -291,13 +287,13 @@ fn parse_cli_config(config_str: &str) -> Result<CargoConfig, CargoConfigsConstru
291
287
break ;
292
288
}
293
289
Item :: ArrayOfTables ( _) => {
294
- return Err ( CargoConfigsConstructError :: InvalidCliConfig {
290
+ return Err ( CargoConfigError :: InvalidCliConfig {
295
291
config_str : config_str. to_owned ( ) ,
296
292
reason : InvalidCargoCliConfigReason :: SetsValueToArrayOfTables ,
297
293
} ) ?;
298
294
}
299
295
Item :: None => {
300
- return Err ( CargoConfigsConstructError :: InvalidCliConfig {
296
+ return Err ( CargoConfigError :: InvalidCliConfig {
301
297
config_str : config_str. to_owned ( ) ,
302
298
reason : InvalidCargoCliConfigReason :: DoesntProvideValue ,
303
299
} ) ?;
@@ -307,14 +303,14 @@ fn parse_cli_config(config_str: &str) -> Result<CargoConfig, CargoConfigsConstru
307
303
got_to_value
308
304
} ;
309
305
if !ok {
310
- return Err ( CargoConfigsConstructError :: InvalidCliConfig {
306
+ return Err ( CargoConfigError :: InvalidCliConfig {
311
307
config_str : config_str. to_owned ( ) ,
312
308
reason : InvalidCargoCliConfigReason :: NotDottedKv ,
313
309
} ) ?;
314
310
}
315
311
316
312
let cargo_config: CargoConfig = toml_edit:: easy:: from_document ( doc) . map_err ( |error| {
317
- CargoConfigsConstructError :: CliConfigDeError {
313
+ CargoConfigError :: CliConfigDeError {
318
314
config_str : config_str. to_owned ( ) ,
319
315
error,
320
316
}
@@ -325,7 +321,7 @@ fn parse_cli_config(config_str: &str) -> Result<CargoConfig, CargoConfigsConstru
325
321
fn discover_impl (
326
322
start_search_at : & Utf8Path ,
327
323
terminate_search_at : Option < & Utf8Path > ,
328
- ) -> Result < Vec < ( CargoConfigSource , CargoConfig ) > , CargoConfigSearchError > {
324
+ ) -> Result < Vec < ( CargoConfigSource , CargoConfig ) > , CargoConfigError > {
329
325
fn read_config_dir ( dir : & mut Utf8PathBuf ) -> Option < Utf8PathBuf > {
330
326
// Check for config before config.toml, same as cargo does
331
327
dir. push ( "config" ) ;
@@ -345,7 +341,7 @@ fn discover_impl(
345
341
}
346
342
347
343
let mut dir = start_search_at. canonicalize_utf8 ( ) . map_err ( |error| {
348
- CargoConfigSearchError :: FailedPathCanonicalization {
344
+ CargoConfigError :: FailedPathCanonicalization {
349
345
path : start_search_at. to_owned ( ) ,
350
346
error,
351
347
}
@@ -377,10 +373,8 @@ fn discover_impl(
377
373
// Attempt lookup the $CARGO_HOME directory from the cwd, as that can
378
374
// contain a default config.toml
379
375
let mut cargo_home_path = home:: cargo_home_with_cwd ( start_search_at. as_std_path ( ) )
380
- . map_err ( CargoConfigSearchError :: GetCargoHome )
381
- . and_then ( |home| {
382
- Utf8PathBuf :: try_from ( home) . map_err ( CargoConfigSearchError :: NonUtf8Path )
383
- } ) ?;
376
+ . map_err ( CargoConfigError :: GetCargoHome )
377
+ . and_then ( |home| Utf8PathBuf :: try_from ( home) . map_err ( CargoConfigError :: NonUtf8Path ) ) ?;
384
378
385
379
if let Some ( home_config) = read_config_dir ( & mut cargo_home_path) {
386
380
// Ensure we don't add a duplicate if the current directory is underneath
@@ -395,21 +389,21 @@ fn discover_impl(
395
389
. into_iter ( )
396
390
. map ( |path| {
397
391
let config_contents = std:: fs:: read_to_string ( & path) . map_err ( |error| {
398
- CargoConfigSearchError :: ConfigReadError {
392
+ CargoConfigError :: ConfigReadError {
399
393
path : path. clone ( ) ,
400
394
error,
401
395
}
402
396
} ) ?;
403
397
let config: CargoConfig =
404
398
toml_edit:: easy:: from_str ( & config_contents) . map_err ( |error| {
405
- CargoConfigSearchError :: ConfigParseError {
399
+ CargoConfigError :: ConfigParseError {
406
400
path : path. clone ( ) ,
407
401
error,
408
402
}
409
403
} ) ?;
410
404
Ok ( ( CargoConfigSource :: File ( path) , config) )
411
405
} )
412
- . collect :: < Result < Vec < _ > , CargoConfigSearchError > > ( ) ?;
406
+ . collect :: < Result < Vec < _ > , CargoConfigError > > ( ) ?;
413
407
414
408
Ok ( configs)
415
409
}
@@ -502,7 +496,7 @@ mod tests {
502
496
// Disallow inline tables
503
497
let err = parse_cli_config ( arg) . unwrap_err ( ) ;
504
498
let actual_reason = match err {
505
- CargoConfigsConstructError :: InvalidCliConfig { reason, .. } => reason,
499
+ CargoConfigError :: InvalidCliConfig { reason, .. } => reason,
506
500
other => panic ! (
507
501
"expected input {arg} to fail with InvalidCliConfig, actual failure: {other}"
508
502
) ,
0 commit comments