mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
fix(schema): Mark package.name as optional
This commit is contained in:
parent
911f174832
commit
6ec8da96f4
@ -241,7 +241,10 @@
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"version": {
|
||||
"anyOf": [
|
||||
@ -475,10 +478,7 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
},
|
||||
"InheritableField_for_string": {
|
||||
"description": "An enum that allows for inheriting keys from a workspace in a Cargo.toml.",
|
||||
|
@ -178,8 +178,8 @@ pub struct TomlPackage {
|
||||
pub edition: Option<InheritableString>,
|
||||
#[cfg_attr(feature = "unstable-schema", schemars(with = "Option<String>"))]
|
||||
pub rust_version: Option<InheritableRustVersion>,
|
||||
#[cfg_attr(feature = "unstable-schema", schemars(with = "String"))]
|
||||
pub name: PackageName,
|
||||
#[cfg_attr(feature = "unstable-schema", schemars(with = "Option<String>"))]
|
||||
pub name: Option<PackageName>,
|
||||
pub version: Option<InheritableSemverVersion>,
|
||||
pub authors: Option<InheritableVecString>,
|
||||
pub build: Option<StringOrBool>,
|
||||
@ -226,7 +226,7 @@ pub struct TomlPackage {
|
||||
impl TomlPackage {
|
||||
pub fn new(name: PackageName) -> Self {
|
||||
Self {
|
||||
name,
|
||||
name: Some(name),
|
||||
|
||||
edition: None,
|
||||
rust_version: None,
|
||||
@ -263,6 +263,10 @@ impl TomlPackage {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn normalized_name(&self) -> Result<&PackageName, UnresolvedError> {
|
||||
self.name.as_ref().ok_or(UnresolvedError)
|
||||
}
|
||||
|
||||
pub fn normalized_edition(&self) -> Result<Option<&String>, UnresolvedError> {
|
||||
self.edition.as_ref().map(|v| v.normalized()).transpose()
|
||||
}
|
||||
|
@ -322,7 +322,10 @@ fn normalize_toml(
|
||||
if let Some(original_package) = original_toml.package() {
|
||||
let normalized_package =
|
||||
normalize_package_toml(original_package, manifest_file, is_embedded, gctx, &inherit)?;
|
||||
let package_name = &normalized_package.name.clone();
|
||||
let package_name = &normalized_package
|
||||
.normalized_name()
|
||||
.expect("previously normalized")
|
||||
.clone();
|
||||
let edition = normalized_package
|
||||
.normalized_edition()
|
||||
.expect("previously normalized")
|
||||
@ -582,7 +585,12 @@ fn normalize_package_toml<'a>(
|
||||
.map(|value| field_inherit_with(value, "rust-version", || inherit()?.rust_version()))
|
||||
.transpose()?
|
||||
.map(manifest::InheritableField::Value);
|
||||
let name = original_package.name.clone();
|
||||
let name = Some(
|
||||
original_package
|
||||
.name
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow::format_err!("missing field `package.name`"))?,
|
||||
);
|
||||
let version = original_package
|
||||
.version
|
||||
.clone()
|
||||
@ -1198,7 +1206,9 @@ pub fn to_real_manifest(
|
||||
let normalized_package = normalized_toml
|
||||
.package()
|
||||
.expect("previously verified to have a `[package]`");
|
||||
let package_name = &normalized_package.name;
|
||||
let package_name = normalized_package
|
||||
.normalized_name()
|
||||
.expect("previously normalized");
|
||||
if package_name.contains(':') {
|
||||
features.require(Feature::open_namespaces())?;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ pub(super) fn to_targets(
|
||||
|
||||
targets.push(Target::metabuild_target(&format!(
|
||||
"metabuild-{}",
|
||||
package.name
|
||||
package.normalized_name().expect("previously normalized")
|
||||
)));
|
||||
}
|
||||
|
||||
|
@ -484,12 +484,10 @@ fn cargo_toml_missing_package_name() {
|
||||
p.cargo("check")
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] missing field `name`
|
||||
--> Cargo.toml:2:16
|
||||
|
|
||||
2 | [package]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
||||
|
||||
Caused by:
|
||||
missing field `package.name`
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
Loading…
x
Reference in New Issue
Block a user