From 2994a16e39a1709cb45f04fbc5d65666abde54a1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Jul 2026 13:00:17 -0500 Subject: [PATCH 1/3] 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 ea73b8f983454161b1d31dec39102aecdff14de5 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Jul 2026 13:05:40 -0500 Subject: [PATCH 2/3] test(profile): Expand debug profile coverage --- tests/testsuite/profile_custom.rs | 61 ++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 11a313833bf..fa950f1bb02 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -765,35 +765,70 @@ 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 + + [profile.debug] + opt-level = 3 "#, ) .file("src/lib.rs", "") .build(); + p.cargo("check --profile=debug -v") + .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:10:22 + | +10 | [profile.debug] + | ^^^^^ - p.cargo("build") +"#]]) + .with_stdout_does_not_contain("[..] -C debuginfo=0[..]") + .with_stdout_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 88c5c580653ca62370f372056e419536852464ad Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 13 Jul 2026 14:13:32 -0500 Subject: [PATCH 3/3] 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. --- .../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/util/command_prelude.rs | 2 +- src/workspace/parser/mod.rs | 9 -------- src/workspace/profiles.rs | 9 +++++++- tests/testsuite/install.rs | 2 +- tests/testsuite/profile_custom.rs | 21 +++++-------------- 19 files changed, 58 insertions(+), 56 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..6ba0123566f 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 +benchmark, 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..00fcdefba17 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 +benchmark, 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..f7313ec4f14 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 benchmark, 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..73a89c8cc8e 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 +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 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/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 4098ef06dd0..56f07dc3f42 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/install.rs b/tests/testsuite/install.rs index dbce2e8dc58..3ab611dcfa3 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -2842,7 +2842,7 @@ fn install_with_debug_profile() { [DOWNLOADED] foo v0.0.1 (registry `dummy-registry`) [INSTALLING] foo v0.0.1 [COMPILING] foo v0.0.1 -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[FINISHED] `debug` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE] [INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`) [WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index fa950f1bb02..075cb20a3b8 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -785,15 +785,10 @@ fn debug_inherits_dev() { .file("src/lib.rs", "") .build(); p.cargo("check --profile=debug -v") - .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:10:22 - | -10 | [profile.debug] - | ^^^^^ +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..]` +[FINISHED] `debug` profile [optimized] target(s) in [ELAPSED]s "#]]) .with_stdout_does_not_contain("[..] -C debuginfo=0[..]") @@ -820,15 +815,9 @@ fn change_debug_inheritance() { .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:7:22 - | -7 | [profile.debug] - | ^^^^^ +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `debug` profile [optimized + debuginfo] target(s) in [ELAPSED]s "#]]) .run();