rustc_const_eval/check_consts/
post_drop_elaboration.rs1use rustc_middle::mir::visit::Visitor;
2use rustc_middle::mir::{self, BasicBlock, Location};
3use rustc_middle::ty::TyCtxt;
4use rustc_span::sym;
5use tracing::trace;
6
7use super::ConstCx;
8use crate::check_consts::check::Checker;
9use crate::check_consts::rustc_allow_const_fn_unstable;
10
11pub fn checking_enabled(ccx: &ConstCx<'_, '_>) -> bool {
14 if ccx.enforce_recursive_const_stability() {
16 return rustc_allow_const_fn_unstable(
18 ccx.tcx,
19 ccx.body.source.def_id().expect_local(),
20 sym::const_precise_live_drops,
21 );
22 }
23
24 ccx.tcx.features().const_precise_live_drops()
25}
26
27pub fn check_live_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
32 let ccx = ConstCx::new(tcx, body);
33 if ccx.const_kind.is_none() {
34 return;
35 }
36
37 if tcx.has_attr(body.source.def_id(), sym::rustc_do_not_const_check) {
38 return;
39 }
40
41 if !checking_enabled(&ccx) {
42 return;
43 }
44
45 let mut visitor = CheckLiveDrops { checker: Checker::new(&ccx) };
49
50 visitor.visit_body(body);
51}
52
53struct CheckLiveDrops<'mir, 'tcx> {
54 checker: Checker<'mir, 'tcx>,
55}
56
57impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> {
58 fn visit_basic_block_data(&mut self, bb: BasicBlock, block: &mir::BasicBlockData<'tcx>) {
59 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs:59",
"rustc_const_eval::check_consts::post_drop_elaboration",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs"),
::tracing_core::__macro_support::Option::Some(59u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::check_consts::post_drop_elaboration"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("visit_basic_block_data: bb={0:?} is_cleanup={1:?}",
bb, block.is_cleanup) as &dyn Value))])
});
} else { ; }
};trace!("visit_basic_block_data: bb={:?} is_cleanup={:?}", bb, block.is_cleanup);
60
61 if block.is_cleanup {
63 return;
64 }
65
66 self.super_basic_block_data(bb, block);
67 }
68
69 fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
70 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs:70",
"rustc_const_eval::check_consts::post_drop_elaboration",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs"),
::tracing_core::__macro_support::Option::Some(70u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::check_consts::post_drop_elaboration"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("visit_terminator: terminator={0:?} location={1:?}",
terminator, location) as &dyn Value))])
});
} else { ; }
};trace!("visit_terminator: terminator={:?} location={:?}", terminator, location);
71
72 match &terminator.kind {
73 mir::TerminatorKind::Drop { place: dropped_place, .. } => {
74 self.checker.check_drop_terminator(
75 *dropped_place,
76 location,
77 terminator.source_info.span,
78 );
79 }
80
81 mir::TerminatorKind::UnwindTerminate(_)
82 | mir::TerminatorKind::Call { .. }
83 | mir::TerminatorKind::TailCall { .. }
84 | mir::TerminatorKind::Assert { .. }
85 | mir::TerminatorKind::FalseEdge { .. }
86 | mir::TerminatorKind::FalseUnwind { .. }
87 | mir::TerminatorKind::CoroutineDrop
88 | mir::TerminatorKind::Goto { .. }
89 | mir::TerminatorKind::InlineAsm { .. }
90 | mir::TerminatorKind::UnwindResume
91 | mir::TerminatorKind::Return
92 | mir::TerminatorKind::SwitchInt { .. }
93 | mir::TerminatorKind::Unreachable
94 | mir::TerminatorKind::Yield { .. } => {}
95 }
96 }
97}