Skip to content

Commit

Permalink
Auto merge of rust-lang#6396 - flip1995:rustup, r=ebroto
Browse files Browse the repository at this point in the history
Rustup?

Basically a rustup from an unknown source. I added a regression test (and slightly changed the lint), so this'll need a review.

changelog: Fix bug in [`items_after_statements`] wher it triggered, if items were separated by trailing semicolons.
  • Loading branch information
bors committed Nov 28, 2020
2 parents 7a73a25 + 0e5aee1 commit d75bc86
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/items_after_statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ impl EarlyLintPass for ItemsAfterStatements {
return;
}

// skip initial items
// skip initial items and trailing semicolons
let stmts = item
.stmts
.iter()
.map(|stmt| &stmt.kind)
.skip_while(|s| matches!(**s, StmtKind::Item(..)));
.skip_while(|s| matches!(**s, StmtKind::Item(..) | StmtKind::Empty));

// lint on all further items
for stmt in stmts {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/redundant_closure_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
cx: &'a LateContext<'tcx>,
path: &'tcx hir::Path<'tcx>,
count: usize,
};
}
impl<'a, 'tcx> hir_visit::Visitor<'tcx> for ClosureUsageCount<'a, 'tcx> {
type Map = Map<'tcx>;

Expand All @@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
fn nested_visit_map(&mut self) -> hir_visit::NestedVisitorMap<Self::Map> {
hir_visit::NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
}
};
}
let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 };
closure_usage_count.visit_block(block);
closure_usage_count.count
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/item_after_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ fn mac() {
b!();
println!("{}", a);
}

fn semicolon() {
struct S {
a: u32,
};
impl S {
fn new(a: u32) -> Self {
Self { a }
}
}

let _ = S::new(3);
}

0 comments on commit d75bc86

Please sign in to comment.