Skip to content

Commit b0942d3

Browse files
authored
fix(toml): Teach users how to pin edition (#16851)
### What does this PR try to resolve? Only when not `--quiet` (note: piped stderr implies `--quiet`) This tries to strike a balance between - Helping users know how to react to the warning - Good noise that encourages users to pin the edition - Bad noise that overwhelms the throwaway scripts ### How to test and review this PR
2 parents 273393c + 8330a7a commit b0942d3

12 files changed

Lines changed: 112 additions & 27 deletions

File tree

src/cargo/util/toml/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,14 @@ fn normalize_package_toml<'a>(
633633
if is_embedded {
634634
const DEFAULT_EDITION: crate::core::features::Edition =
635635
crate::core::features::Edition::LATEST_STABLE;
636-
let report = [Group::with_title(Level::WARNING.secondary_title(format!(
636+
let mut report = vec![Group::with_title(Level::WARNING.secondary_title(format!(
637637
"`package.edition` is unspecified, defaulting to the latest edition (currently `{DEFAULT_EDITION}`)"
638638
)))];
639+
if !matches!(gctx.shell().verbosity(), cargo_util_terminal::Verbosity::Quiet) {
640+
report.push(Group::with_title(Level::HELP.secondary_title(format!(
641+
"to pin the edition, run `cargo fix --manifest-path {}`", manifest_file.display()
642+
))));
643+
}
639644
let _ = gctx.shell().print_report(&report, true);
640645
Some(manifest::InheritableField::Value(
641646
DEFAULT_EDITION.to_string(),

tests/testsuite/cargo_add/script_bare/stderr.term.svg

Lines changed: 11 additions & 6 deletions
Loading

tests/testsuite/cargo_add/script_frontmatter_empty/stderr.term.svg

Lines changed: 11 additions & 6 deletions
Loading

tests/testsuite/cargo_add/script_shebang/stderr.term.svg

Lines changed: 11 additions & 6 deletions
Loading

tests/testsuite/cargo_remove/script/stderr.term.svg

Lines changed: 9 additions & 4 deletions
Loading

tests/testsuite/cargo_remove/script_last/stderr.term.svg

Lines changed: 9 additions & 4 deletions
Loading

tests/testsuite/fix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,7 @@ fn script_without_frontmatter() {
30913091
.with_stdout_data(str![""])
30923092
.with_stderr_data(str![[r#"
30933093
[WARNING] `package.edition` is unspecified, defaulting to the latest edition (currently `[..]`)
3094+
[HELP] to pin the edition, run `cargo fix --manifest-path [ROOT]/foo/echo.rs`
30943095
[FIXED] echo.rs (1 fix)
30953096
[CHECKING] echo v0.0.0 ([ROOT]/foo/echo.rs)
30963097
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -3129,6 +3130,7 @@ fn main() {}",
31293130
.with_stdout_data(str![""])
31303131
.with_stderr_data(str![[r#"
31313132
[WARNING] `package.edition` is unspecified, defaulting to the latest edition (currently `[..]`)
3133+
[HELP] to pin the edition, run `cargo fix --manifest-path [ROOT]/foo/echo.rs`
31323134
[FIXED] echo.rs (1 fix)
31333135
[CHECKING] echo v0.0.0 ([ROOT]/foo/echo.rs)
31343136
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -3169,6 +3171,7 @@ fn main() {}"#,
31693171
.with_stdout_data(str![""])
31703172
.with_stderr_data(str![[r#"
31713173
[WARNING] `package.edition` is unspecified, defaulting to the latest edition (currently `[..]`)
3174+
[HELP] to pin the edition, run `cargo fix --manifest-path [ROOT]/foo/echo.rs`
31723175
[FIXED] echo.rs (1 fix)
31733176
[CHECKING] foo v0.0.0 ([ROOT]/foo/echo.rs)
31743177
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -3208,6 +3211,7 @@ fn main() {}"#,
32083211
.with_stdout_data(str![""])
32093212
.with_stderr_data(str![[r#"
32103213
[WARNING] `package.edition` is unspecified, defaulting to the latest edition (currently `[..]`)
3214+
[HELP] to pin the edition, run `cargo fix --manifest-path [ROOT]/foo/echo.rs`
32113215
[FIXED] echo.rs (1 fix)
32123216
[CHECKING] foo v0.0.0 ([ROOT]/foo/echo.rs)
32133217
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

tests/testsuite/lints/non_kebab_case_bins.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ fn main() {}"#,
154154
.masquerade_as_nightly_cargo(&["cargo-lints", "script"])
155155
.with_stderr_data(str![[r#"
156156
[WARNING] `package.edition` is unspecified, defaulting to the latest edition (currently `[..]`)
157+
[HELP] to pin the edition, run `cargo fix --manifest-path [ROOT]/foo/foo_bar`
157158
[WARNING] binaries should have a kebab-case name
158159
|
159160
1 | [ROOT]/home/.cargo/build/[HASH]/target/.../foo_bar[EXE]

tests/testsuite/lints/non_kebab_case_packages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fn main() {}"#,
6161
.masquerade_as_nightly_cargo(&["cargo-lints", "script"])
6262
.with_stderr_data(str![[r#"
6363
[WARNING] `package.edition` is unspecified, defaulting to the latest edition (currently `[..]`)
64+
[HELP] to pin the edition, run `cargo fix --manifest-path [ROOT]/foo/foo_bar`
6465
[WARNING] packages should have a kebab-case name
6566
--> foo_bar
6667
= [NOTE] `cargo::non_kebab_case_packages` is set to `warn` in `[lints]`

tests/testsuite/lints/non_snake_case_packages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fn main() {}"#,
6161
.masquerade_as_nightly_cargo(&["cargo-lints", "script"])
6262
.with_stderr_data(str![[r#"
6363
[WARNING] `package.edition` is unspecified, defaulting to the latest edition (currently `[..]`)
64+
[HELP] to pin the edition, run `cargo fix --manifest-path [ROOT]/foo/foo-bar`
6465
[WARNING] packages should have a snake-case name
6566
--> foo-bar
6667
= [NOTE] `cargo::non_snake_case_packages` is set to `warn` in `[lints]`

0 commit comments

Comments
 (0)