From 34cedd6d028a675555bc77265b529ddcd58baa23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 27 Aug 2024 09:57:58 +0200 Subject: [PATCH 1/3] Upgrade all dependencies --- Cargo.toml | 8 ++++---- src/lib.rs | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb869c2..040048c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,9 @@ readme = "./README.md" rust-version = "1.67.0" [dependencies] -toml_edit = "0.21.0" +toml_edit = "0.22.20" [dev-dependencies] -quote = "1.0.33" -syn = "2.0.37" -proc-macro2 = "1.0.67" +quote = "1.0.37" +syn = "2.0.76" +proc-macro2 = "1.0.86" diff --git a/src/lib.rs b/src/lib.rs index c9817eb..9e3ddfd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,7 +94,7 @@ use std::{ time::SystemTime, }; -use toml_edit::{Document, Item, Table, TomlError}; +use toml_edit::{DocumentMut, Item, Table, TomlError}; /// Error type used by this crate. pub enum Error { @@ -302,7 +302,7 @@ fn read_cargo_toml( /// Returns a hash map that maps from dep name to the package name. Dep name /// and package name can be the same if there doesn't exist any rename. fn extract_workspace_dependencies( - workspace_toml: &Document, + workspace_toml: &DocumentMut, ) -> Result, Error> { Ok(workspace_dep_tables(&workspace_toml) .into_iter() @@ -316,7 +316,7 @@ fn extract_workspace_dependencies( } /// Return an iterator over all `[workspace.dependencies]` -fn workspace_dep_tables(cargo_toml: &Document) -> Option<&Table> { +fn workspace_dep_tables(cargo_toml: &DocumentMut) -> Option<&Table> { cargo_toml .get("workspace") .and_then(|w| w.as_table()?.get("dependencies")?.as_table()) @@ -328,16 +328,16 @@ fn sanitize_crate_name>(name: S) -> String { } /// Open the given `Cargo.toml` and parse it into a hashmap. -fn open_cargo_toml(path: &Path) -> Result { +fn open_cargo_toml(path: &Path) -> Result { let content = fs::read_to_string(path) .map_err(|e| Error::CouldNotRead { source: e, path: path.into() })?; - content.parse::().map_err(|e| Error::InvalidToml { source: e }) + content.parse::().map_err(|e| Error::InvalidToml { source: e }) } /// Extract all crate names from the given `Cargo.toml` by checking the `dependencies` and /// `dev-dependencies`. fn extract_crate_names( - cargo_toml: &Document, + cargo_toml: &DocumentMut, workspace_dependencies: BTreeMap, ) -> Result { let package_name = extract_package_name(cargo_toml); @@ -377,11 +377,11 @@ fn extract_crate_names( Ok(root_pkg.into_iter().chain(dep_pkgs).collect()) } -fn extract_package_name(cargo_toml: &Document) -> Option<&str> { +fn extract_package_name(cargo_toml: &DocumentMut) -> Option<&str> { cargo_toml.get("package")?.get("name")?.as_str() } -fn target_dep_tables(cargo_toml: &Document) -> impl Iterator { +fn target_dep_tables(cargo_toml: &DocumentMut) -> impl Iterator { cargo_toml.get("target").into_iter().filter_map(Item::as_table).flat_map(|t| { t.iter().map(|(_, value)| value).filter_map(Item::as_table).flat_map(dep_tables) }) @@ -408,9 +408,11 @@ mod tests { ) => { #[test] fn $name() { - let cargo_toml = $cargo_toml.parse::() + let cargo_toml = $cargo_toml.parse::() .expect("Parses `Cargo.toml`"); - let workspace_cargo_toml = $workspace_toml.parse::() + let workspace_cargo_toml = $workspace_toml.parse::() .expect("Parses workspace `Cargo.toml`"); let workspace_deps = extract_workspace_dependencies(&workspace_cargo_toml) From 0a46dbc80da4d614eba4db576598b5a010c6c35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 27 Aug 2024 10:04:20 +0200 Subject: [PATCH 2/3] Small formatting fix --- src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9e3ddfd..fe46eb3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -408,11 +408,9 @@ mod tests { ) => { #[test] fn $name() { - let cargo_toml = $cargo_toml.parse::() + let cargo_toml = $cargo_toml.parse::() .expect("Parses `Cargo.toml`"); - let workspace_cargo_toml = $workspace_toml.parse::() + let workspace_cargo_toml = $workspace_toml.parse::() .expect("Parses workspace `Cargo.toml`"); let workspace_deps = extract_workspace_dependencies(&workspace_cargo_toml) From 310085871cd7b2856c40219c73d247479cc0f228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 27 Aug 2024 10:04:56 +0200 Subject: [PATCH 3/3] Bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 040048c..0e94526 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "proc-macro-crate" -version = "3.1.0" +version = "3.2.0" authors = ["Bastian Köcher "] edition = "2021" categories = ["development-tools::procedural-macro-helpers"]