Skip to content

Commit e7edf45

Browse files
committed
Apply collapsible_else_if to Clippy itself
1 parent cc44343 commit e7edf45

File tree

3 files changed

+37
-43
lines changed

3 files changed

+37
-43
lines changed

clippy_lints/src/loops/same_item_push.rs

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

clippy_lints/src/single_component_path_imports.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,21 @@ impl SingleComponentPathImports {
219219
}
220220
}
221221
}
222-
} else {
222+
} else if segments[0].ident.name == kw::SelfLower {
223223
// 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-
}
230224

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-
}
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+
}
230+
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: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -606,32 +606,30 @@ 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.
609+
} else if let Ok(unsafe_line) = source_map.lookup_line(span.lo())
610+
// From a macro expansion. Get the text from the start of the macro declaration to start of
611+
// the unsafe block.
612612
// macro_rules! foo { () => { stuff }; (x) => { unsafe { stuff } }; }
613613
// ^--------------------------------------------^
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
614+
&& let Ok(macro_line) = source_map.lookup_line(ctxt.outer_expn_data().def_site.lo())
615+
&& Arc::ptr_eq(&unsafe_line.sf, &macro_line.sf)
616+
&& let Some(src) = unsafe_line.sf.src.as_deref()
617+
{
618+
if macro_line.line < unsafe_line.line {
619+
match text_has_safety_comment(
620+
src,
621+
&unsafe_line.sf.lines()[macro_line.line + 1..=unsafe_line.line],
622+
unsafe_line.sf.start_pos,
623+
) {
624+
Some(b) => HasSafetyComment::Yes(b),
625+
None => HasSafetyComment::No,
630626
}
631627
} else {
632-
// Problem getting source text. Pretend a comment was found.
633-
HasSafetyComment::Maybe
628+
HasSafetyComment::No
634629
}
630+
} else {
631+
// Problem getting source text. Pretend a comment was found.
632+
HasSafetyComment::Maybe
635633
}
636634
}
637635

0 commit comments

Comments
 (0)