Skip to content

Commit c6c859b

Browse files
committed
apply fixes after breaking toml lib changes
1 parent 1d853a8 commit c6c859b

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

crates/metadata/lib.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ impl std::str::FromStr for Metadata {
325325
fn from_str(manifest: &str) -> Result<Metadata, Self::Err> {
326326
use toml::value::Table;
327327

328-
let manifest = match manifest.parse::<Value>()? {
329-
Value::Table(t) => Some(t),
330-
_ => None,
331-
};
328+
// the `Cargo.toml` is a full document, and:
329+
// > A TOML document is represented with the Table type which maps
330+
// > String to the Value enum.
331+
let manifest = manifest.parse::<Table>()?;
332332

333333
fn table<'a>(manifest: &'a Table, table_name: &str) -> Option<&'a Table> {
334334
match manifest.get(table_name) {
@@ -337,17 +337,14 @@ impl std::str::FromStr for Metadata {
337337
}
338338
}
339339

340-
let plain_table = manifest
341-
.as_ref()
342-
.and_then(|t| table(t, "package"))
343-
.and_then(|t| table(t, "metadata"))
340+
let package_metadata = table(&manifest, "package").and_then(|t| table(t, "metadata"));
341+
342+
let plain_table = package_metadata
344343
.and_then(|t| table(t, "docs"))
345344
.and_then(|t| table(t, "rs"));
346-
let quoted_table = manifest
347-
.as_ref()
348-
.and_then(|t| table(t, "package"))
349-
.and_then(|t| table(t, "metadata"))
350-
.and_then(|t| table(t, "docs.rs"));
345+
346+
let quoted_table = package_metadata.and_then(|t| table(t, "docs.rs"));
347+
351348
let mut metadata = if let Some(table) = plain_table {
352349
Value::Table(table.clone()).try_into()?
353350
} else if let Some(table) = quoted_table {
@@ -356,9 +353,7 @@ impl std::str::FromStr for Metadata {
356353
Metadata::default()
357354
};
358355

359-
let proc_macro = manifest
360-
.as_ref()
361-
.and_then(|t| table(t, "lib"))
356+
let proc_macro = table(&manifest, "lib")
362357
.and_then(|table| table.get("proc-macro").or_else(|| table.get("proc_macro")))
363358
.and_then(|val| val.as_bool());
364359
if let Some(proc_macro) = proc_macro {

0 commit comments

Comments
 (0)