Skip to content

Commit ceb65c8

Browse files
mo8itSergioBenitez
authored andcommitted
Apply some Clippy lints.
1 parent 6a363a1 commit ceb65c8

File tree

13 files changed

+50
-52
lines changed

13 files changed

+50
-52
lines changed

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl From<String> for Error {
438438
impl Display for Kind {
439439
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
440440
match self {
441-
Kind::Message(msg) => f.write_str(&msg),
441+
Kind::Message(msg) => f.write_str(msg),
442442
Kind::InvalidType(v, exp) => {
443443
write!(f, "invalid type: found {}, expected {}", v, exp)
444444
}

src/figment.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ impl Figment {
159159
(Err(e), Err(prev)) => Err(e.retagged(tag).chain(prev)),
160160
(Ok(mut new), Ok(old)) => {
161161
new.iter_mut()
162-
.map(|(p, map)| std::iter::repeat(p).zip(map.values_mut()))
163-
.flatten()
162+
.flat_map(|(p, map)| std::iter::repeat(p).zip(map.values_mut()))
164163
.for_each(|(p, v)| v.map_tag(|t| *t = tag.for_profile(p)));
165164

166165
Ok(old.coalesce(new, order))

src/jail.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ impl Jail {
320320
pub fn clear_env(&mut self) {
321321
for (key, val) in std::env::vars_os() {
322322
std::env::remove_var(&key);
323-
if !self.saved_env_vars.contains_key(&key) {
324-
self.saved_env_vars.insert(key, Some(val));
325-
}
323+
self.saved_env_vars.entry(key).or_insert(Some(val));
326324
}
327325
}
328326

@@ -356,7 +354,7 @@ impl Jail {
356354

357355
impl Drop for Jail {
358356
fn drop(&mut self) {
359-
for (key, value) in self.saved_env_vars.iter() {
357+
for (key, value) in &self.saved_env_vars {
360358
match value {
361359
Some(val) => std::env::set_var(key, val),
362360
None => std::env::remove_var(key)

src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl fmt::Display for Source {
292292
Source::File(p) => {
293293
use {std::env::current_dir, crate::util::diff_paths};
294294

295-
match current_dir().ok().and_then(|cwd| diff_paths(p, &cwd)) {
295+
match current_dir().ok().and_then(|cwd| diff_paths(p, cwd)) {
296296
Some(r) if r.iter().count() < p.iter().count() => r.display().fmt(f),
297297
Some(_) | None => p.display().fmt(f)
298298
}

src/providers/data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ impl<F: Format> Provider for Data<F> {
290290
use Source::*;
291291
let map: Result<Map<Profile, Dict>, _> = match (&self.source, &self.profile) {
292292
(File(None), _) => return Ok(Map::new()),
293-
(File(Some(path)), None) => F::from_path(&path),
294-
(String(s), None) => F::from_str(&s),
295-
(File(Some(path)), Some(prof)) => F::from_path(&path).map(|v| prof.collect(v)),
296-
(String(s), Some(prof)) => F::from_str(&s).map(|v| prof.collect(v)),
293+
(File(Some(path)), None) => F::from_path(path),
294+
(String(s), None) => F::from_str(s),
295+
(File(Some(path)), Some(prof)) => F::from_path(path).map(|v| prof.collect(v)),
296+
(String(s), Some(prof)) => F::from_str(s).map(|v| prof.collect(v)),
297297
};
298298

299299
Ok(map.map_err(|e| e.to_string())?)

src/providers/env.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl Env {
232232
pub fn filter<F: Clone + 'static>(self, filter: F) -> Self
233233
where F: Fn(&UncasedStr) -> bool
234234
{
235-
self.chain(move |prev| prev.filter(|v| filter(&v)))
235+
self.chain(move |prev| prev.filter(|v| filter(v)))
236236
}
237237

238238
/// Applys an additional mapping to the keys of environment variables being
@@ -432,7 +432,7 @@ impl Env {
432432
/// });
433433
/// ```
434434
pub fn ignore(self, keys: &[&str]) -> Self {
435-
let keys: Vec<String> = keys.iter().map(|s| s.to_string()).collect();
435+
let keys: Vec<String> = keys.iter().map(|s| (*s).to_string()).collect();
436436
self.filter(move |key| !keys.iter().any(|k| k.as_str() == key))
437437
}
438438

@@ -461,7 +461,7 @@ impl Env {
461461
/// });
462462
/// ```
463463
pub fn only(self, keys: &[&str]) -> Self {
464-
let keys: Vec<String> = keys.iter().map(|s| s.to_string()).collect();
464+
let keys: Vec<String> = keys.iter().map(|s| (*s).to_string()).collect();
465465
self.filter(move |key| keys.iter().any(|k| k.as_str() == key))
466466
}
467467

src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub fn diff_paths<P, B>(path: P, base: B) -> Option<PathBuf>
8484
}
8585
(None, _) => comps.push(Component::ParentDir),
8686
(Some(a), Some(b)) if comps.is_empty() && a == b => (),
87-
(Some(a), Some(b)) if b == Component::CurDir => comps.push(a),
88-
(Some(_), Some(b)) if b == Component::ParentDir => return None,
87+
(Some(a), Some(Component::CurDir)) => comps.push(a),
88+
(Some(_), Some(Component::ParentDir)) => return None,
8989
(Some(a), Some(_)) => {
9090
comps.push(Component::ParentDir);
9191
for _ in itb {

src/value/de.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'de: 'c, 'c, I: Interpreter> Deserializer<'de> for ConfiguredValueDe<'c, I>
9999
_ => visitor.visit_some(self)
100100
};
101101

102-
result.map_err(|e| e.retagged(tag).resolved(&config))
102+
result.map_err(|e| e.retagged(tag).resolved(config))
103103
}
104104

105105
fn deserialize_struct<V: Visitor<'de>>(
@@ -145,7 +145,7 @@ impl<'de: 'c, 'c, I: Interpreter> Deserializer<'de> for ConfiguredValueDe<'c, I>
145145
_ => self.deserialize_any(v)
146146
};
147147

148-
result.map_err(|e| e.retagged(tag).resolved(&config))
148+
result.map_err(|e| e.retagged(tag).resolved(config))
149149
}
150150

151151
fn deserialize_newtype_struct<V: Visitor<'de>>(
@@ -432,10 +432,10 @@ impl<'de> Deserialize<'de> for Value {
432432
// Total hack to "fingerprint" our deserializer by checking if
433433
// human_readable changes, which does for ours but shouldn't for others.
434434
let (a, b) = (de.is_human_readable(), de.is_human_readable());
435-
if a != b {
436-
de.deserialize_struct(Value::NAME, Value::FIELDS, ValueVisitor)
437-
} else {
435+
if a == b {
438436
de.deserialize_any(ValueVisitor)
437+
} else {
438+
de.deserialize_struct(Value::NAME, Value::FIELDS, ValueVisitor)
439439
}
440440
}
441441
}

src/value/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn escape(string: &str) -> Result<Cow<'_, str>, Error> {
3737
Some((_, 'n')) => val.push('\n'),
3838
Some((_, 'r')) => val.push('\r'),
3939
Some((_, 't')) => val.push('\t'),
40-
Some((i, c @ 'u')) | Some((i, c @ 'U')) => {
40+
Some((i, c @ ('u' | 'U'))) => {
4141
let len = if c == 'u' { 4 } else { 8 };
4242
val.push(hex(&mut chars, i, len)?);
4343
}
@@ -64,7 +64,7 @@ fn hex<I>(mut chars: I, i: usize, len: usize) -> Result<char, Error>
6464
let mut buf = String::with_capacity(len);
6565
for _ in 0..len {
6666
match chars.next() {
67-
Some((_, ch)) if ch as u32 <= 0x7F && ch.is_digit(16) => buf.push(ch),
67+
Some((_, ch)) if ch as u32 <= 0x7F && ch.is_ascii_hexdigit() => buf.push(ch),
6868
Some((i, ch)) => return Err(Error::InvalidHexEscape(i, ch)),
6969
None => return Err(Error::UnterminatedString(0)),
7070
}

src/value/magic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl Magic for RelativePathBuf {
203203
}
204204

205205
// If we have this struct with no metadata_path, still use the value.
206-
let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(&de.value);
206+
let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(de.value);
207207
map.insert(Self::FIELDS[1].into(), value.clone());
208208
visitor.visit_map(MapDe::new(&map, |v| ConfiguredValueDe::<I>::from(config, v)))
209209
}
@@ -592,7 +592,7 @@ impl<T: for<'de> Deserialize<'de>> Magic for Tagged<T> {
592592
}
593593

594594
// If we have this struct with default tag, use the value.
595-
let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(&de.value);
595+
let value = de.value.find_ref(Self::FIELDS[1]).unwrap_or(de.value);
596596
map.insert(Self::FIELDS[0].into(), de.value.tag().into());
597597
map.insert(Self::FIELDS[1].into(), value.clone());
598598
visitor.visit_map(MapDe::new(&map, |v| ConfiguredValueDe::<I>::from(config, v)))

0 commit comments

Comments
 (0)