@@ -414,7 +414,10 @@ fn rustfix_crate(
414
414
args : & FixArgs ,
415
415
config : & Config ,
416
416
) -> Result < FixedCrate , Error > {
417
- args. check_edition_and_send_status ( config) ?;
417
+ if !args. can_run_rustfix ( config) ? {
418
+ // This fix should not be run. Skipping...
419
+ return Ok ( FixedCrate :: default ( ) ) ;
420
+ }
418
421
419
422
// First up, we want to make sure that each crate is only checked by one
420
423
// process at a time. If two invocations concurrently check a crate then
@@ -804,15 +807,16 @@ impl FixArgs {
804
807
}
805
808
806
809
/// Validates the edition, and sends a message indicating what is being
807
- /// done.
808
- fn check_edition_and_send_status ( & self , config : & Config ) -> CargoResult < ( ) > {
810
+ /// done. Returns a flag indicating whether this fix should be run.
811
+ fn can_run_rustfix ( & self , config : & Config ) -> CargoResult < bool > {
809
812
let to_edition = match self . prepare_for_edition {
810
813
Some ( s) => s,
811
814
None => {
812
815
return Message :: Fixing {
813
816
file : self . file . display ( ) . to_string ( ) ,
814
817
}
815
- . post ( ) ;
818
+ . post ( )
819
+ . and ( Ok ( true ) ) ;
816
820
}
817
821
} ;
818
822
// Unfortunately determining which cargo targets are being built
@@ -826,18 +830,31 @@ impl FixArgs {
826
830
// multiple jobs run in parallel (the error appears multiple
827
831
// times). Hopefully this doesn't happen often in practice.
828
832
if !to_edition. is_stable ( ) && !config. nightly_features_allowed {
829
- bail ! (
830
- "cannot migrate {} to edition {to_edition}\n \
831
- Edition {to_edition} is unstable and not allowed in this release, \
832
- consider trying the nightly release channel.",
833
- self . file. display( ) ,
833
+ let message = format ! (
834
+ "`{file}` is on the latest edition, but trying to \
835
+ migrate to edition {to_edition}.\n \
836
+ Edition {to_edition} is unstable and not allowed in \
837
+ this release, consider trying the nightly release channel.",
838
+ file = self . file. display( ) ,
834
839
to_edition = to_edition
835
840
) ;
841
+ return Message :: EditionAlreadyEnabled {
842
+ message,
843
+ edition : to_edition. previous ( ) . unwrap ( ) ,
844
+ }
845
+ . post ( )
846
+ . and ( Ok ( false ) ) ; // Do not run rustfix for this the edition.
836
847
}
837
848
let from_edition = self . enabled_edition . unwrap_or ( Edition :: Edition2015 ) ;
838
849
if from_edition == to_edition {
850
+ let message = format ! (
851
+ "`{}` is already on the latest edition ({}), \
852
+ unable to migrate further",
853
+ self . file. display( ) ,
854
+ to_edition
855
+ ) ;
839
856
Message :: EditionAlreadyEnabled {
840
- file : self . file . display ( ) . to_string ( ) ,
857
+ message ,
841
858
edition : to_edition,
842
859
}
843
860
. post ( )
@@ -849,5 +866,6 @@ impl FixArgs {
849
866
}
850
867
. post ( )
851
868
}
869
+ . and ( Ok ( true ) )
852
870
}
853
871
}
0 commit comments