Skip to content

Commit bd32589

Browse files
committed
Merge pull request #747 from Manishearth/clippy
Clippy rustfmt
2 parents f5bd7b7 + ffe9c9d commit bd32589

File tree

6 files changed

+21
-31
lines changed

6 files changed

+21
-31
lines changed

src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn rewrite_closure(capture: ast::CaptureClause,
382382
let rewrite = inner_expr.rewrite(context, budget, offset + extra_offset);
383383

384384
// Checks if rewrite succeeded and fits on a single line.
385-
let accept_rewrite = rewrite.as_ref().map(|result| !result.contains('\n')).unwrap_or(false);
385+
let accept_rewrite = rewrite.as_ref().map_or(false, |result| !result.contains('\n'));
386386

387387
if accept_rewrite {
388388
return Some(format!("{}{}{}{}", prefix, spacer, rewrite.unwrap(), closer));

src/items.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,15 @@ fn format_tuple_struct(context: &RewriteContext,
693693
let where_budget = try_opt!(context.config
694694
.max_width
695695
.checked_sub(last_line_width(&result)));
696-
let where_clause_str = try_opt!(rewrite_where_clause(context,
697-
&generics.where_clause,
698-
context.config,
699-
context.config.item_brace_style,
700-
context.block_indent,
701-
where_budget,
702-
Density::Compressed,
703-
";",
704-
None));
705-
706-
where_clause_str
696+
try_opt!(rewrite_where_clause(context,
697+
&generics.where_clause,
698+
context.config,
699+
context.config.item_brace_style,
700+
context.block_indent,
701+
where_budget,
702+
Density::Compressed,
703+
";",
704+
None))
707705
}
708706
None => "".to_owned(),
709707
};
@@ -1114,8 +1112,7 @@ fn rewrite_fn_base(context: &RewriteContext,
11141112
// A conservative estimation, to goal is to be over all parens in generics
11151113
let args_start = generics.ty_params
11161114
.last()
1117-
.map(|tp| end_typaram(tp))
1118-
.unwrap_or(span.lo);
1115+
.map_or(span.lo, |tp| end_typaram(tp));
11191116
let args_span = mk_sp(span_after(mk_sp(args_start, span.hi), "(", context.codemap),
11201117
span_for_return(&fd.output).lo);
11211118
let arg_str = try_opt!(rewrite_args(context,
@@ -1243,11 +1240,10 @@ fn rewrite_args(context: &RewriteContext,
12431240
let min_args = explicit_self.and_then(|explicit_self| {
12441241
rewrite_explicit_self(explicit_self, args, context)
12451242
})
1246-
.map(|self_str| {
1243+
.map_or(1, |self_str| {
12471244
arg_item_strs[0] = self_str;
12481245
2
1249-
})
1250-
.unwrap_or(1);
1246+
});
12511247

12521248
// Comments between args.
12531249
let mut arg_items = Vec::new();

src/lists.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ pub struct ListItem {
129129

130130
impl ListItem {
131131
pub fn is_multiline(&self) -> bool {
132-
self.item.as_ref().map(|s| s.contains('\n')).unwrap_or(false) ||
133-
self.pre_comment.is_some() ||
134-
self.post_comment.as_ref().map(|s| s.contains('\n')).unwrap_or(false)
132+
self.item.as_ref().map_or(false, |s| s.contains('\n')) || self.pre_comment.is_some() ||
133+
self.post_comment.as_ref().map_or(false, |s| s.contains('\n'))
135134
}
136135

137136
pub fn has_line_pre_comment(&self) -> bool {
@@ -156,10 +155,7 @@ pub enum DefinitiveListTactic {
156155
Mixed,
157156
}
158157

159-
pub fn definitive_tactic<'t, I, T>(items: I,
160-
tactic: ListTactic,
161-
width: usize)
162-
-> DefinitiveListTactic
158+
pub fn definitive_tactic<I, T>(items: I, tactic: ListTactic, width: usize) -> DefinitiveListTactic
163159
where I: IntoIterator<Item = T> + Clone,
164160
T: AsRef<ListItem>
165161
{
@@ -493,7 +489,7 @@ fn needs_trailing_separator(separator_tactic: SeparatorTactic,
493489
}
494490

495491
/// Returns the count and total width of the list items.
496-
fn calculate_width<'li, I, T>(items: I) -> (usize, usize)
492+
fn calculate_width<I, T>(items: I) -> (usize, usize)
497493
where I: IntoIterator<Item = T>,
498494
T: AsRef<ListItem>
499495
{
@@ -505,7 +501,7 @@ fn calculate_width<'li, I, T>(items: I) -> (usize, usize)
505501
fn total_item_width(item: &ListItem) -> usize {
506502
comment_len(item.pre_comment.as_ref().map(|x| &(*x)[..])) +
507503
comment_len(item.post_comment.as_ref().map(|x| &(*x)[..])) +
508-
item.item.as_ref().map(|str| str.len()).unwrap_or(0)
504+
item.item.as_ref().map_or(0, |str| str.len())
509505
}
510506

511507
fn comment_len(comment: Option<&str>) -> usize {

src/missed_spans.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ impl<'a> FmtVisitor<'a> {
122122
.skip_while(|rev_c| [' ', '\t'].contains(&rev_c))
123123
.next();
124124

125-
let fix_indent = last_char.map(|rev_c| ['{', '\n'].contains(&rev_c))
126-
.unwrap_or(true);
125+
let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c));
127126

128127
if rewrite_next_comment && fix_indent {
129128
if let Some('{') = last_char {

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn rewrite_path(context: &RewriteContext,
3030
width: usize,
3131
offset: Indent)
3232
-> Option<String> {
33-
let skip_count = qself.map(|x| x.position).unwrap_or(0);
33+
let skip_count = qself.map_or(0, |x| x.position);
3434

3535
let mut result = if path.global {
3636
"::".to_owned()

src/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool {
117117
pub fn end_typaram(typaram: &ast::TyParam) -> BytePos {
118118
typaram.bounds
119119
.last()
120-
.map(|bound| {
120+
.map_or(typaram.span, |bound| {
121121
match *bound {
122122
ast::RegionTyParamBound(ref lt) => lt.span,
123123
ast::TraitTyParamBound(ref prt, _) => prt.span,
124124
}
125125
})
126-
.unwrap_or(typaram.span)
127126
.hi
128127
}
129128

0 commit comments

Comments
 (0)