Auto merge of #6396 - flip1995:rustup, r=ebroto

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.
This commit is contained in:
bors 2020-11-28 21:14:37 +00:00
commit d75bc868ca
3 changed files with 17 additions and 4 deletions

View file

@ -58,12 +58,12 @@ impl EarlyLintPass for ItemsAfterStatements {
return; return;
} }
// skip initial items // skip initial items and trailing semicolons
let stmts = item let stmts = item
.stmts .stmts
.iter() .iter()
.map(|stmt| &stmt.kind) .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 // lint on all further items
for stmt in stmts { for stmt in stmts {

View file

@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
cx: &'a LateContext<'tcx>, cx: &'a LateContext<'tcx>,
path: &'tcx hir::Path<'tcx>, path: &'tcx hir::Path<'tcx>,
count: usize, count: usize,
}; }
impl<'a, 'tcx> hir_visit::Visitor<'tcx> for ClosureUsageCount<'a, 'tcx> { impl<'a, 'tcx> hir_visit::Visitor<'tcx> for ClosureUsageCount<'a, 'tcx> {
type Map = Map<'tcx>; type Map = Map<'tcx>;
@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
fn nested_visit_map(&mut self) -> hir_visit::NestedVisitorMap<Self::Map> { fn nested_visit_map(&mut self) -> hir_visit::NestedVisitorMap<Self::Map> {
hir_visit::NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) hir_visit::NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
} }
}; }
let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 }; let mut closure_usage_count = ClosureUsageCount { cx, path, count: 0 };
closure_usage_count.visit_block(block); closure_usage_count.visit_block(block);
closure_usage_count.count closure_usage_count.count

View file

@ -37,3 +37,16 @@ fn mac() {
b!(); b!();
println!("{}", a); println!("{}", a);
} }
fn semicolon() {
struct S {
a: u32,
};
impl S {
fn new(a: u32) -> Self {
Self { a }
}
}
let _ = S::new(3);
}