Skip to content

Commit 937f921

Browse files
committed
chore: address some pedantic clippy lints
1 parent 4c89ade commit 937f921

File tree

7 files changed

+30
-22
lines changed

7 files changed

+30
-22
lines changed

confik-macros/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod tests;
2020
pub fn derive_macro_builder(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
2121
let target_struct = parse_macro_input!(input as DeriveInput);
2222

23-
match derive_macro_builder_inner(target_struct) {
23+
match derive_macro_builder_inner(&target_struct) {
2424
Ok(token_stream) => token_stream,
2525
Err(err) => err.to_compile_error().into(),
2626
}
@@ -599,7 +599,7 @@ impl ToTokens for Derive {
599599
struct RootImplementer {
600600
/// The ident/name of the target (the struct/enum the derive was called on).
601601
///
602-
/// To get the builder_name, see [`RootImplementer::builder_name`].
602+
/// To get the builder name, see [`RootImplementer::builder_name`].
603603
ident: Ident,
604604

605605
// #[darling(rename = "ident")]
@@ -716,12 +716,11 @@ impl RootImplementer {
716716
// present...
717717
//
718718
// Therefore, conditionally add the `;`.
719-
let terminator = if matches!(&self.data, ast::Data::Struct(fields) if fields.style.is_tuple())
720-
{
721-
Some(quote!(;))
722-
} else {
723-
None
724-
};
719+
let terminator = matches!(
720+
&self.data,
721+
ast::Data::Struct(fields) if fields.style.is_tuple(),
722+
)
723+
.then_some(quote!(;));
725724

726725
let (_impl_generics, type_generics, where_clause) = generics.split_for_impl();
727726

@@ -895,8 +894,8 @@ impl RootImplementer {
895894
}
896895
}
897896

898-
fn derive_macro_builder_inner(target_struct: DeriveInput) -> syn::Result<proc_macro::TokenStream> {
899-
let implementer = RootImplementer::from_derive_input(&target_struct)?;
897+
fn derive_macro_builder_inner(target_struct: &DeriveInput) -> syn::Result<proc_macro::TokenStream> {
898+
let implementer = RootImplementer::from_derive_input(target_struct)?;
900899
implementer.check_valid()?;
901900
let builder_struct = implementer.define_builder()?;
902901
let builder_impl = implementer.impl_builder();

confik/examples/defaulting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const FIELD2_DEFAULT: &str = "Hello World";
1414

1515
#[derive(Configuration, Debug, PartialEq, Eq)]
1616
struct Config {
17-
#[confik(default = 5usize)]
17+
#[confik(default = 5_usize)]
1818
field1: usize,
1919
#[confik(default = FIELD2_DEFAULT)]
2020
field2: String,

confik/src/builder.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ impl<'a, Target: Configuration> ConfigBuilder<'a, Target> {
103103
}
104104

105105
/// Attempt to build from the provided sources.
106+
///
107+
/// # Errors
108+
///
109+
/// Returns an error if a required value is missing, a secret value was provided in a non-secret
110+
/// source, or an error is returned from a source (e.g., invalid TOML). See [`Error`] for more
111+
/// details.
106112
pub fn try_build(&mut self) -> Result<Target, Error> {
107113
if self.sources.is_empty() {
108114
build_from_sources([Box::new(DefaultSource) as Box<dyn DynSource<_>>])

confik/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum Error {
3737
impl Error {
3838
/// Used in chaining [`MissingValue`] errors during [`crate::Configuration::try_build`].
3939
#[doc(hidden)]
40+
#[must_use]
4041
pub fn prepend(self, path_segment: impl Into<Cow<'static, str>>) -> Self {
4142
match self {
4243
Self::MissingValue(err) => Self::MissingValue(err.prepend(path_segment)),

confik/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,17 @@ where
9191
sources
9292
.into_iter()
9393
// Convert each source to a `Target::Builder`
94-
.map::<Result<Target::Builder, Error>, _>(|s: Box<dyn DynSource<Target::Builder> + 'a>| {
95-
let debug = || format!("{:?}", s);
96-
let res = s.provide().map_err(|e| Error::Source(e, debug()))?;
97-
if s.allows_secrets().not() {
98-
res.contains_non_secret_data()
99-
.map_err(|e| Error::UnexpectedSecret(e, debug()))?;
100-
}
101-
Ok(res)
102-
})
94+
.map::<Result<Target::Builder, Error>, _>(
95+
|source: Box<dyn DynSource<Target::Builder> + 'a>| {
96+
let debug = || format!("{source:?}");
97+
let res = source.provide().map_err(|e| Error::Source(e, debug()))?;
98+
if source.allows_secrets().not() {
99+
res.contains_non_secret_data()
100+
.map_err(|e| Error::UnexpectedSecret(e, debug()))?;
101+
}
102+
Ok(res)
103+
},
104+
)
103105
// Merge the builders
104106
.reduce(|first, second| Ok(Target::Builder::merge(first?, second?)))
105107
// If there was no data then we're missing values

confik/tests/secret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ mod toml {
113113

114114
assert_matches!(
115115
&target,
116-
Error::UnexpectedSecret(path, _) if path.to_string().contains(&format!("`{}`", expected_path))
116+
Error::UnexpectedSecret(path, _) if path.to_string().contains(&format!("`{expected_path}`"))
117117
);
118118
}
119119

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ clippy:
99

1010
msrv := ```
1111
cargo metadata --format-version=1 \
12-
| jq -r 'first(.packages[] | select(.source == null and .name == "actix-tls")) | .rust_version' \
12+
| jq -r 'first(.packages[] | select(.source == null and .rust_version)) | .rust_version' \
1313
| sed -E 's/^1\.([0-9]{2})$/1\.\1\.0/'
1414
```
1515
msrv_rustup := "+" + msrv

0 commit comments

Comments
 (0)