Skip to content

Commit b46f5b4

Browse files
committed
Episode 1 - The simple cases
1 parent 54bf4ff commit b46f5b4

File tree

4 files changed

+20
-46
lines changed

4 files changed

+20
-46
lines changed

clippy_lints/src/escape.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
8585
cx.param_env,
8686
region_scope_tree,
8787
cx.tables,
88-
None,
8988
)
9089
.consume_body(body);
9190

@@ -114,15 +113,14 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {
114113
}
115114

116115
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
117-
fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
116+
fn consume(&mut self, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
118117
if let Categorization::Local(lid) = cmt.cat {
119-
if let Move(DirectRefMove) | Move(CaptureMove) = mode {
118+
if let ConsumeMode::Move = mode {
120119
// moved out or in. clearly can't be localized
121120
self.set.remove(&lid);
122121
}
123122
}
124123
}
125-
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
126124
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
127125
let map = &self.cx.tcx.hir();
128126
if is_argument(map, consume_pat.hir_id) {
@@ -137,7 +135,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
137135
}
138136
return;
139137
}
140-
if let Categorization::Rvalue(..) = cmt.cat {
138+
if let Categorization::Rvalue = cmt.cat {
141139
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(cmt.hir_id)) {
142140
if let StmtKind::Local(ref loc) = st.kind {
143141
if let Some(ref ex) = loc.init {
@@ -163,12 +161,10 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
163161
}
164162
}
165163
}
164+
166165
fn borrow(
167166
&mut self,
168-
_: HirId,
169-
_: Span,
170167
cmt: &cmt_<'tcx>,
171-
_: ty::Region<'_>,
172168
_: ty::BorrowKind,
173169
loan_cause: LoanCause,
174170
) {
@@ -192,8 +188,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
192188
}
193189
}
194190
}
195-
fn decl_without_init(&mut self, _: HirId, _: Span) {}
196-
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
191+
192+
fn mutate(&mut self, _: &cmt_<'tcx>) {}
197193
}
198194

199195
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

clippy_lints/src/loops.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,37 +1547,31 @@ struct MutatePairDelegate {
15471547
}
15481548

15491549
impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
1550-
fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {}
1550+
fn consume(&mut self, _: &cmt_<'tcx>, _: ConsumeMode) {}
15511551

1552-
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
1553-
1554-
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
1555-
1556-
fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
1552+
fn borrow(&mut self, cmt: &cmt_<'tcx>, bk: ty::BorrowKind) {
15571553
if let ty::BorrowKind::MutBorrow = bk {
15581554
if let Categorization::Local(id) = cmt.cat {
15591555
if Some(id) == self.hir_id_low {
1560-
self.span_low = Some(sp)
1556+
self.span_low = Some(cmt.span)
15611557
}
15621558
if Some(id) == self.hir_id_high {
1563-
self.span_high = Some(sp)
1559+
self.span_high = Some(cmt.span)
15641560
}
15651561
}
15661562
}
15671563
}
15681564

1569-
fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
1565+
fn mutate(&mut self, cmt: &cmt_<'tcx>) {
15701566
if let Categorization::Local(id) = cmt.cat {
15711567
if Some(id) == self.hir_id_low {
1572-
self.span_low = Some(sp)
1568+
self.span_low = Some(cmt.span)
15731569
}
15741570
if Some(id) == self.hir_id_high {
1575-
self.span_high = Some(sp)
1571+
self.span_high = Some(cmt.span)
15761572
}
15771573
}
15781574
}
1579-
1580-
fn decl_without_init(&mut self, _: HirId, _: Span) {}
15811575
}
15821576

15831577
impl<'tcx> MutatePairDelegate {
@@ -1655,7 +1649,6 @@ fn check_for_mutation(
16551649
cx.param_env,
16561650
region_scope_tree,
16571651
cx.tables,
1658-
None,
16591652
)
16601653
.walk_expr(body);
16611654
delegate.mutation_span()

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
143143
cx.param_env,
144144
region_scope_tree,
145145
cx.tables,
146-
None,
147146
)
148147
.consume_body(body);
149148
ctx
@@ -400,9 +399,9 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
400399
}
401400

402401
impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
403-
fn consume(&mut self, consume_id: HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) {
404-
if let euv::ConsumeMode::Move(_) = mode {
405-
self.move_common(consume_id, consume_span, cmt);
402+
fn consume(&mut self, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) {
403+
if let euv::ConsumeMode::Move = mode {
404+
self.move_common(cmt.hir_id, cmt.span, cmt);
406405
}
407406
}
408407

@@ -422,18 +421,12 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
422421

423422
fn borrow(
424423
&mut self,
425-
_: HirId,
426-
_: Span,
427424
_: &mc::cmt_<'tcx>,
428-
_: ty::Region<'_>,
429425
_: ty::BorrowKind,
430-
_: euv::LoanCause,
431426
) {
432427
}
433428

434-
fn mutate(&mut self, _: HirId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {}
435-
436-
fn decl_without_init(&mut self, _: HirId, _: Span) {}
429+
fn mutate(&mut self, _: &mc::cmt_<'tcx>) {}
437430
}
438431

439432
fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a mc::cmt_<'tcx>) -> mc::cmt_<'tcx> {

clippy_lints/src/utils/usage.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc::middle::mem_categorization::cmt_;
66
use rustc::middle::mem_categorization::Categorization;
77
use rustc::ty;
88
use rustc_data_structures::fx::FxHashSet;
9-
use syntax::source_map::Span;
109

1110
/// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined.
1211
pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option<FxHashSet<HirId>> {
@@ -23,7 +22,6 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tc
2322
cx.param_env,
2423
region_scope_tree,
2524
cx.tables,
26-
None,
2725
)
2826
.walk_expr(expr);
2927

@@ -66,21 +64,15 @@ impl<'tcx> MutVarsDelegate {
6664
}
6765

6866
impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
69-
fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {}
67+
fn consume(&mut self, _: &cmt_<'tcx>, _: ConsumeMode) {}
7068

71-
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
72-
73-
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
74-
75-
fn borrow(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
69+
fn borrow(&mut self, cmt: &cmt_<'tcx>, bk: ty::BorrowKind) {
7670
if let ty::BorrowKind::MutBorrow = bk {
7771
self.update(&cmt.cat)
7872
}
7973
}
8074

81-
fn mutate(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
75+
fn mutate(&mut self, cmt: &cmt_<'tcx>) {
8276
self.update(&cmt.cat)
8377
}
84-
85-
fn decl_without_init(&mut self, _: HirId, _: Span) {}
8678
}

0 commit comments

Comments
 (0)