]> git.proxmox.com Git - cargo.git/commitdiff
Add future compatibility warning on mixture of --release with --profile.
authorEric Huss <eric@huss.org>
Fri, 24 Sep 2021 17:59:00 +0000 (10:59 -0700)
committerEric Huss <eric@huss.org>
Fri, 24 Sep 2021 17:59:00 +0000 (10:59 -0700)
This was historically allowed, but it silently ignores the --release flag.

src/cargo/util/command_prelude.rs
tests/testsuite/profile_custom.rs

index afe3d68abff7b5c387bcb3e2405556502d2cd7ac..d0cf17824b1e3cdc09fb3ba4f23d2186b521a712 100644 (file)
@@ -353,7 +353,7 @@ pub trait ArgMatchesExt {
 
     fn get_profile_name(
         &self,
-        _config: &Config,
+        config: &Config,
         default: &str,
         profile_checking: ProfileChecking,
     ) -> CargoResult<InternedString> {
@@ -363,9 +363,19 @@ pub trait ArgMatchesExt {
         // This is an early exit, since it allows combination with `--release`.
         match (specified_profile, profile_checking) {
             // `cargo rustc` has legacy handling of these names
-            (Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc) |
+            (Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc)
             // `cargo fix` and `cargo check` has legacy handling of this profile name
-            (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => return Ok(InternedString::new(name)),
+            | (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => {
+                if self._is_present("release") {
+                    config.shell().warn(
+                        "the `--release` flag should not be specified with the `--profile` flag\n\
+                         The `--release` flag will be ignored.\n\
+                         This was historically accepted, but will become an error \
+                         in a future release."
+                    )?;
+                }
+                return Ok(InternedString::new(name));
+            }
             _ => {}
         }
 
index e7961f373c6982a8d41d4be575d246ce681c2554..889665baf87dab47a0bdd8bdb804df981cd855a4 100644 (file)
@@ -360,7 +360,7 @@ fn conflicting_usage() {
                 authors = []
             "#,
         )
-        .file("src/lib.rs", "")
+        .file("src/main.rs", "fn main() {}")
         .build();
 
     p.cargo("build --profile=dev --release")
@@ -381,6 +381,82 @@ Remove one flag or the other to continue.
 error: conflicting usage of --profile=release and --debug
 The `--debug` flag is the same as `--profile=dev`.
 Remove one flag or the other to continue.
+",
+        )
+        .run();
+
+    p.cargo("rustc --profile=dev --release")
+        .with_stderr(
+            "\
+warning: the `--release` flag should not be specified with the `--profile` flag
+The `--release` flag will be ignored.
+This was historically accepted, but will become an error in a future release.
+[COMPILING] foo [..]
+[FINISHED] dev [..]
+",
+        )
+        .run();
+
+    p.cargo("check --profile=dev --release")
+        .with_status(101)
+        .with_stderr(
+            "\
+error: conflicting usage of --profile=dev and --release
+The `--release` flag is the same as `--profile=release`.
+Remove one flag or the other to continue.
+",
+        )
+        .run();
+
+    p.cargo("check --profile=test --release")
+        .with_stderr(
+            "\
+warning: the `--release` flag should not be specified with the `--profile` flag
+The `--release` flag will be ignored.
+This was historically accepted, but will become an error in a future release.
+[CHECKING] foo [..]
+[FINISHED] test [..]
+",
+        )
+        .run();
+
+    // This is OK since the two are the same.
+    p.cargo("rustc --profile=release --release")
+        .with_stderr(
+            "\
+[COMPILING] foo [..]
+[FINISHED] release [..]
+",
+        )
+        .run();
+
+    p.cargo("build --profile=release --release")
+        .with_stderr(
+            "\
+[FINISHED] release [..]
+",
+        )
+        .run();
+
+    p.cargo("install --path . --profile=dev --debug")
+        .with_stderr(
+            "\
+[INSTALLING] foo [..]
+[FINISHED] dev [..]
+[INSTALLING] [..]
+[INSTALLED] [..]
+[WARNING] be sure to add [..]
+",
+        )
+        .run();
+
+    p.cargo("install --path . --profile=release --debug")
+        .with_status(101)
+        .with_stderr(
+            "\
+error: conflicting usage of --profile=release and --debug
+The `--debug` flag is the same as `--profile=dev`.
+Remove one flag or the other to continue.
 ",
         )
         .run();