1
Fork 0
Episode 1 - The simple cases
This commit is contained in:
flip1995 2019-10-04 14:24:47 +02:00
parent 54bf4ffd62
commit b46f5b4a98
No known key found for this signature in database
GPG key ID: 693086869D506637
4 changed files with 20 additions and 46 deletions

View file

@ -85,7 +85,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
cx.param_env, cx.param_env,
region_scope_tree, region_scope_tree,
cx.tables, cx.tables,
None,
) )
.consume_body(body); .consume_body(body);
@ -114,15 +113,14 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {
} }
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) { fn consume(&mut self, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
if let Categorization::Local(lid) = cmt.cat { if let Categorization::Local(lid) = cmt.cat {
if let Move(DirectRefMove) | Move(CaptureMove) = mode { if let ConsumeMode::Move = mode {
// moved out or in. clearly can't be localized // moved out or in. clearly can't be localized
self.set.remove(&lid); self.set.remove(&lid);
} }
} }
} }
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) { fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
let map = &self.cx.tcx.hir(); let map = &self.cx.tcx.hir();
if is_argument(map, consume_pat.hir_id) { if is_argument(map, consume_pat.hir_id) {
@ -137,7 +135,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
} }
return; return;
} }
if let Categorization::Rvalue(..) = cmt.cat { if let Categorization::Rvalue = cmt.cat {
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(cmt.hir_id)) { if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(cmt.hir_id)) {
if let StmtKind::Local(ref loc) = st.kind { if let StmtKind::Local(ref loc) = st.kind {
if let Some(ref ex) = loc.init { if let Some(ref ex) = loc.init {
@ -163,12 +161,10 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
} }
} }
} }
fn borrow( fn borrow(
&mut self, &mut self,
_: HirId,
_: Span,
cmt: &cmt_<'tcx>, cmt: &cmt_<'tcx>,
_: ty::Region<'_>,
_: ty::BorrowKind, _: ty::BorrowKind,
loan_cause: LoanCause, loan_cause: LoanCause,
) { ) {
@ -192,8 +188,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
} }
} }
} }
fn decl_without_init(&mut self, _: HirId, _: Span) {}
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {} fn mutate(&mut self, _: &cmt_<'tcx>) {}
} }
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

View file

@ -1547,37 +1547,31 @@ struct MutatePairDelegate {
} }
impl<'tcx> Delegate<'tcx> for MutatePairDelegate { impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {} fn consume(&mut self, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {} fn borrow(&mut self, cmt: &cmt_<'tcx>, bk: ty::BorrowKind) {
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
if let ty::BorrowKind::MutBorrow = bk { if let ty::BorrowKind::MutBorrow = bk {
if let Categorization::Local(id) = cmt.cat { if let Categorization::Local(id) = cmt.cat {
if Some(id) == self.hir_id_low { if Some(id) == self.hir_id_low {
self.span_low = Some(sp) self.span_low = Some(cmt.span)
} }
if Some(id) == self.hir_id_high { if Some(id) == self.hir_id_high {
self.span_high = Some(sp) self.span_high = Some(cmt.span)
} }
} }
} }
} }
fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) { fn mutate(&mut self, cmt: &cmt_<'tcx>) {
if let Categorization::Local(id) = cmt.cat { if let Categorization::Local(id) = cmt.cat {
if Some(id) == self.hir_id_low { if Some(id) == self.hir_id_low {
self.span_low = Some(sp) self.span_low = Some(cmt.span)
} }
if Some(id) == self.hir_id_high { if Some(id) == self.hir_id_high {
self.span_high = Some(sp) self.span_high = Some(cmt.span)
} }
} }
} }
fn decl_without_init(&mut self, _: HirId, _: Span) {}
} }
impl<'tcx> MutatePairDelegate { impl<'tcx> MutatePairDelegate {
@ -1655,7 +1649,6 @@ fn check_for_mutation(
cx.param_env, cx.param_env,
region_scope_tree, region_scope_tree,
cx.tables, cx.tables,
None,
) )
.walk_expr(body); .walk_expr(body);
delegate.mutation_span() delegate.mutation_span()

View file

@ -143,7 +143,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
cx.param_env, cx.param_env,
region_scope_tree, region_scope_tree,
cx.tables, cx.tables,
None,
) )
.consume_body(body); .consume_body(body);
ctx ctx
@ -400,9 +399,9 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
} }
impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> { impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
fn consume(&mut self, consume_id: HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) { fn consume(&mut self, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) {
if let euv::ConsumeMode::Move(_) = mode { if let euv::ConsumeMode::Move = mode {
self.move_common(consume_id, consume_span, cmt); self.move_common(cmt.hir_id, cmt.span, cmt);
} }
} }
@ -422,18 +421,12 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
fn borrow( fn borrow(
&mut self, &mut self,
_: HirId,
_: Span,
_: &mc::cmt_<'tcx>, _: &mc::cmt_<'tcx>,
_: ty::Region<'_>,
_: ty::BorrowKind, _: ty::BorrowKind,
_: euv::LoanCause,
) { ) {
} }
fn mutate(&mut self, _: HirId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {} fn mutate(&mut self, _: &mc::cmt_<'tcx>) {}
fn decl_without_init(&mut self, _: HirId, _: Span) {}
} }
fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a mc::cmt_<'tcx>) -> mc::cmt_<'tcx> { fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a mc::cmt_<'tcx>) -> mc::cmt_<'tcx> {

View file

@ -6,7 +6,6 @@ use rustc::middle::mem_categorization::cmt_;
use rustc::middle::mem_categorization::Categorization; use rustc::middle::mem_categorization::Categorization;
use rustc::ty; use rustc::ty;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use syntax::source_map::Span;
/// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined.
pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option<FxHashSet<HirId>> { 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
cx.param_env, cx.param_env,
region_scope_tree, region_scope_tree,
cx.tables, cx.tables,
None,
) )
.walk_expr(expr); .walk_expr(expr);
@ -66,21 +64,15 @@ impl<'tcx> MutVarsDelegate {
} }
impl<'tcx> Delegate<'tcx> for MutVarsDelegate { impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {} fn consume(&mut self, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {} fn borrow(&mut self, cmt: &cmt_<'tcx>, bk: ty::BorrowKind) {
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn borrow(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
if let ty::BorrowKind::MutBorrow = bk { if let ty::BorrowKind::MutBorrow = bk {
self.update(&cmt.cat) self.update(&cmt.cat)
} }
} }
fn mutate(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: MutateMode) { fn mutate(&mut self, cmt: &cmt_<'tcx>) {
self.update(&cmt.cat) self.update(&cmt.cat)
} }
fn decl_without_init(&mut self, _: HirId, _: Span) {}
} }