-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce false positives of tail-expr-drop-order from consumed values
- Loading branch information
1 parent
1a1cc05
commit de2d256
Showing
9 changed files
with
237 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use rustc_hir::def_id::DefId; | ||
use rustc_hir::{HirId, HirIdSet}; | ||
use rustc_middle::hir::place::{PlaceBase, PlaceWithHirId}; | ||
use rustc_middle::mir::FakeReadCause; | ||
use rustc_middle::query::Providers; | ||
use rustc_middle::ty::{self, TyCtxt}; | ||
use tracing::instrument; | ||
|
||
use crate::expr_use_visitor::{Delegate, ExprUseVisitor}; | ||
|
||
#[derive(Default)] | ||
struct ExtractConsumingNodeDelegate { | ||
nodes: HirIdSet, | ||
} | ||
|
||
impl<'tcx> Delegate<'tcx> for ExtractConsumingNodeDelegate { | ||
#[instrument(level = "debug", skip(self))] | ||
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, _: HirId) { | ||
match place_with_id.place.base { | ||
PlaceBase::Rvalue => { | ||
self.nodes.insert(place_with_id.hir_id); | ||
} | ||
PlaceBase::Local(id) => { | ||
self.nodes.insert(id); | ||
} | ||
PlaceBase::Upvar(upvar) => { | ||
self.nodes.insert(upvar.var_path.hir_id); | ||
} | ||
PlaceBase::StaticItem => {} | ||
} | ||
} | ||
|
||
fn borrow( | ||
&mut self, | ||
_place_with_id: &PlaceWithHirId<'tcx>, | ||
_diag_expr_id: HirId, | ||
_bk: ty::BorrowKind, | ||
) { | ||
// do nothing | ||
} | ||
|
||
fn mutate(&mut self, _assignee_place: &PlaceWithHirId<'tcx>, _diag_expr_id: HirId) { | ||
// do nothing | ||
} | ||
|
||
fn fake_read( | ||
&mut self, | ||
_place_with_id: &PlaceWithHirId<'tcx>, | ||
_cause: FakeReadCause, | ||
_diag_expr_id: HirId, | ||
) { | ||
// do nothing | ||
} | ||
} | ||
|
||
fn extract_tail_expr_consuming_nodes<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx HirIdSet { | ||
let hir = tcx.hir(); | ||
let body = hir.body_owned_by(def_id.expect_local()); | ||
let mut delegate = ExtractConsumingNodeDelegate::default(); | ||
let euv = ExprUseVisitor::new((tcx, def_id.expect_local()), &mut delegate); | ||
let _ = euv.walk_expr(body.value); | ||
tcx.arena.alloc(delegate.nodes) | ||
} | ||
|
||
pub(crate) fn provide(providers: &mut Providers) { | ||
providers.extract_tail_expr_consuming_nodes = extract_tail_expr_consuming_nodes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.