diff --git a/src/cargo/util/restricted_names.rs b/src/cargo/util/restricted_names.rs index 8f83674dd65..2c3eaa9e1f8 100644 --- a/src/cargo/util/restricted_names.rs +++ b/src/cargo/util/restricted_names.rs @@ -100,6 +100,9 @@ pub fn sanitize_package_name(name: &str, placeholder: char) -> String { slug.push(placeholder); } } + if slug.is_empty() { + slug.push_str("package"); + } slug } diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index bb672fc0def..ab758498b02 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -574,13 +574,16 @@ fn test_name_is_number() { p.cargo("-Zscript -v 42.rs") .masquerade_as_nightly_cargo(&["script"]) - .with_status(101) + .with_stdout( + r#"bin: [..]/debug/package[EXE] +args: [] +"#, + ) .with_stderr( r#"[WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[ERROR] failed to parse manifest at `[ROOT]/foo/42.rs` - -Caused by: - package name cannot be an empty string +[COMPILING] package v0.0.0 ([ROOT]/foo) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s +[RUNNING] `[..]/debug/package[EXE]` "#, ) .run();