From 2dd9518ea18fccea9489d0faa65a212b45e6e60f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 11 Feb 2026 15:45:54 -0600 Subject: [PATCH 1/2] test(cli): Port more tests to snapshots --- tests/testsuite/bad_manifest_path.rs | 530 +++++++++++++++++++++++---- 1 file changed, 450 insertions(+), 80 deletions(-) diff --git a/tests/testsuite/bad_manifest_path.rs b/tests/testsuite/bad_manifest_path.rs index c497e303f85..611216b510d 100644 --- a/tests/testsuite/bad_manifest_path.rs +++ b/tests/testsuite/bad_manifest_path.rs @@ -4,7 +4,7 @@ use crate::prelude::*; use cargo_test_support::{basic_bin_manifest, main_file, project, str}; #[track_caller] -fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) { +fn assert_bad_manifest_path(command: &str, manifest_path_argument: &str, stderr: impl IntoData) { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) .file("src/foo.rs", &main_file(r#""i am foo""#, &[])) @@ -15,310 +15,680 @@ fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) { .arg(manifest_path_argument) .cwd(p.root().parent().unwrap()) .with_status(101) - .with_stderr_data( - "[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/[..]`\n", - ) - .run(); -} - -#[track_caller] -fn assert_cargo_toml_doesnt_exist(command: &str, manifest_path_argument: &str) { - let p = project().build(); - let expected_path = manifest_path_argument - .split('/') - .collect::>() - .join("[..]"); - - p.cargo(command) - .arg("--manifest-path") - .arg(manifest_path_argument) - .cwd(p.root().parent().unwrap()) - .with_status(101) - .with_stderr_data(format!( - "[ERROR] manifest path `{}` does not exist\n", - expected_path - )) + .with_stderr_data(stderr) .run(); } #[cargo_test] fn bench_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("bench", "foo"); + assert_bad_manifest_path( + "bench", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn bench_dir_plus_file() { - assert_not_a_cargo_toml("bench", "foo/bar"); + assert_bad_manifest_path( + "bench", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn bench_dir_plus_path() { - assert_not_a_cargo_toml("bench", "foo/bar/baz"); + assert_bad_manifest_path( + "bench", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn bench_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("bench", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "bench", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn build_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("check", "foo"); + assert_bad_manifest_path( + "check", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn build_dir_plus_file() { - assert_not_a_cargo_toml("bench", "foo/bar"); + assert_bad_manifest_path( + "bench", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn build_dir_plus_path() { - assert_not_a_cargo_toml("bench", "foo/bar/baz"); + assert_bad_manifest_path( + "bench", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn build_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("check", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "check", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn clean_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("clean", "foo"); + assert_bad_manifest_path( + "clean", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn clean_dir_plus_file() { - assert_not_a_cargo_toml("clean", "foo/bar"); + assert_bad_manifest_path( + "clean", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn clean_dir_plus_path() { - assert_not_a_cargo_toml("clean", "foo/bar/baz"); + assert_bad_manifest_path( + "clean", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn clean_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("clean", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "clean", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn doc_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("doc", "foo"); + assert_bad_manifest_path( + "doc", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn doc_dir_plus_file() { - assert_not_a_cargo_toml("doc", "foo/bar"); + assert_bad_manifest_path( + "doc", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn doc_dir_plus_path() { - assert_not_a_cargo_toml("doc", "foo/bar/baz"); + assert_bad_manifest_path( + "doc", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn doc_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("doc", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "doc", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn fetch_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("fetch", "foo"); + assert_bad_manifest_path( + "fetch", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn fetch_dir_plus_file() { - assert_not_a_cargo_toml("fetch", "foo/bar"); + assert_bad_manifest_path( + "fetch", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn fetch_dir_plus_path() { - assert_not_a_cargo_toml("fetch", "foo/bar/baz"); + assert_bad_manifest_path( + "fetch", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn fetch_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("fetch", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "fetch", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn generate_lockfile_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("generate-lockfile", "foo"); + assert_bad_manifest_path( + "generate-lockfile", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn generate_lockfile_dir_plus_file() { - assert_not_a_cargo_toml("generate-lockfile", "foo/bar"); + assert_bad_manifest_path( + "generate-lockfile", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn generate_lockfile_dir_plus_path() { - assert_not_a_cargo_toml("generate-lockfile", "foo/bar/baz"); + assert_bad_manifest_path( + "generate-lockfile", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn generate_lockfile_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("generate-lockfile", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "generate-lockfile", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn package_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("package", "foo"); + assert_bad_manifest_path( + "package", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn package_dir_plus_file() { - assert_not_a_cargo_toml("package", "foo/bar"); + assert_bad_manifest_path( + "package", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn package_dir_plus_path() { - assert_not_a_cargo_toml("package", "foo/bar/baz"); + assert_bad_manifest_path( + "package", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn package_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("package", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "package", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn pkgid_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("pkgid", "foo"); + assert_bad_manifest_path( + "pkgid", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn pkgid_dir_plus_file() { - assert_not_a_cargo_toml("pkgid", "foo/bar"); + assert_bad_manifest_path( + "pkgid", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn pkgid_dir_plus_path() { - assert_not_a_cargo_toml("pkgid", "foo/bar/baz"); + assert_bad_manifest_path( + "pkgid", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn pkgid_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("pkgid", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "pkgid", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn publish_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("publish", "foo"); + assert_bad_manifest_path( + "publish", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn publish_dir_plus_file() { - assert_not_a_cargo_toml("publish", "foo/bar"); + assert_bad_manifest_path( + "publish", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn publish_dir_plus_path() { - assert_not_a_cargo_toml("publish", "foo/bar/baz"); + assert_bad_manifest_path( + "publish", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn publish_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("publish", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "publish", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn read_manifest_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("read-manifest", "foo"); + assert_bad_manifest_path( + "read-manifest", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn read_manifest_dir_plus_file() { - assert_not_a_cargo_toml("read-manifest", "foo/bar"); + assert_bad_manifest_path( + "read-manifest", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn read_manifest_dir_plus_path() { - assert_not_a_cargo_toml("read-manifest", "foo/bar/baz"); + assert_bad_manifest_path( + "read-manifest", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn read_manifest_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("read-manifest", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "read-manifest", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn run_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("run", "foo"); + assert_bad_manifest_path( + "run", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn run_dir_plus_file() { - assert_not_a_cargo_toml("run", "foo/bar"); + assert_bad_manifest_path( + "run", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn run_dir_plus_path() { - assert_not_a_cargo_toml("run", "foo/bar/baz"); + assert_bad_manifest_path( + "run", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn run_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("run", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "run", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn rustc_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("rustc", "foo"); + assert_bad_manifest_path( + "rustc", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn rustc_dir_plus_file() { - assert_not_a_cargo_toml("rustc", "foo/bar"); + assert_bad_manifest_path( + "rustc", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn rustc_dir_plus_path() { - assert_not_a_cargo_toml("rustc", "foo/bar/baz"); + assert_bad_manifest_path( + "rustc", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn rustc_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("rustc", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "rustc", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn test_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("test", "foo"); + assert_bad_manifest_path( + "test", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn test_dir_plus_file() { - assert_not_a_cargo_toml("test", "foo/bar"); + assert_bad_manifest_path( + "test", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn test_dir_plus_path() { - assert_not_a_cargo_toml("test", "foo/bar/baz"); + assert_bad_manifest_path( + "test", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn test_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("test", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "test", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] fn update_dir_containing_cargo_toml() { - assert_not_a_cargo_toml("update", "foo"); + assert_bad_manifest_path( + "update", + "foo", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` + +"#]], + ); } #[cargo_test] fn update_dir_plus_file() { - assert_not_a_cargo_toml("update", "foo/bar"); + assert_bad_manifest_path( + "update", + "foo/bar", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` + +"#]], + ); } #[cargo_test] fn update_dir_plus_path() { - assert_not_a_cargo_toml("update", "foo/bar/baz"); + assert_bad_manifest_path( + "update", + "foo/bar/baz", + str![[r#" +[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` + +"#]], + ); } #[cargo_test] fn update_dir_to_nonexistent_cargo_toml() { - assert_cargo_toml_doesnt_exist("update", "foo/bar/baz/Cargo.toml"); + assert_bad_manifest_path( + "update", + "foo/bar/baz/Cargo.toml", + str![[r#" +[ERROR] manifest path `foo/bar/baz/Cargo.toml` does not exist + +"#]], + ); } #[cargo_test] From 0e8570b1ec6858229e014a74c3db63ed9fbd1dfc Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 11 Feb 2026 15:30:50 -0600 Subject: [PATCH 2/2] fix(cli): Improve bad manifest error Fixes #16612 --- src/cargo/core/source_id.rs | 4 +- src/cargo/util/command_prelude.rs | 29 +++++--- src/cargo/util/toml/mod.rs | 5 +- tests/testsuite/bad_manifest_path.rs | 104 +++++++++++++++------------ tests/testsuite/metadata.rs | 6 +- tests/testsuite/read_manifest.rs | 6 +- tests/testsuite/script/cargo.rs | 4 +- 7 files changed, 92 insertions(+), 66 deletions(-) diff --git a/src/cargo/core/source_id.rs b/src/cargo/core/source_id.rs index df958bf133d..dade72b5a4b 100644 --- a/src/cargo/core/source_id.rs +++ b/src/cargo/core/source_id.rs @@ -208,7 +208,7 @@ impl SourceId { /// /// `path`: an absolute path. pub fn for_manifest_path(manifest_path: &Path) -> CargoResult { - if crate::util::toml::is_embedded(manifest_path) { + if crate::util::toml::is_embedded(manifest_path) && manifest_path.is_file() { Self::for_path(manifest_path) } else { Self::for_path(manifest_path.parent().unwrap()) @@ -404,7 +404,7 @@ impl SourceId { .url .to_file_path() .expect("path sources cannot be remote"); - if crate::util::toml::is_embedded(&path) { + if crate::util::toml::is_embedded(&path) && path.is_file() { anyhow::bail!("single file packages cannot be used as dependencies") } Ok(Box::new(PathSource::new(&path, self, gctx))) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 9efa5c73fd4..2791cb88f89 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -1083,20 +1083,31 @@ pub fn root_manifest(manifest_path: Option<&Path>, gctx: &GlobalContext) -> Carg // In general, we try to avoid normalizing paths in Cargo, // but in this particular case we need it to fix #3586. let path = paths::normalize_path(&path); - if !path.ends_with("Cargo.toml") && !crate::util::toml::is_embedded(&path) { - anyhow::bail!( - "the manifest-path must be a path to a Cargo.toml file: `{}`", - path.display() - ) - } if !path.exists() { anyhow::bail!("manifest path `{}` does not exist", manifest_path.display()) - } - if path.is_dir() { + } else if path.is_dir() { + let child_path = path.join("Cargo.toml"); + let suggested_path = if child_path.exists() { + format!("\nhelp: {} exists", child_path.display()) + } else { + "".to_string() + }; anyhow::bail!( - "manifest path `{}` is a directory but expected a file", + "manifest path `{}` is a directory but expected a file{suggested_path}", manifest_path.display() ) + } else if !path.ends_with("Cargo.toml") && !crate::util::toml::is_embedded(&path) { + if gctx.cli_unstable().script { + anyhow::bail!( + "the manifest-path must be a path to a Cargo.toml or script file: `{}`", + path.display() + ) + } else { + anyhow::bail!( + "the manifest-path must be a path to a Cargo.toml file: `{}`", + path.display() + ) + } } if crate::util::toml::is_embedded(&path) && !gctx.cli_unstable().script { anyhow::bail!("embedded manifest `{}` requires `-Zscript`", path.display()) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 27f8de9df8a..46313e9e771 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -49,10 +49,7 @@ use self::targets::to_targets; /// See also `bin/cargo/commands/run.rs`s `is_manifest_command` pub fn is_embedded(path: &Path) -> bool { let ext = path.extension(); - (ext == Some(OsStr::new("rs")) || - // Provide better errors by not considering directories to be embedded manifests - ext.is_none()) - && path.is_file() + ext == Some(OsStr::new("rs")) || ext.is_none() } /// Loads a `Cargo.toml` from a file on disk. diff --git a/tests/testsuite/bad_manifest_path.rs b/tests/testsuite/bad_manifest_path.rs index 611216b510d..cd97224b870 100644 --- a/tests/testsuite/bad_manifest_path.rs +++ b/tests/testsuite/bad_manifest_path.rs @@ -25,7 +25,8 @@ fn bench_dir_containing_cargo_toml() { "bench", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -37,7 +38,7 @@ fn bench_dir_plus_file() { "bench", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -49,7 +50,7 @@ fn bench_dir_plus_path() { "bench", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -73,7 +74,8 @@ fn build_dir_containing_cargo_toml() { "check", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -85,7 +87,7 @@ fn build_dir_plus_file() { "bench", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -97,7 +99,7 @@ fn build_dir_plus_path() { "bench", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -121,7 +123,8 @@ fn clean_dir_containing_cargo_toml() { "clean", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -133,7 +136,7 @@ fn clean_dir_plus_file() { "clean", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -145,7 +148,7 @@ fn clean_dir_plus_path() { "clean", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -169,7 +172,8 @@ fn doc_dir_containing_cargo_toml() { "doc", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -181,7 +185,7 @@ fn doc_dir_plus_file() { "doc", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -193,7 +197,7 @@ fn doc_dir_plus_path() { "doc", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -217,7 +221,8 @@ fn fetch_dir_containing_cargo_toml() { "fetch", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -229,7 +234,7 @@ fn fetch_dir_plus_file() { "fetch", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -241,7 +246,7 @@ fn fetch_dir_plus_path() { "fetch", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -265,7 +270,8 @@ fn generate_lockfile_dir_containing_cargo_toml() { "generate-lockfile", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -277,7 +283,7 @@ fn generate_lockfile_dir_plus_file() { "generate-lockfile", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -289,7 +295,7 @@ fn generate_lockfile_dir_plus_path() { "generate-lockfile", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -313,7 +319,8 @@ fn package_dir_containing_cargo_toml() { "package", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -325,7 +332,7 @@ fn package_dir_plus_file() { "package", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -337,7 +344,7 @@ fn package_dir_plus_path() { "package", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -361,7 +368,8 @@ fn pkgid_dir_containing_cargo_toml() { "pkgid", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -373,7 +381,7 @@ fn pkgid_dir_plus_file() { "pkgid", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -385,7 +393,7 @@ fn pkgid_dir_plus_path() { "pkgid", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -409,7 +417,8 @@ fn publish_dir_containing_cargo_toml() { "publish", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -421,7 +430,7 @@ fn publish_dir_plus_file() { "publish", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -433,7 +442,7 @@ fn publish_dir_plus_path() { "publish", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -457,7 +466,8 @@ fn read_manifest_dir_containing_cargo_toml() { "read-manifest", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -469,7 +479,7 @@ fn read_manifest_dir_plus_file() { "read-manifest", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -481,7 +491,7 @@ fn read_manifest_dir_plus_path() { "read-manifest", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -505,7 +515,8 @@ fn run_dir_containing_cargo_toml() { "run", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -517,7 +528,7 @@ fn run_dir_plus_file() { "run", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -529,7 +540,7 @@ fn run_dir_plus_path() { "run", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -553,7 +564,8 @@ fn rustc_dir_containing_cargo_toml() { "rustc", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -565,7 +577,7 @@ fn rustc_dir_plus_file() { "rustc", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -577,7 +589,7 @@ fn rustc_dir_plus_path() { "rustc", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -601,7 +613,8 @@ fn test_dir_containing_cargo_toml() { "test", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -613,7 +626,7 @@ fn test_dir_plus_file() { "test", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -625,7 +638,7 @@ fn test_dir_plus_path() { "test", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -649,7 +662,8 @@ fn update_dir_containing_cargo_toml() { "update", "foo", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]], ); @@ -661,7 +675,7 @@ fn update_dir_plus_file() { "update", "foo/bar", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar` +[ERROR] manifest path `foo/bar` does not exist "#]], ); @@ -673,7 +687,7 @@ fn update_dir_plus_path() { "update", "foo/bar/baz", str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz` +[ERROR] manifest path `foo/bar/baz` does not exist "#]], ); @@ -705,7 +719,7 @@ fn verify_project_dir_containing_cargo_toml() { str![[r#" [ { - "invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo`" + "invalid": "manifest path `foo` is a directory but expected a file\n[HELP] [ROOT]/foo/Cargo.toml exists" } ] "#]] @@ -729,7 +743,7 @@ fn verify_project_dir_plus_file() { str![[r#" [ { - "invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar`" + "invalid": "manifest path `foo/bar` does not exist" } ] "#]] @@ -753,7 +767,7 @@ fn verify_project_dir_plus_path() { str![[r#" [ { - "invalid": "the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/bar/baz`" + "invalid": "manifest path `foo/bar/baz` does not exist" } ] "#]] diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 872886e7c52..d42455ff388 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -2394,7 +2394,8 @@ fn cargo_metadata_no_deps_path_to_cargo_toml_parent_relative() { .cwd(p.root().parent().unwrap()) .with_status(101) .with_stderr_data(str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]]) .run(); @@ -2412,7 +2413,8 @@ fn cargo_metadata_no_deps_path_to_cargo_toml_parent_absolute() { .cwd(p.root().parent().unwrap()) .with_status(101) .with_stderr_data(str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `[ROOT]/foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]]) .run(); diff --git a/tests/testsuite/read_manifest.rs b/tests/testsuite/read_manifest.rs index 496088874e4..5e14674c901 100644 --- a/tests/testsuite/read_manifest.rs +++ b/tests/testsuite/read_manifest.rs @@ -75,7 +75,8 @@ fn cargo_read_manifest_path_to_cargo_toml_parent_relative() { .cwd(p.root().parent().unwrap()) .with_status(101) .with_stderr_data(str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]]) .run(); @@ -93,7 +94,8 @@ fn cargo_read_manifest_path_to_cargo_toml_parent_absolute() { .cwd(p.root().parent().unwrap()) .with_status(101) .with_stderr_data(str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo` +[ERROR] manifest path `[ROOT]/foo` is a directory but expected a file +[HELP] [ROOT]/foo/Cargo.toml exists "#]]) .run(); diff --git a/tests/testsuite/script/cargo.rs b/tests/testsuite/script/cargo.rs index dec2b721216..d9c3f8b8a46 100644 --- a/tests/testsuite/script/cargo.rs +++ b/tests/testsuite/script/cargo.rs @@ -1567,7 +1567,7 @@ fn cmd_check_with_missing_script_rs() { .with_status(101) .with_stdout_data("") .with_stderr_data(str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/script.rs` +[ERROR] manifest path `script.rs` does not exist "#]]) .run(); @@ -1582,7 +1582,7 @@ fn cmd_check_with_missing_script() { .with_status(101) .with_stdout_data("") .with_stderr_data(str![[r#" -[ERROR] the manifest-path must be a path to a Cargo.toml file: `[ROOT]/foo/script` +[ERROR] manifest path `script` does not exist "#]]) .run();