@@ -271,12 +271,21 @@ impl Config {
271271 ///
272272 /// Returns a `Config` if the config could be read and parsed from
273273 /// 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 > {
275279 let mut file = File :: open ( & file_path) ?;
276280 let mut toml = String :: new ( ) ;
277281 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) )
280289 }
281290
282291 /// Resolves the config for input in `dir`.
@@ -288,7 +297,11 @@ impl Config {
288297 ///
289298 /// Returns the `Config` to use, and the path of the project file if there was
290299 /// 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 > {
292305 /// Try to find a project file in the given directory and its parents.
293306 /// Returns the path of the nearest project file if one exists,
294307 /// or `None` if no project file was found.
@@ -333,12 +346,26 @@ impl Config {
333346 }
334347
335348 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) ) ) ,
338355 }
339356 }
340357
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 > {
342369 let parsed: :: toml:: Value = toml
343370 . parse ( )
344371 . map_err ( |e| format ! ( "Could not parse TOML: {}" , e) ) ?;
@@ -358,7 +385,7 @@ impl Config {
358385 if !err. is_empty ( ) {
359386 eprint ! ( "{err}" ) ;
360387 }
361- Ok ( parsed_config. to_parsed_config ( None , None , dir) )
388+ Ok ( parsed_config. to_parsed_config ( style_edition , edition , dir) )
362389 }
363390 Err ( e) => {
364391 err. push_str ( "Error: Decoding config file failed:\n " ) ;
@@ -376,21 +403,21 @@ pub fn load_config<O: CliOptions>(
376403 file_path : Option < & Path > ,
377404 options : Option < O > ,
378405) -> 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 ( ) ) ,
385408 None => ( None , None , None ) ,
386409 } ;
387410
388411 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 ( ) ) ) )
390414 } 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 )
392416 } else {
393- Ok ( ( Config :: default ( ) , None ) )
417+ Ok ( (
418+ Config :: default_for_possible_style_edition ( style_edition, edition) ,
419+ None ,
420+ ) )
394421 } ;
395422
396423 result. map ( |( mut c, p) | {
0 commit comments