Skip to content

Commit 8506f66

Browse files
committed
Minor simplification to manual_map
1 parent 80a263d commit 8506f66

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

clippy_lints/src/manual_map.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,22 @@ impl LateLintPass<'_> for ManualMap {
179179
} else {
180180
""
181181
};
182+
let expr_snip = snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0;
182183
if some_expr.needs_unsafe_block {
183-
format!(
184-
"|{}{}| unsafe {{ {} }}",
185-
annotation,
186-
some_binding,
187-
snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0
188-
)
184+
format!("|{}{}| unsafe {{ {} }}", annotation, some_binding, expr_snip)
189185
} else {
190-
format!(
191-
"|{}{}| {}",
192-
annotation,
193-
some_binding,
194-
snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0
195-
)
186+
format!("|{}{}| {}", annotation, some_binding, expr_snip)
196187
}
197188
}
198189
}
199190
} else if !is_wild_none && explicit_ref.is_none() {
200191
// TODO: handle explicit reference annotations.
192+
let pat_snip = snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0;
193+
let expr_snip = snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0;
201194
if some_expr.needs_unsafe_block {
202-
format!(
203-
"|{}| unsafe {{ {} }}",
204-
snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0,
205-
snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0
206-
)
195+
format!("|{}| unsafe {{ {} }}", pat_snip, expr_snip)
207196
} else {
208-
format!(
209-
"|{}| {}",
210-
snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0,
211-
snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0
212-
)
197+
format!("|{}| {}", pat_snip, expr_snip)
213198
}
214199
} else {
215200
// Refutable bindings and mixed reference annotations can't be handled by `map`.

0 commit comments

Comments
 (0)