Skip to content

Commit ee80deb

Browse files
committed
Apply collapsible_else_if to Clippy itself
1 parent fea8dd2 commit ee80deb

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

clippy_lints/src/loops/same_item_push.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ impl<'tcx> Visitor<'tcx> for SameItemPushVisitor<'_, 'tcx> {
163163
StmtKind::Expr(expr) | StmtKind::Semi(expr) => self.visit_expr(expr),
164164
_ => {},
165165
}
166+
}
167+
// Current statement is a push ...check whether another
168+
// push had been previously done
169+
else if self.vec_push.is_none() {
170+
self.vec_push = vec_push_option;
166171
} else {
167-
// Current statement is a push ...check whether another
168-
// push had been previously done
169-
if self.vec_push.is_none() {
170-
self.vec_push = vec_push_option;
171-
} else {
172-
// There are multiple pushes ... don't lint
173-
self.multiple_pushes = true;
174-
}
172+
// There are multiple pushes ... don't lint
173+
self.multiple_pushes = true;
175174
}
176175
}
177176
}

clippy_lints/src/single_component_path_imports.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,21 @@ impl SingleComponentPathImports {
219219
}
220220
}
221221
}
222-
} else {
223-
// keep track of `use self::some_module` usages
224-
if segments[0].ident.name == kw::SelfLower {
225-
// simple case such as `use self::module::SomeStruct`
226-
if segments.len() > 1 {
227-
imports_reused_with_self.push(segments[1].ident.name);
228-
return;
229-
}
222+
}
223+
// keep track of `use self::some_module` usages
224+
else if segments[0].ident.name == kw::SelfLower {
225+
// simple case such as `use self::module::SomeStruct`
226+
if segments.len() > 1 {
227+
imports_reused_with_self.push(segments[1].ident.name);
228+
return;
229+
}
230230

231-
// nested case such as `use self::{module1::Struct1, module2::Struct2}`
232-
if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
233-
for tree in items {
234-
let segments = &tree.0.prefix.segments;
235-
if !segments.is_empty() {
236-
imports_reused_with_self.push(segments[0].ident.name);
237-
}
231+
// nested case such as `use self::{module1::Struct1, module2::Struct2}`
232+
if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
233+
for tree in items {
234+
let segments = &tree.0.prefix.segments;
235+
if !segments.is_empty() {
236+
imports_reused_with_self.push(segments[0].ident.name);
238237
}
239238
}
240239
}

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -606,32 +606,31 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span
606606
let ctxt = span.ctxt();
607607
if ctxt == SyntaxContext::root() {
608608
HasSafetyComment::Maybe
609-
} else {
610-
// From a macro expansion. Get the text from the start of the macro declaration to start of the
611-
// unsafe block.
612-
// macro_rules! foo { () => { stuff }; (x) => { unsafe { stuff } }; }
613-
// ^--------------------------------------------^
614-
if let Ok(unsafe_line) = source_map.lookup_line(span.lo())
615-
&& let Ok(macro_line) = source_map.lookup_line(ctxt.outer_expn_data().def_site.lo())
616-
&& Arc::ptr_eq(&unsafe_line.sf, &macro_line.sf)
617-
&& let Some(src) = unsafe_line.sf.src.as_deref()
618-
{
619-
if macro_line.line < unsafe_line.line {
620-
match text_has_safety_comment(
621-
src,
622-
&unsafe_line.sf.lines()[macro_line.line + 1..=unsafe_line.line],
623-
unsafe_line.sf.start_pos,
624-
) {
625-
Some(b) => HasSafetyComment::Yes(b),
626-
None => HasSafetyComment::No,
627-
}
628-
} else {
629-
HasSafetyComment::No
609+
}
610+
// From a macro expansion. Get the text from the start of the macro declaration to start of the
611+
// unsafe block.
612+
// macro_rules! foo { () => { stuff }; (x) => { unsafe { stuff } }; }
613+
// ^--------------------------------------------^
614+
else if let Ok(unsafe_line) = source_map.lookup_line(span.lo())
615+
&& let Ok(macro_line) = source_map.lookup_line(ctxt.outer_expn_data().def_site.lo())
616+
&& Arc::ptr_eq(&unsafe_line.sf, &macro_line.sf)
617+
&& let Some(src) = unsafe_line.sf.src.as_deref()
618+
{
619+
if macro_line.line < unsafe_line.line {
620+
match text_has_safety_comment(
621+
src,
622+
&unsafe_line.sf.lines()[macro_line.line + 1..=unsafe_line.line],
623+
unsafe_line.sf.start_pos,
624+
) {
625+
Some(b) => HasSafetyComment::Yes(b),
626+
None => HasSafetyComment::No,
630627
}
631628
} else {
632-
// Problem getting source text. Pretend a comment was found.
633-
HasSafetyComment::Maybe
629+
HasSafetyComment::No
634630
}
631+
} else {
632+
// Problem getting source text. Pretend a comment was found.
633+
HasSafetyComment::Maybe
635634
}
636635
}
637636

0 commit comments

Comments
 (0)