Skip to content

Commit

Permalink
simplify by not returning an additional Expr from the IdentIter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan1729 committed Oct 1, 2020
1 parent b85ac8d commit 442bb91
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions clippy_lints/src/suspicious_chained_operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ fn ident_difference(left: &Expr, right: &Expr) -> IdentDifference {
fn get_ident(expr: &Expr, location: IdentLocation) -> Option<Ident> {
IdentIter::new(expr)
.nth(location.index)
.map(|(ident, _)| ident)
}

fn suggestion_with_swapped_ident(
Expand All @@ -254,22 +253,21 @@ fn suggestion_with_swapped_ident(
ident: Ident,
applicability: &mut Applicability,
) -> Option<String> {
IdentIter::new(expr)
.nth(location.index)
.map(|(current_ident, current_expr)| {
get_ident(expr, location)
.map(|current_ident| {
format!(
"{}{}{}",
snippet_with_applicability(
cx,
current_expr.span
expr.span
.with_hi(current_ident.span.lo()),
"..",
applicability
),
current_ident.to_string(),
snippet_with_applicability(
cx,
current_expr.span
expr.span
.with_lo(current_ident.span.hi()),
"..",
applicability
Expand Down Expand Up @@ -302,7 +300,7 @@ impl <'expr> IdentIter<'expr> {
}

impl <'expr> Iterator for IdentIter<'expr> {
type Item = (Ident, &'expr Expr);
type Item = Ident;

fn next(&mut self) -> Option<Self::Item> {
if self.done {
Expand Down Expand Up @@ -336,11 +334,9 @@ impl <'expr> Iterator for IdentIter<'expr> {
ExprKind::Lit(_)|ExprKind::Err => None,
ExprKind::Path(_, ref path)
| ExprKind::MacCall(MacCall{ ref path, ..}) => {
let current_expr: &'expr Expr = self.expr;

set_and_call_next!(
path.segments.iter()
.map(move |s| (s.ident, current_expr))
.map(|s| s.ident)
)
},
ExprKind::Box(ref expr)
Expand All @@ -365,10 +361,8 @@ impl <'expr> Iterator for IdentIter<'expr> {
)
},
ExprKind::MethodCall(ref method_name, ref args, _) => {
let current_expr: &'expr Expr = self.expr;

set_and_call_next!(
iter::once((method_name.ident, current_expr))
iter::once(method_name.ident)
.chain(
args.iter()
.flat_map(IdentIter::new_p)
Expand Down

0 comments on commit 442bb91

Please sign in to comment.