1
Fork 0

Changed unwrap_or to unwrap_or_else in some places.

The discussion seems to have resolved that this lint is a bit "noisy" in
that applying it in all places would result in a reduction in
readability.

A few of the trivial functions (like `Path::new`) are fine to leave
outside of closures.

The general rule seems to be that anything that is obviously an
allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it
is a 0-sized allocation.
This commit is contained in:
Nicholas-Baron 2020-11-06 13:24:55 -08:00
parent 38030ffb4e
commit 261ca04c92
14 changed files with 31 additions and 30 deletions

View file

@ -66,7 +66,7 @@ impl NestedMetaItem {
self.meta_item().and_then(|meta_item| meta_item.ident())
}
pub fn name_or_empty(&self) -> Symbol {
self.ident().unwrap_or(Ident::invalid()).name
self.ident().unwrap_or_else(Ident::invalid).name
}
/// Gets the string value if `self` is a `MetaItem` and the `MetaItem` is a
@ -139,7 +139,7 @@ impl Attribute {
}
}
pub fn name_or_empty(&self) -> Symbol {
self.ident().unwrap_or(Ident::invalid()).name
self.ident().unwrap_or_else(Ident::invalid).name
}
pub fn value_str(&self) -> Option<Symbol> {
@ -183,7 +183,7 @@ impl MetaItem {
if self.path.segments.len() == 1 { Some(self.path.segments[0].ident) } else { None }
}
pub fn name_or_empty(&self) -> Symbol {
self.ident().unwrap_or(Ident::invalid()).name
self.ident().unwrap_or_else(Ident::invalid).name
}
// Example: