@@ -222,11 +222,13 @@ impl PartialConfig {
222222 self ,
223223 style_edition_override : Option < StyleEdition > ,
224224 edition_override : Option < Edition > ,
225+ version_override : Option < Version > ,
225226 dir : & Path ,
226227 ) -> Config {
227228 Config :: default_for_possible_style_edition (
228229 style_edition_override. or ( self . style_edition ) ,
229230 edition_override. or ( self . edition ) ,
231+ version_override. or ( self . version ) ,
230232 )
231233 . fill_from_parsed_config ( self , dir)
232234 }
@@ -236,16 +238,25 @@ impl Config {
236238 pub fn default_for_possible_style_edition (
237239 style_edition : Option < StyleEdition > ,
238240 edition : Option < Edition > ,
241+ version : Option < Version > ,
239242 ) -> Config {
240- style_edition. map_or_else (
241- || {
242- edition. map_or_else (
243- || Config :: default ( ) ,
244- |e| Self :: default_with_style_edition ( e. into ( ) ) ,
245- )
246- } ,
247- |se| Self :: default_with_style_edition ( se) ,
248- )
243+ // Ensures the configuration defaults associated with Style Editions
244+ // follow the precedence set in
245+ // https://rust-lang.github.io/rfcs/3338-style-evolution.html
246+ // 'version' is a legacy alias for 'style_edition' that we'll support
247+ // for some period of time
248+ // FIXME(calebcartwright) - remove 'version' at some point
249+ match ( style_edition, version, edition) {
250+ ( Some ( se) , _, _) => Self :: default_with_style_edition ( se) ,
251+ ( None , Some ( Version :: Two ) , _) => {
252+ Self :: default_with_style_edition ( StyleEdition :: Edition2024 )
253+ }
254+ ( None , Some ( Version :: One ) , _) => {
255+ Self :: default_with_style_edition ( StyleEdition :: Edition2015 )
256+ }
257+ ( None , None , Some ( e) ) => Self :: default_with_style_edition ( e. into ( ) ) ,
258+ ( None , None , None ) => Config :: default ( ) ,
259+ }
249260 }
250261
251262 pub ( crate ) fn version_meets_requirement ( & self ) -> bool {
@@ -275,6 +286,7 @@ impl Config {
275286 file_path : & Path ,
276287 edition : Option < Edition > ,
277288 style_edition : Option < StyleEdition > ,
289+ version : Option < Version > ,
278290 ) -> Result < Config , Error > {
279291 let mut file = File :: open ( & file_path) ?;
280292 let mut toml = String :: new ( ) ;
@@ -284,6 +296,7 @@ impl Config {
284296 file_path. parent ( ) . unwrap ( ) ,
285297 edition,
286298 style_edition,
299+ version,
287300 )
288301 . map_err ( |err| Error :: new ( ErrorKind :: InvalidData , err) )
289302 }
@@ -301,6 +314,7 @@ impl Config {
301314 dir : & Path ,
302315 edition : Option < Edition > ,
303316 style_edition : Option < StyleEdition > ,
317+ version : Option < Version > ,
304318 ) -> Result < ( Config , Option < PathBuf > ) , Error > {
305319 /// Try to find a project file in the given directory and its parents.
306320 /// Returns the path of the nearest project file if one exists,
@@ -347,24 +361,25 @@ impl Config {
347361
348362 match resolve_project_file ( dir) ? {
349363 None => Ok ( (
350- Config :: default_for_possible_style_edition ( style_edition, edition) ,
364+ Config :: default_for_possible_style_edition ( style_edition, edition, version ) ,
351365 None ,
352366 ) ) ,
353- Some ( path) => Config :: from_toml_path ( & path, edition, style_edition)
367+ Some ( path) => Config :: from_toml_path ( & path, edition, style_edition, version )
354368 . map ( |config| ( config, Some ( path) ) ) ,
355369 }
356370 }
357371
358372 #[ allow( dead_code) ]
359373 pub ( super ) fn from_toml ( toml : & str , dir : & Path ) -> Result < Config , String > {
360- Self :: from_toml_for_style_edition ( toml, dir, None , None )
374+ Self :: from_toml_for_style_edition ( toml, dir, None , None , None )
361375 }
362376
363377 pub ( crate ) fn from_toml_for_style_edition (
364378 toml : & str ,
365379 dir : & Path ,
366380 edition : Option < Edition > ,
367381 style_edition : Option < StyleEdition > ,
382+ version : Option < Version > ,
368383 ) -> Result < Config , String > {
369384 let parsed: :: toml:: Value = toml
370385 . parse ( )
@@ -385,7 +400,7 @@ impl Config {
385400 if !err. is_empty ( ) {
386401 eprint ! ( "{err}" ) ;
387402 }
388- Ok ( parsed_config. to_parsed_config ( style_edition, edition, dir) )
403+ Ok ( parsed_config. to_parsed_config ( style_edition, edition, version , dir) )
389404 }
390405 Err ( e) => {
391406 err. push_str ( "Error: Decoding config file failed:\n " ) ;
@@ -403,19 +418,24 @@ pub fn load_config<O: CliOptions>(
403418 file_path : Option < & Path > ,
404419 options : Option < O > ,
405420) -> Result < ( Config , Option < PathBuf > ) , Error > {
406- let ( over_ride, edition, style_edition) = match options {
407- Some ( ref opts) => ( config_path ( opts) ?, opts. edition ( ) , opts. style_edition ( ) ) ,
408- None => ( None , None , None ) ,
421+ let ( over_ride, edition, style_edition, version) = match options {
422+ Some ( ref opts) => (
423+ config_path ( opts) ?,
424+ opts. edition ( ) ,
425+ opts. style_edition ( ) ,
426+ opts. version ( ) ,
427+ ) ,
428+ None => ( None , None , None , None ) ,
409429 } ;
410430
411431 let result = if let Some ( over_ride) = over_ride {
412- Config :: from_toml_path ( over_ride. as_ref ( ) , edition, style_edition)
432+ Config :: from_toml_path ( over_ride. as_ref ( ) , edition, style_edition, version )
413433 . map ( |p| ( p, Some ( over_ride. to_owned ( ) ) ) )
414434 } else if let Some ( file_path) = file_path {
415- Config :: from_resolved_toml_path ( file_path, edition, style_edition)
435+ Config :: from_resolved_toml_path ( file_path, edition, style_edition, version )
416436 } else {
417437 Ok ( (
418- Config :: default_for_possible_style_edition ( style_edition, edition) ,
438+ Config :: default_for_possible_style_edition ( style_edition, edition, version ) ,
419439 None ,
420440 ) )
421441 } ;
0 commit comments