File tree 2 files changed +36
-3
lines changed
2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -81,8 +81,11 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
81
81
82
82
let mut opts = args. compile_options ( gctx, mode, Some ( & ws) , ProfileChecking :: LegacyTestOnly ) ?;
83
83
84
- if !opts. filter . is_specific ( ) {
85
- // cargo fix with no target selection implies `--all-targets`.
84
+ let edition = args. flag ( "edition" ) || args. flag ( "edition-idioms" ) ;
85
+ if !opts. filter . is_specific ( ) && edition {
86
+ // When `cargo fix` is run without specifying targets but with `--edition` or `--edition-idioms`,
87
+ // it should default to fixing all targets.
88
+ // See: https://github.com/rust-lang/cargo/issues/13527
86
89
opts. filter = ops:: CompileFilter :: new_all_targets ( ) ;
87
90
}
88
91
Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ fn prepare_for_2018() {
198
198
}
199
199
200
200
#[ cargo_test]
201
- fn fix_tests ( ) {
201
+ fn do_not_fix_tests ( ) {
202
202
let p = project ( )
203
203
. file (
204
204
"src/lib.rs" ,
@@ -220,6 +220,36 @@ fn fix_tests() {
220
220
p. cargo ( "fix --allow-no-vcs" )
221
221
. with_stderr_data ( str![ [ r#"
222
222
[CHECKING] foo v0.0.1 ([ROOT]/foo)
223
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
224
+
225
+ "# ] ] )
226
+ . with_stdout_data ( "" )
227
+ . run ( ) ;
228
+ }
229
+
230
+ #[ cargo_test]
231
+ fn fix_tests_with_edition ( ) {
232
+ let p = project ( )
233
+ . file (
234
+ "src/lib.rs" ,
235
+ r#"
236
+ pub fn foo() {}
237
+
238
+ #[cfg(test)]
239
+ mod tests {
240
+ #[test]
241
+ fn it_works() {
242
+ let mut x = 3;
243
+ x;
244
+ }
245
+ }
246
+ "# ,
247
+ )
248
+ . build ( ) ;
249
+
250
+ p. cargo ( "fix --edition-idioms --allow-no-vcs" )
251
+ . with_stderr_data ( str![ [ r#"
252
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
223
253
[FIXED] src/lib.rs (1 fix)
224
254
[WARNING] path statement with no effect
225
255
--> src/lib.rs:9:25
You can’t perform that action at this time.
0 commit comments