From ba0a60c0e11369b83516e4ec9894b9f757c48504 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Jul 2026 13:00:17 -0500 Subject: [PATCH 1/4] test(profile): Pull out debug test --- tests/testsuite/profile_custom.rs | 64 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index da58477aa3b..11a313833bf 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -599,35 +599,6 @@ See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configur )) .run(); } - - p.change_file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2015" - authors = [] - - [profile.debug] - debug = 1 - inherits = "dev" - "#, - ); - - p.cargo("build") - .with_status(101) - .with_stderr_data(str![[r#" -[ERROR] profile name `debug` is reserved - To configure the default development profile, use the name `dev` as in [profile.dev] - See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configuring profiles. - --> Cargo.toml:8:25 - | -8 | [profile.debug] - | ^^^^^ - -"#]]) - .run(); } #[cargo_test] @@ -792,3 +763,38 @@ fn request_test_profile() { "#]]) .run(); } + +#[cargo_test] +fn override_debug_propfile() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + authors = [] + + [profile.debug] + debug = 1 + inherits = "dev" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] profile name `debug` is reserved + To configure the default development profile, use the name `dev` as in [profile.dev] + See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configuring profiles. + --> Cargo.toml:8:25 + | +8 | [profile.debug] + | ^^^^^ + +"#]]) + .run(); +} From 825f7c314f8a3af0133c3d401ad3a5e374d88df0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 31 Jul 2026 11:47:20 -0500 Subject: [PATCH 2/4] test(profile): Fix assert conditions --- tests/testsuite/profile_custom.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 11a313833bf..65272a2fcdb 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -709,8 +709,9 @@ fn test_inherits_dev() { [EXECUTABLE] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]` "#]]) - .with_stdout_does_not_contain("[..] -C debuginfo=0[..]") - .with_stdout_does_not_contain("[..] -C opt-level=0[..]") + .with_stderr_does_not_contain("[..] -C debuginfo=0[..]") + .with_stderr_does_not_contain("[..] -C opt-level=0[..]") + .with_stderr_contains("[..] -C opt-level=3[..]") .run(); } From 0cc4686c709307e9a47c91decee2b1f660444e33 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Jul 2026 13:05:40 -0500 Subject: [PATCH 3/4] test(profile): Expand debug profile coverage --- tests/testsuite/profile_custom.rs | 53 +++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 65272a2fcdb..9593ab9b83c 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -766,35 +766,62 @@ fn request_test_profile() { } #[cargo_test] -fn override_debug_propfile() { +fn debug_inherits_dev() { let p = project() .file( "Cargo.toml", r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2015" - authors = [] + [package] + name = "foo" + version = "0.1.0" + edition = "2015" - [profile.debug] - debug = 1 - inherits = "dev" + [profile.dev] + debug = 0 "#, ) .file("src/lib.rs", "") .build(); + p.cargo("check --profile=dev -v") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..]` +[FINISHED] `dev` profile [unoptimized] target(s) in [ELAPSED]s - p.cargo("build") +"#]]) + .with_stderr_does_not_contain("[..] -C debuginfo=0[..]") + .with_stderr_does_not_contain("[..] -C opt-level=0[..]") + .run(); +} + +#[cargo_test] +fn change_debug_inheritance() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + + [profile.debug] + inherits = "release" + debug = true + "#, + ) + .file("src/lib.rs", "") + .build(); + p.cargo("check --profile=debug") .with_status(101) .with_stderr_data(str![[r#" [ERROR] profile name `debug` is reserved To configure the default development profile, use the name `dev` as in [profile.dev] See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configuring profiles. - --> Cargo.toml:8:25 + --> Cargo.toml:7:22 | -8 | [profile.debug] - | ^^^^^ +7 | [profile.debug] + | ^^^^^ "#]]) .run(); From c916d365909c01a97ddfca28e601e029328e5865 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 13 Jul 2026 14:13:32 -0500 Subject: [PATCH 4/4] feat(profile): Add built-in profile `debug` Key points: - It inherits from `dev` - Conceptually, debugging is part of the development process - The hope is this will smooth out the transition for people - `cargo install --debug` now uses `debug` instead of `dev` - `debug` changes nothing from `dev` right now. `dev` will evolve in the future (with `debug` overriding those values to leave it effectively unchanged) but that is deferred out to offer a transition period where `debug` can be used without but isn't required for debugging as people deal with multiple Rust versions. This also shrinks the change and decouples what the conversation around what the settings should be. --- .../cargo-util-schemas/src/restricted_names.rs | 8 -------- doc/book/src/commands/cargo-bench.md | 4 ++-- doc/book/src/commands/cargo-install.md | 2 +- doc/book/src/commands/cargo-test.md | 5 ++++- doc/book/src/reference/profiles.md | 15 +++++++++++++-- doc/man/cargo-bench.md | 4 ++-- doc/man/cargo-install.md | 2 +- doc/man/cargo-test.md | 5 ++++- doc/man/generated_txt/cargo-bench.txt | 6 +++--- doc/man/generated_txt/cargo-install.txt | 4 ++-- doc/man/generated_txt/cargo-test.txt | 5 ++++- etc/man/cargo-bench.1 | 4 ++-- etc/man/cargo-install.1 | 2 +- etc/man/cargo-test.1 | 5 ++++- src/bin/cargo/commands/install.rs | 9 +++------ src/util/command_prelude.rs | 2 +- src/workspace/parser/mod.rs | 9 --------- src/workspace/profiles.rs | 9 ++++++++- .../cargo_install/help/stdout.term.svg | 4 ++-- tests/testsuite/install.rs | 2 +- tests/testsuite/profile_custom.rs | 18 ++++++++---------- 21 files changed, 66 insertions(+), 58 deletions(-) diff --git a/crates/cargo-util-schemas/src/restricted_names.rs b/crates/cargo-util-schemas/src/restricted_names.rs index 44c17a9968c..dfe44bfb92b 100644 --- a/crates/cargo-util-schemas/src/restricted_names.rs +++ b/crates/cargo-util-schemas/src/restricted_names.rs @@ -137,14 +137,6 @@ pub(crate) fn validate_profile_name(name: &str) -> Result<()> { } let lower_name = name.to_lowercase(); - if lower_name == "debug" { - return Err(ErrorKind::ProfileNameReservedKeyword { - name: name.into(), - help: "To configure the default development profile, \ - use the name `dev` as in [profile.dev]", - } - .into()); - } if lower_name == "build-override" { return Err(ErrorKind::ProfileNameReservedKeyword { name: name.into(), diff --git a/doc/book/src/commands/cargo-bench.md b/doc/book/src/commands/cargo-bench.md index 3e871f27105..74fe4ee7864 100644 --- a/doc/book/src/commands/cargo-bench.md +++ b/doc/book/src/commands/cargo-bench.md @@ -46,8 +46,8 @@ function to handle running benchmarks. By default, `cargo bench` uses the [`bench` profile], which enables optimizations and disables debugging information. If you need to debug a -benchmark, you can use the `--profile=dev` command-line option to switch to -the dev profile. You can then run the debug-enabled benchmark within a +benchmark, you can use the `--profile=debug` command-line option to switch to +the debug profile. You can then run the debug-enabled benchmark within a debugger. [`bench` profile]: ../reference/profiles.html#bench diff --git a/doc/book/src/commands/cargo-install.md b/doc/book/src/commands/cargo-install.md index dd17bde89c1..ff962e6d6f8 100644 --- a/doc/book/src/commands/cargo-install.md +++ b/doc/book/src/commands/cargo-install.md @@ -260,7 +260,7 @@ is specified.

--debug
-

Build with the dev profile instead of the release profile. +

Build with the debug profile instead of the release profile. See also the --profile option for choosing a specific profile by name.

diff --git a/doc/book/src/commands/cargo-test.md b/doc/book/src/commands/cargo-test.md index 71183f9b7bc..b21f4e60b50 100644 --- a/doc/book/src/commands/cargo-test.md +++ b/doc/book/src/commands/cargo-test.md @@ -38,7 +38,10 @@ manifest settings, in which case your code will need to provide its own `main` function to handle running tests. By default, `cargo test` uses the [`test` profile], which enables -debugging. +some optimizations and disables debugging information for fast feedback. If you need to debug a +test, you can use the `--profile=debug` command-line option to switch to +the debug profile. You can then run the debug-enabled test within a +debugger. [`test` profile]: ../reference/profiles.html#test diff --git a/doc/book/src/reference/profiles.md b/doc/book/src/reference/profiles.md index 5ad011e2af2..894a8bf77f7 100644 --- a/doc/book/src/reference/profiles.md +++ b/doc/book/src/reference/profiles.md @@ -262,8 +262,8 @@ whether or not [`rpath`] is enabled. ### dev -The `dev` profile is used for normal development and debugging. It is the -default for build commands like [`cargo build`], and is used for `cargo install --debug`. +The `dev` profile is used for normal development. It is the +default for build commands like [`cargo build`], and is used for `cargo install --profile dev`. The default settings for the `dev` profile are: @@ -282,6 +282,17 @@ codegen-units = 256 rpath = false ``` +### debug + +The `debug` profile is used for creating binaries to run with a debugger. It is used with `cargo build --profile debug` and `cargo install --debug`. + +The default settings for the `debug` profile are: + +```toml +[profile.debug] +inherits = "dev" +``` + ### release The `release` profile is intended for optimized artifacts used for releases diff --git a/doc/man/cargo-bench.md b/doc/man/cargo-bench.md index a1f5028e3ba..6a38854b8a9 100644 --- a/doc/man/cargo-bench.md +++ b/doc/man/cargo-bench.md @@ -51,8 +51,8 @@ function to handle running benchmarks. By default, `cargo bench` uses the [`bench` profile], which enables optimizations and disables debugging information. If you need to debug a -benchmark, you can use the `--profile=dev` command-line option to switch to -the dev profile. You can then run the debug-enabled benchmark within a +benchmark, you can use the `--profile=debug` command-line option to switch to +the debug profile. You can then run the debug-enabled benchmark within a debugger. [`bench` profile]: ../reference/profiles.html#bench diff --git a/doc/man/cargo-install.md b/doc/man/cargo-install.md index 1b1d823f0e9..ac816afc2f0 100644 --- a/doc/man/cargo-install.md +++ b/doc/man/cargo-install.md @@ -178,7 +178,7 @@ Directory to install packages into. {{> options-target-dir }} {{#option "`--debug`" }} -Build with the `dev` profile instead of the `release` profile. +Build with the `debug` profile instead of the `release` profile. See also the `--profile` option for choosing a specific profile by name. {{/option}} diff --git a/doc/man/cargo-test.md b/doc/man/cargo-test.md index c9105f9fc61..181a8e78044 100644 --- a/doc/man/cargo-test.md +++ b/doc/man/cargo-test.md @@ -43,7 +43,10 @@ manifest settings, in which case your code will need to provide its own `main` function to handle running tests. By default, `cargo test` uses the [`test` profile], which enables -debugging. +some optimizations and disables debugging information for fast feedback. If you need to debug a +test, you can use the `--profile=debug` command-line option to switch to +the debug profile. You can then run the debug-enabled test within a +debugger. [`test` profile]: ../reference/profiles.html#test diff --git a/doc/man/generated_txt/cargo-bench.txt b/doc/man/generated_txt/cargo-bench.txt index 089ed26453a..8f8c1ea79b1 100644 --- a/doc/man/generated_txt/cargo-bench.txt +++ b/doc/man/generated_txt/cargo-bench.txt @@ -46,9 +46,9 @@ DESCRIPTION By default, cargo bench uses the bench profile , which enables optimizations and disables debugging information. If you need to - debug a benchmark, you can use the --profile=dev command-line option to - switch to the dev profile. You can then run the debug-enabled benchmark - within a debugger. + debug a benchmark, you can use the --profile=debug command-line option + to switch to the debug profile. You can then run the debug-enabled + benchmark within a debugger. Working directory of benchmarks The working directory of every benchmark is set to the root directory of diff --git a/doc/man/generated_txt/cargo-install.txt b/doc/man/generated_txt/cargo-install.txt index fc695558215..96373360f4e 100644 --- a/doc/man/generated_txt/cargo-install.txt +++ b/doc/man/generated_txt/cargo-install.txt @@ -226,8 +226,8 @@ OPTIONS workspace of the local crate unless --target-dir is specified. --debug - Build with the dev profile instead of the release profile. See also - the --profile option for choosing a specific profile by name. + Build with the debug profile instead of the release profile. See + also the --profile option for choosing a specific profile by name. --profile name Install with the given profile. See the reference diff --git a/doc/man/generated_txt/cargo-test.txt b/doc/man/generated_txt/cargo-test.txt index bd27f8ff796..d48ac64d8cf 100644 --- a/doc/man/generated_txt/cargo-test.txt +++ b/doc/man/generated_txt/cargo-test.txt @@ -38,7 +38,10 @@ DESCRIPTION By default, cargo test uses the test profile , which - enables debugging. + enables some optimizations and disables debugging information for fast + feedback. If you need to debug a test, you can use the --profile=debug + command-line option to switch to the debug profile. You can then run the + debug-enabled test within a debugger. Documentation tests Documentation tests are also run by default, which is handled by diff --git a/etc/man/cargo-bench.1 b/etc/man/cargo-bench.1 index 998c747ceca..a4aed656281 100644 --- a/etc/man/cargo-bench.1 +++ b/etc/man/cargo-bench.1 @@ -54,8 +54,8 @@ running benchmarks on the stable channel, such as .sp By default, \fBcargo bench\fR uses the \fI\f(BIbench\fI profile\fR , which enables optimizations and disables debugging information. If you need to debug a -benchmark, you can use the \fB\-\-profile=dev\fR command\-line option to switch to -the dev profile. You can then run the debug\-enabled benchmark within a +benchmark, you can use the \fB\-\-profile=debug\fR command\-line option to switch to +the debug profile. You can then run the debug\-enabled benchmark within a debugger. .SS "Working directory of benchmarks" The working directory of every benchmark is set to the root directory of the diff --git a/etc/man/cargo-install.1 b/etc/man/cargo-install.1 index a16c7eb16aa..94d64bbfa42 100644 --- a/etc/man/cargo-install.1 +++ b/etc/man/cargo-install.1 @@ -281,7 +281,7 @@ is specified. .sp \fB\-\-debug\fR .RS 4 -Build with the \fBdev\fR profile instead of the \fBrelease\fR profile. +Build with the \fBdebug\fR profile instead of the \fBrelease\fR profile. See also the \fB\-\-profile\fR option for choosing a specific profile by name. .RE .sp diff --git a/etc/man/cargo-test.1 b/etc/man/cargo-test.1 index 2a63f51b8c7..2643cb85670 100644 --- a/etc/man/cargo-test.1 +++ b/etc/man/cargo-test.1 @@ -41,7 +41,10 @@ manifest settings, in which case your code will need to provide its own \fBmain\ function to handle running tests. .sp By default, \fBcargo test\fR uses the \fI\f(BItest\fI profile\fR , which enables -debugging. +some optimizations and disables debugging information for fast feedback. If you need to debug a +test, you can use the \fB\-\-profile=debug\fR command\-line option to switch to +the debug profile. You can then run the debug\-enabled test within a +debugger. .SS "Documentation tests" Documentation tests are also run by default, which is handled by \fBrustdoc\fR\&. It extracts code samples from documentation comments of the library target, and diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 92c7b1c2b5d..bd81f5799e0 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -92,12 +92,9 @@ pub fn cli() -> Command { .arg_features() .arg_parallel() .arg( - flag( - "debug", - "Build in debug mode (with the 'dev' profile) instead of release mode", - ) - .conflicts_with("profile") - .help_heading(heading::COMPILATION_OPTIONS), + flag("debug", "Build in debug mode instead of release mode") + .conflicts_with("profile") + .help_heading(heading::COMPILATION_OPTIONS), ) .arg_redundant_default_mode("release", "install", "debug") .arg_profile("Install artifacts with the specified profile") diff --git a/src/util/command_prelude.rs b/src/util/command_prelude.rs index f3ba638bc22..e09db6eb397 100644 --- a/src/util/command_prelude.rs +++ b/src/util/command_prelude.rs @@ -709,7 +709,7 @@ Run `{cmd}` to see possible targets." ) { (false, false, None) => default, (true, _, None) => "release", - (_, true, None) => "dev", + (_, true, None) => "debug", // `doc` is separate from all the other reservations because // [profile.doc] was historically allowed, but is deprecated and // has no effect. To avoid potentially breaking projects, it is a diff --git a/src/workspace/parser/mod.rs b/src/workspace/parser/mod.rs index 6e57423d0b6..16e88f29edf 100644 --- a/src/workspace/parser/mod.rs +++ b/src/workspace/parser/mod.rs @@ -2564,15 +2564,6 @@ pub fn validate_profile( ); } - // `inherits` validation - if matches!(root.inherits.as_deref(), Some("debug")) { - bail!( - "profile.{}.inherits=\"debug\" should be profile.{}.inherits=\"dev\"", - name, - name - ); - } - match name { "doc" => { warnings.push("profile `doc` is deprecated and has no effect".to_string()); diff --git a/src/workspace/profiles.rs b/src/workspace/profiles.rs index 1f2509a8911..643e8b6401d 100644 --- a/src/workspace/profiles.rs +++ b/src/workspace/profiles.rs @@ -156,6 +156,13 @@ impl Profiles { /// "root" profiles). fn predefined_profiles() -> Vec<(&'static str, TomlProfile)> { vec![ + ( + "debug", + TomlProfile { + inherits: Some(String::from("dev")), + ..TomlProfile::default() + }, + ), ( "bench", TomlProfile { @@ -1298,7 +1305,7 @@ fn merge_config_profiles( } // Add the built-in profiles. This is important for things like `cargo // test` which implicitly use the "dev" profile for dependencies. - for name in ["dev", "release", "test", "bench"] { + for name in ["dev", "release", "debug", "test", "bench"] { check_to_add.insert(name.into()); } // Add config-only profiles. diff --git a/tests/testsuite/cargo_install/help/stdout.term.svg b/tests/testsuite/cargo_install/help/stdout.term.svg index caa01b0c2c7..0596d150173 100644 --- a/tests/testsuite/cargo_install/help/stdout.term.svg +++ b/tests/testsuite/cargo_install/help/stdout.term.svg @@ -1,4 +1,4 @@ - +