@@ -271,12 +271,21 @@ impl Config {
271
271
///
272
272
/// Returns a `Config` if the config could be read and parsed from
273
273
/// the file, otherwise errors.
274
- pub ( super ) fn from_toml_path ( file_path : & Path ) -> Result < Config , Error > {
274
+ pub ( super ) fn from_toml_path (
275
+ file_path : & Path ,
276
+ edition : Option < Edition > ,
277
+ style_edition : Option < StyleEdition > ,
278
+ ) -> Result < Config , Error > {
275
279
let mut file = File :: open ( & file_path) ?;
276
280
let mut toml = String :: new ( ) ;
277
281
file. read_to_string ( & mut toml) ?;
278
- Config :: from_toml ( & toml, file_path. parent ( ) . unwrap ( ) )
279
- . map_err ( |err| Error :: new ( ErrorKind :: InvalidData , err) )
282
+ Config :: from_toml_for_style_edition (
283
+ & toml,
284
+ file_path. parent ( ) . unwrap ( ) ,
285
+ edition,
286
+ style_edition,
287
+ )
288
+ . map_err ( |err| Error :: new ( ErrorKind :: InvalidData , err) )
280
289
}
281
290
282
291
/// Resolves the config for input in `dir`.
@@ -288,7 +297,11 @@ impl Config {
288
297
///
289
298
/// Returns the `Config` to use, and the path of the project file if there was
290
299
/// one.
291
- pub ( super ) fn from_resolved_toml_path ( dir : & Path ) -> Result < ( Config , Option < PathBuf > ) , Error > {
300
+ pub ( super ) fn from_resolved_toml_path (
301
+ dir : & Path ,
302
+ edition : Option < Edition > ,
303
+ style_edition : Option < StyleEdition > ,
304
+ ) -> Result < ( Config , Option < PathBuf > ) , Error > {
292
305
/// Try to find a project file in the given directory and its parents.
293
306
/// Returns the path of the nearest project file if one exists,
294
307
/// or `None` if no project file was found.
@@ -333,12 +346,26 @@ impl Config {
333
346
}
334
347
335
348
match resolve_project_file ( dir) ? {
336
- None => Ok ( ( Config :: default ( ) , None ) ) ,
337
- Some ( path) => Config :: from_toml_path ( & path) . map ( |config| ( config, Some ( path) ) ) ,
349
+ None => Ok ( (
350
+ Config :: default_for_possible_style_edition ( style_edition, edition) ,
351
+ None ,
352
+ ) ) ,
353
+ Some ( path) => Config :: from_toml_path ( & path, edition, style_edition)
354
+ . map ( |config| ( config, Some ( path) ) ) ,
338
355
}
339
356
}
340
357
341
- pub ( crate ) fn from_toml ( toml : & str , dir : & Path ) -> Result < Config , String > {
358
+ #[ allow( dead_code) ]
359
+ pub ( super ) fn from_toml ( toml : & str , dir : & Path ) -> Result < Config , String > {
360
+ Self :: from_toml_for_style_edition ( toml, dir, None , None )
361
+ }
362
+
363
+ pub ( crate ) fn from_toml_for_style_edition (
364
+ toml : & str ,
365
+ dir : & Path ,
366
+ edition : Option < Edition > ,
367
+ style_edition : Option < StyleEdition > ,
368
+ ) -> Result < Config , String > {
342
369
let parsed: :: toml:: Value = toml
343
370
. parse ( )
344
371
. map_err ( |e| format ! ( "Could not parse TOML: {}" , e) ) ?;
@@ -358,7 +385,7 @@ impl Config {
358
385
if !err. is_empty ( ) {
359
386
eprint ! ( "{err}" ) ;
360
387
}
361
- Ok ( parsed_config. to_parsed_config ( None , None , dir) )
388
+ Ok ( parsed_config. to_parsed_config ( style_edition , edition , dir) )
362
389
}
363
390
Err ( e) => {
364
391
err. push_str ( "Error: Decoding config file failed:\n " ) ;
@@ -376,21 +403,21 @@ pub fn load_config<O: CliOptions>(
376
403
file_path : Option < & Path > ,
377
404
options : Option < O > ,
378
405
) -> Result < ( Config , Option < PathBuf > ) , Error > {
379
- let ( over_ride, _edition, _style_edition) = match options {
380
- Some ( ref opts) => (
381
- config_path ( opts) ?,
382
- opts. edition ( ) ,
383
- opts. style_edition ( ) ,
384
- ) ,
406
+ let ( over_ride, edition, style_edition) = match options {
407
+ Some ( ref opts) => ( config_path ( opts) ?, opts. edition ( ) , opts. style_edition ( ) ) ,
385
408
None => ( None , None , None ) ,
386
409
} ;
387
410
388
411
let result = if let Some ( over_ride) = over_ride {
389
- Config :: from_toml_path ( over_ride. as_ref ( ) ) . map ( |p| ( p, Some ( over_ride. to_owned ( ) ) ) )
412
+ Config :: from_toml_path ( over_ride. as_ref ( ) , edition, style_edition)
413
+ . map ( |p| ( p, Some ( over_ride. to_owned ( ) ) ) )
390
414
} else if let Some ( file_path) = file_path {
391
- Config :: from_resolved_toml_path ( file_path)
415
+ Config :: from_resolved_toml_path ( file_path, edition , style_edition )
392
416
} else {
393
- Ok ( ( Config :: default ( ) , None ) )
417
+ Ok ( (
418
+ Config :: default_for_possible_style_edition ( style_edition, edition) ,
419
+ None ,
420
+ ) )
394
421
} ;
395
422
396
423
result. map ( |( mut c, p) | {
0 commit comments