Skip to content

Commit fe9047f

Browse files
committed
fix or allow clippy lints
1 parent 927ba3a commit fe9047f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ partial_pub_fields = { level = "allow", priority = 1 }
5757
pattern_type_mismatch = { level = "allow", priority = 1 }
5858
std_instead_of_alloc = { level = "allow", priority = 1 }
5959
arbitrary_source_item_ordering = { level = "allow", priority = 1 }
60+
missing_inline_in_public_items = { level = "allow", priority = 1 }

crates/cargo-gpu/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Config {
2525
/// `Cargo.toml`, so here we load that config first as the base config, and the CLI arguments can
2626
/// then later override it.
2727
pub fn clap_command_with_cargo_config(
28-
shader_crate_path: &std::path::PathBuf,
28+
shader_crate_path: &std::path::Path,
2929
mut env_args: Vec<String>,
3030
metadata: &mut MetadataCache,
3131
) -> anyhow::Result<crate::build::Build> {

crates/cargo-gpu/src/metadata.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct MetadataCache {
1717
}
1818

1919
impl MetadataCache {
20+
/// Return the cached cargo metadata for the Cargo.toml at the given path,
21+
/// or find it, populate the cache with it and return it.
2022
fn get_metadata(
2123
&mut self,
2224
maybe_path_to_manifest_dir: Option<&std::path::Path>,
@@ -32,11 +34,15 @@ impl MetadataCache {
3234
self.inner.insert(path.clone(), metadata);
3335
}
3436

35-
// UNWRAP: safe because we just inserted it
36-
Ok(self.inner.get(&path).unwrap())
37+
self.inner.get(&path).context("unreachable")
3738
}
3839

3940
/// Resolve a package name to a crate directory.
41+
///
42+
/// ## Errors
43+
/// * if fetching cargo metadata fails.
44+
/// * if no packages are listed in the cargo metadata.
45+
/// * if the manifest path has no parent.
4046
pub fn resolve_package_to_shader_crate(
4147
&mut self,
4248
package: &str,
@@ -69,7 +75,10 @@ impl MetadataCache {
6975
/// First we generate the CLI arg defaults as JSON. Then on top of those we merge any config
7076
/// from the workspace `Cargo.toml`, then on top of those we merge any config from the shader
7177
/// crate's `Cargo.toml`.
72-
pub fn as_json(&mut self, path: &std::path::PathBuf) -> anyhow::Result<Value> {
78+
///
79+
/// ## Errors
80+
/// Errors if cargo metadata cannot be found or if it cannot be operated on.
81+
pub fn as_json(&mut self, path: &std::path::Path) -> anyhow::Result<Value> {
7382
log::debug!("reading package metadata from {}", path.display());
7483
let cargo_json = self.get_cargo_toml_as_json(path)?;
7584
let config = Self::merge_configs(&cargo_json, path)?;
@@ -121,9 +130,9 @@ impl MetadataCache {
121130
/// Convert a `Cargo.toml` to JSON
122131
fn get_cargo_toml_as_json(
123132
&mut self,
124-
path: &std::path::PathBuf,
133+
path: &std::path::Path,
125134
) -> anyhow::Result<cargo_metadata::Metadata> {
126-
self.get_metadata(Some(path.as_path())).cloned()
135+
self.get_metadata(Some(path)).cloned()
127136
}
128137

129138
/// Get any `rust-gpu` metadata set in the crate's `Cargo.toml`

0 commit comments

Comments
 (0)