You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(new): Improve quality of package name error messages (#16398)
### What does this PR try to resolve?
While triaging #16396, I noticed that the error messages don't match the
rustc style which we are aiming for, so I tweaked the messages and went
ahead and fixed#16396.
Fixes#16396
### How to test and review this PR?
Since `different-binary-name` doesn't have a `-Z` variant, I held off on
suggesting it so we didn't suggest using an unstable feature.
Copy file name to clipboardExpand all lines: tests/testsuite/new.rs
+32-30Lines changed: 32 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -168,13 +168,8 @@ fn invalid_characters() {
168
168
.with_stderr_data(str![[r#"
169
169
[CREATING] binary (application) `foo.rs` package
170
170
[ERROR] invalid character `.` in package name: `foo.rs`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
171
-
If you need a package name to not match the directory name, consider using --name flag.
172
-
If you need a binary with the name "foo.rs", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/foo.rs.rs` or change the name in Cargo.toml with:
173
-
174
-
[[bin]]
175
-
name = "foo.rs"
176
-
path = "src/main.rs"
177
-
171
+
[NOTE] the directory name is used as the package name
172
+
[HELP] to override the package name, pass `--name <pkgname>`
178
173
179
174
"#]])
180
175
.run();
@@ -186,9 +181,10 @@ fn reserved_name() {
186
181
.with_status(101)
187
182
.with_stderr_data(str![[r#"
188
183
[CREATING] binary (application) `test` package
189
-
[ERROR] the name `test` cannot be used as a package name, it conflicts with Rust's built-in test library
190
-
If you need a package name to not match the directory name, consider using --name flag.
191
-
If you need a binary with the name "test", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/test.rs` or change the name in Cargo.toml with:
184
+
[ERROR] invalid package name `test`: it conflicts with Rust's built-in test library
185
+
[NOTE] the directory name is used as the package name
186
+
[HELP] to override the package name, pass `--name <pkgname>`
187
+
[HELP] to name the binary "test", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/test.rs` or change the name in Cargo.toml with:
[ERROR] the name `incremental` cannot be used as a package name, it conflicts with cargo's build directory names
209
-
If you need a package name to not match the directory name, consider using --name flag.
204
+
[ERROR] invalid package name `incremental`: it conflicts with cargo's build directory names
205
+
[NOTE] the directory name is used as the package name
206
+
[HELP] to override the package name, pass `--name <pkgname>`
210
207
211
208
"#]])
212
209
.run();
213
210
214
211
cargo_process("new --lib incremental")
215
212
.with_stderr_data(str![[r#"
216
213
[CREATING] library `incremental` package
217
-
[WARNING] the name `incremental` will not support binary executables with that name, it conflicts with cargo's build directory names
214
+
[WARNING] package `incremental` will not support binary executables with that name, it conflicts with cargo's build directory names
218
215
[NOTE] see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
219
216
220
217
"#]])
@@ -227,9 +224,10 @@ fn keyword_name() {
227
224
.with_status(101)
228
225
.with_stderr_data(str![[r#"
229
226
[CREATING] binary (application) `pub` package
230
-
[ERROR] the name `pub` cannot be used as a package name, it is a Rust keyword
231
-
If you need a package name to not match the directory name, consider using --name flag.
232
-
If you need a binary with the name "pub", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/pub.rs` or change the name in Cargo.toml with:
227
+
[ERROR] invalid package name `pub`: it is a Rust keyword
228
+
[NOTE] the directory name is used as the package name
229
+
[HELP] to override the package name, pass `--name <pkgname>`
230
+
[HELP] to name the binary "pub", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/pub.rs` or change the name in Cargo.toml with:
233
231
234
232
[[bin]]
235
233
name = "pub"
@@ -244,10 +242,11 @@ If you need a binary with the name "pub", use a valid package name, and set the
[WARNING] the name `core` is part of Rust's standard library
245
+
[WARNING] package name `core` may be confused with the package with that name in Rust's standard library
248
246
It is recommended to use a different name to avoid problems.
249
-
If you need a package name to not match the directory name, consider using --name flag.
250
-
If you need a binary with the name "core", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/core.rs` or change the name in Cargo.toml with:
247
+
[NOTE] the directory name is used as the package name
248
+
[HELP] to override the package name, pass `--name <pkgname>`
249
+
[HELP] to name the binary "core", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/core.rs` or change the name in Cargo.toml with:
[ERROR] invalid character `1` in package name: `10-invalid`, the name cannot start with a digit
372
-
If you need a binary with the name "10-invalid", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/10-invalid.rs` or change the name in Cargo.toml with:
371
+
[HELP] to name the binary "10-invalid", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/10-invalid.rs` or change the name in Cargo.toml with:
[WARNING] the name `Привет` contains non-ASCII characters
464
+
[WARNING] invalid package name `Привет`: contains non-ASCII characters
465
465
Non-ASCII crate names are not supported by Rust.
466
-
[WARNING] the name `Привет` is not snake_case or kebab-case which is recommended for package names, consider `привет`
466
+
[WARNING] package name `Привет` is not snake_case or kebab-case which is recommended for package names, consider `привет`
467
467
[NOTE] see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
468
468
469
469
"#]]).run();
@@ -477,8 +477,9 @@ fn non_ascii_name_invalid() {
477
477
.with_stderr_data(str![[r#"
478
478
[CREATING] binary (application) `ⒶⒷⒸ` package
479
479
[ERROR] invalid character `Ⓐ` in package name: `ⒶⒷⒸ`, the first character must be a Unicode XID start character (most letters or `_`)
480
-
If you need a package name to not match the directory name, consider using --name flag.
481
-
If you need a binary with the name "ⒶⒷⒸ", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/ⒶⒷⒸ.rs` or change the name in Cargo.toml with:
480
+
[NOTE] the directory name is used as the package name
481
+
[HELP] to override the package name, pass `--name <pkgname>`
482
+
[HELP] to name the binary "ⒶⒷⒸ", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/ⒶⒷⒸ.rs` or change the name in Cargo.toml with:
482
483
483
484
[[bin]]
484
485
name = "ⒶⒷⒸ"
@@ -493,8 +494,9 @@ If you need a binary with the name "ⒶⒷⒸ", use a valid package name, and se
493
494
.with_stderr_data(str![[r#"
494
495
[CREATING] binary (application) `a¼` package
495
496
[ERROR] invalid character `¼` in package name: `a¼`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
496
-
If you need a package name to not match the directory name, consider using --name flag.
497
-
If you need a binary with the name "a¼", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/a¼.rs` or change the name in Cargo.toml with:
497
+
[NOTE] the directory name is used as the package name
498
+
[HELP] to override the package name, pass `--name <pkgname>`
499
+
[HELP] to name the binary "a¼", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/a¼.rs` or change the name in Cargo.toml with:
0 commit comments