1#![allow(internal_features)]
5#![feature(default_field_values)]
6#![feature(deref_patterns)]
7#![feature(file_buffered)]
8#![feature(negative_impls)]
9#![feature(never_type)]
10#![feature(rustc_attrs)]
11#![feature(stmt_expr_attributes)]
12#![feature(try_blocks)]
13use std::borrow::Cow;
16use std::cell::{OnceCell, RefCell};
17use std::marker::PhantomData;
18use std::ops::{ControlFlow, Deref};
19use std::rc::Rc;
20
21use borrow_set::LocalsStateAtExit;
22use polonius_engine::AllFacts;
23use root_cx::BorrowCheckRootCtxt;
24use rustc_abi::FieldIdx;
25use rustc_data_structures::frozen::Frozen;
26use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
27use rustc_data_structures::graph::dominators::Dominators;
28use rustc_hir as hir;
29use rustc_hir::CRATE_HIR_ID;
30use rustc_hir::def_id::LocalDefId;
31use rustc_index::bit_set::MixedBitSet;
32use rustc_index::{IndexSlice, IndexVec};
33use rustc_infer::infer::outlives::env::RegionBoundPairs;
34use rustc_infer::infer::{
35 InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
36};
37use rustc_middle::mir::*;
38use rustc_middle::query::Providers;
39use rustc_middle::ty::{
40 self, ParamEnv, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypingMode, fold_regions,
41};
42use rustc_middle::{bug, span_bug};
43use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
44use rustc_mir_dataflow::move_paths::{
45 InitIndex, InitLocation, LookupResult, MoveData, MovePathIndex,
46};
47use rustc_mir_dataflow::points::DenseLocationMap;
48use rustc_mir_dataflow::{Analysis, EntryStates, Results, ResultsVisitor, visit_results};
49use rustc_session::lint::builtin::{TAIL_EXPR_DROP_ORDER, UNUSED_MUT};
50use rustc_span::{ErrorGuaranteed, Span, Symbol};
51use smallvec::SmallVec;
52use tracing::{debug, instrument};
53
54use crate::borrow_set::{BorrowData, BorrowSet};
55use crate::consumers::{BodyWithBorrowckFacts, RustcFacts};
56use crate::dataflow::{BorrowIndex, Borrowck, BorrowckDomain, Borrows};
57use crate::diagnostics::{
58 AccessKind, BorrowckDiagnosticsBuffer, IllegalMoveOriginKind, MoveError, RegionName,
59};
60use crate::path_utils::*;
61use crate::place_ext::PlaceExt;
62use crate::places_conflict::{PlaceConflictBias, places_conflict};
63use crate::polonius::PoloniusContext;
64use crate::polonius::legacy::{
65 PoloniusFacts, PoloniusFactsExt, PoloniusLocationTable, PoloniusOutput,
66};
67use crate::prefixes::PrefixSet;
68use crate::region_infer::RegionInferenceContext;
69use crate::region_infer::opaque_types::DeferredOpaqueTypeError;
70use crate::renumber::RegionCtxt;
71use crate::session_diagnostics::VarNeedNotMut;
72use crate::type_check::free_region_relations::UniversalRegionRelations;
73use crate::type_check::{Locations, MirTypeckRegionConstraints, MirTypeckResults};
74
75mod borrow_set;
76mod borrowck_errors;
77mod constraints;
78mod dataflow;
79mod def_use;
80mod diagnostics;
81mod handle_placeholders;
82mod nll;
83mod path_utils;
84mod place_ext;
85mod places_conflict;
86mod polonius;
87mod prefixes;
88mod region_infer;
89mod renumber;
90mod root_cx;
91mod session_diagnostics;
92mod type_check;
93mod universal_regions;
94mod used_muts;
95
96pub mod consumers;
98
99struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>);
101
102impl<'tcx> TyCtxtConsts<'tcx> {
103 const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref];
104}
105
106pub fn provide(providers: &mut Providers) {
107 *providers = Providers { mir_borrowck, ..*providers };
108}
109
110fn mir_borrowck(
114 tcx: TyCtxt<'_>,
115 def: LocalDefId,
116) -> Result<&FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'_>>, ErrorGuaranteed> {
117 if !!tcx.is_typeck_child(def.to_def_id()) {
::core::panicking::panic("assertion failed: !tcx.is_typeck_child(def.to_def_id())")
};assert!(!tcx.is_typeck_child(def.to_def_id()));
118 if tcx.is_trivial_const(def) {
119 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:119",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(119u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("Skipping borrowck because of trivial const")
as &dyn Value))])
});
} else { ; }
};debug!("Skipping borrowck because of trivial const");
120 let opaque_types = Default::default();
121 return Ok(tcx.arena.alloc(opaque_types));
122 }
123 let (input_body, _) = tcx.mir_promoted(def);
124 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:124",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(124u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("run query mir_borrowck: {0}",
tcx.def_path_str(def)) as &dyn Value))])
});
} else { ; }
};debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
125
126 tcx.ensure_result().check_coroutine_obligations(def)?;
130
131 let input_body: &Body<'_> = &input_body.borrow();
132 if let Some(guar) = input_body.tainted_by_errors {
133 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:133",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(133u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("Skipping borrowck because of tainted body")
as &dyn Value))])
});
} else { ; }
};debug!("Skipping borrowck because of tainted body");
134 Err(guar)
135 } else if input_body.should_skip() {
136 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:136",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(136u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("Skipping borrowck because of injected body")
as &dyn Value))])
});
} else { ; }
};debug!("Skipping borrowck because of injected body");
137 let opaque_types = Default::default();
138 Ok(tcx.arena.alloc(opaque_types))
139 } else {
140 let mut root_cx = BorrowCheckRootCtxt::new(tcx, def, None);
141 root_cx.do_mir_borrowck();
142 root_cx.finalize()
143 }
144}
145
146#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PropagatedBorrowCheckResults<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"PropagatedBorrowCheckResults", "closure_requirements",
&self.closure_requirements, "used_mut_upvars",
&&self.used_mut_upvars)
}
}Debug)]
149struct PropagatedBorrowCheckResults<'tcx> {
150 closure_requirements: Option<ClosureRegionRequirements<'tcx>>,
151 used_mut_upvars: SmallVec<[FieldIdx; 8]>,
152}
153
154type DeferredClosureRequirements<'tcx> = Vec<(LocalDefId, ty::GenericArgsRef<'tcx>, Locations)>;
155
156#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ClosureRegionRequirements<'tcx> {
#[inline]
fn clone(&self) -> ClosureRegionRequirements<'tcx> {
ClosureRegionRequirements {
num_external_vids: ::core::clone::Clone::clone(&self.num_external_vids),
outlives_requirements: ::core::clone::Clone::clone(&self.outlives_requirements),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ClosureRegionRequirements<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ClosureRegionRequirements", "num_external_vids",
&self.num_external_vids, "outlives_requirements",
&&self.outlives_requirements)
}
}Debug)]
199pub struct ClosureRegionRequirements<'tcx> {
200 pub num_external_vids: usize,
206
207 pub outlives_requirements: Vec<ClosureOutlivesRequirement<'tcx>>,
210}
211
212#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ClosureOutlivesRequirement<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for ClosureOutlivesRequirement<'tcx> {
#[inline]
fn clone(&self) -> ClosureOutlivesRequirement<'tcx> {
let _:
::core::clone::AssertParamIsClone<ClosureOutlivesSubject<'tcx>>;
let _: ::core::clone::AssertParamIsClone<ty::RegionVid>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<ConstraintCategory<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ClosureOutlivesRequirement<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"ClosureOutlivesRequirement", "subject", &self.subject,
"outlived_free_region", &self.outlived_free_region, "blame_span",
&self.blame_span, "category", &&self.category)
}
}Debug)]
215pub struct ClosureOutlivesRequirement<'tcx> {
216 pub subject: ClosureOutlivesSubject<'tcx>,
218
219 pub outlived_free_region: ty::RegionVid,
221
222 pub blame_span: Span,
224
225 pub category: ConstraintCategory<'tcx>,
227}
228
229#[cfg(target_pointer_width = "64")]
231const _: [(); 16] = [(); ::std::mem::size_of::<ConstraintCategory<'_>>()];rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
232
233#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ClosureOutlivesSubject<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for ClosureOutlivesSubject<'tcx> {
#[inline]
fn clone(&self) -> ClosureOutlivesSubject<'tcx> {
let _:
::core::clone::AssertParamIsClone<ClosureOutlivesSubjectTy<'tcx>>;
let _: ::core::clone::AssertParamIsClone<ty::RegionVid>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ClosureOutlivesSubject<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ClosureOutlivesSubject::Ty(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Ty",
&__self_0),
ClosureOutlivesSubject::Region(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Region",
&__self_0),
}
}
}Debug)]
236pub enum ClosureOutlivesSubject<'tcx> {
237 Ty(ClosureOutlivesSubjectTy<'tcx>),
241
242 Region(ty::RegionVid),
245}
246
247#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ClosureOutlivesSubjectTy<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for ClosureOutlivesSubjectTy<'tcx> {
#[inline]
fn clone(&self) -> ClosureOutlivesSubjectTy<'tcx> {
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ClosureOutlivesSubjectTy<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ClosureOutlivesSubjectTy", "inner", &&self.inner)
}
}Debug)]
253pub struct ClosureOutlivesSubjectTy<'tcx> {
254 inner: Ty<'tcx>,
255}
256impl<'tcx, I> !TypeVisitable<I> for ClosureOutlivesSubjectTy<'tcx> {}
259impl<'tcx, I> !TypeFoldable<I> for ClosureOutlivesSubjectTy<'tcx> {}
260
261impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
262 pub fn bind(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
265 let inner = fold_regions(tcx, ty, |r, depth| match r.kind() {
266 ty::ReVar(vid) => {
267 let br = ty::BoundRegion {
268 var: ty::BoundVar::from_usize(vid.index()),
269 kind: ty::BoundRegionKind::Anon,
270 };
271 ty::Region::new_bound(tcx, depth, br)
272 }
273 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected region in ClosureOutlivesSubjectTy: {0:?}",
r))bug!("unexpected region in ClosureOutlivesSubjectTy: {r:?}"),
274 });
275
276 Self { inner }
277 }
278
279 pub fn instantiate(
280 self,
281 tcx: TyCtxt<'tcx>,
282 mut map: impl FnMut(ty::RegionVid) -> ty::Region<'tcx>,
283 ) -> Ty<'tcx> {
284 fold_regions(tcx, self.inner, |r, depth| match r.kind() {
285 ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), br) => {
286 if true {
match (&debruijn, &depth) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};debug_assert_eq!(debruijn, depth);
287 map(ty::RegionVid::from_usize(br.var.index()))
288 }
289 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected region {0:?}", r))bug!("unexpected region {r:?}"),
290 })
291 }
292}
293
294struct CollectRegionConstraintsResult<'tcx> {
295 infcx: BorrowckInferCtxt<'tcx>,
296 body_owned: Body<'tcx>,
297 promoted: IndexVec<Promoted, Body<'tcx>>,
298 move_data: MoveData<'tcx>,
299 borrow_set: BorrowSet<'tcx>,
300 location_table: PoloniusLocationTable,
301 location_map: Rc<DenseLocationMap>,
302 universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
303 region_bound_pairs: Frozen<RegionBoundPairs<'tcx>>,
304 known_type_outlives_obligations: Frozen<Vec<ty::PolyTypeOutlivesPredicate<'tcx>>>,
305 constraints: MirTypeckRegionConstraints<'tcx>,
306 deferred_closure_requirements: DeferredClosureRequirements<'tcx>,
307 deferred_opaque_type_errors: Vec<DeferredOpaqueTypeError<'tcx>>,
308 polonius_facts: Option<AllFacts<RustcFacts>>,
309 polonius_context: Option<PoloniusContext>,
310}
311
312fn borrowck_collect_region_constraints<'tcx>(
316 root_cx: &mut BorrowCheckRootCtxt<'tcx>,
317 def: LocalDefId,
318) -> CollectRegionConstraintsResult<'tcx> {
319 let tcx = root_cx.tcx;
320 let infcx = BorrowckInferCtxt::new(tcx, def, root_cx.root_def_id());
321 let (input_body, promoted) = tcx.mir_promoted(def);
322 let input_body: &Body<'_> = &input_body.borrow();
323 let input_promoted: &IndexSlice<_, _> = &promoted.borrow();
324 if let Some(e) = input_body.tainted_by_errors {
325 infcx.set_tainted_by_errors(e);
326 root_cx.set_tainted_by_errors(e);
327 }
328
329 let mut body_owned = input_body.clone();
334 let mut promoted = input_promoted.to_owned();
335 let universal_regions = nll::replace_regions_in_mir(&infcx, &mut body_owned, &mut promoted);
336 let body = &body_owned; let location_table = PoloniusLocationTable::new(body);
339
340 let move_data = MoveData::gather_moves(body, tcx, |_| true);
341
342 let locals_are_invalidated_at_exit = tcx.hir_body_owner_kind(def).is_fn_or_closure();
343 let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
344
345 let location_map = Rc::new(DenseLocationMap::new(body));
346
347 let polonius_input = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_input())
348 || infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
349 let mut polonius_facts =
350 (polonius_input || PoloniusFacts::enabled(infcx.tcx)).then_some(PoloniusFacts::default());
351
352 let MirTypeckResults {
354 constraints,
355 universal_region_relations,
356 region_bound_pairs,
357 known_type_outlives_obligations,
358 deferred_closure_requirements,
359 polonius_context,
360 } = type_check::type_check(
361 root_cx,
362 &infcx,
363 body,
364 &promoted,
365 universal_regions,
366 &location_table,
367 &borrow_set,
368 &mut polonius_facts,
369 &move_data,
370 Rc::clone(&location_map),
371 );
372
373 CollectRegionConstraintsResult {
374 infcx,
375 body_owned,
376 promoted,
377 move_data,
378 borrow_set,
379 location_table,
380 location_map,
381 universal_region_relations,
382 region_bound_pairs,
383 known_type_outlives_obligations,
384 constraints,
385 deferred_closure_requirements,
386 deferred_opaque_type_errors: Default::default(),
387 polonius_facts,
388 polonius_context,
389 }
390}
391
392fn borrowck_check_region_constraints<'tcx>(
396 root_cx: &mut BorrowCheckRootCtxt<'tcx>,
397 CollectRegionConstraintsResult {
398 infcx,
399 body_owned,
400 promoted,
401 move_data,
402 borrow_set,
403 location_table,
404 location_map,
405 universal_region_relations,
406 region_bound_pairs: _,
407 known_type_outlives_obligations: _,
408 constraints,
409 deferred_closure_requirements,
410 deferred_opaque_type_errors,
411 polonius_facts,
412 polonius_context,
413 }: CollectRegionConstraintsResult<'tcx>,
414) -> PropagatedBorrowCheckResults<'tcx> {
415 if !!infcx.has_opaque_types_in_storage() {
::core::panicking::panic("assertion failed: !infcx.has_opaque_types_in_storage()")
};assert!(!infcx.has_opaque_types_in_storage());
416 if !deferred_closure_requirements.is_empty() {
::core::panicking::panic("assertion failed: deferred_closure_requirements.is_empty()")
};assert!(deferred_closure_requirements.is_empty());
417 let tcx = root_cx.tcx;
418 let body = &body_owned;
419 let def = body.source.def_id().expect_local();
420
421 let nll::NllOutput {
424 regioncx,
425 polonius_input,
426 polonius_output,
427 opt_closure_req,
428 nll_errors,
429 polonius_context,
430 } = nll::compute_regions(
431 root_cx,
432 &infcx,
433 body,
434 &location_table,
435 &move_data,
436 &borrow_set,
437 location_map,
438 universal_region_relations,
439 constraints,
440 polonius_facts,
441 polonius_context,
442 );
443
444 nll::dump_nll_mir(&infcx, body, ®ioncx, &opt_closure_req, &borrow_set);
447 polonius::dump_polonius_mir(
448 &infcx,
449 body,
450 ®ioncx,
451 &opt_closure_req,
452 &borrow_set,
453 polonius_context.as_ref(),
454 );
455
456 nll::dump_annotation(&infcx, body, ®ioncx, &opt_closure_req);
459
460 let movable_coroutine = body.coroutine.is_some()
461 && tcx.coroutine_movability(def.to_def_id()) == hir::Movability::Movable;
462
463 let diags_buffer = &mut BorrowckDiagnosticsBuffer::default();
464 for promoted_body in &promoted {
467 use rustc_middle::mir::visit::Visitor;
468 let move_data = MoveData::gather_moves(promoted_body, tcx, |_| true);
472 let mut promoted_mbcx = MirBorrowckCtxt {
473 root_cx,
474 infcx: &infcx,
475 body: promoted_body,
476 move_data: &move_data,
477 location_table: &location_table,
479 movable_coroutine,
480 fn_self_span_reported: Default::default(),
481 access_place_error_reported: Default::default(),
482 reservation_error_reported: Default::default(),
483 uninitialized_error_reported: Default::default(),
484 regioncx: ®ioncx,
485 used_mut: Default::default(),
486 used_mut_upvars: SmallVec::new(),
487 borrow_set: &borrow_set,
488 upvars: &[],
489 local_names: OnceCell::from(IndexVec::from_elem(None, &promoted_body.local_decls)),
490 region_names: RefCell::default(),
491 next_region_name: RefCell::new(1),
492 polonius_output: None,
493 move_errors: Vec::new(),
494 diags_buffer,
495 polonius_context: polonius_context.as_ref(),
496 };
497 struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
498 ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
499 }
500
501 impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, '_, 'tcx> {
502 fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
503 if let Operand::Move(place) = operand {
504 self.ctxt.check_movable_place(location, *place);
505 }
506 }
507 }
508 MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
509 promoted_mbcx.report_move_errors();
510 }
511
512 let mut mbcx = MirBorrowckCtxt {
513 root_cx,
514 infcx: &infcx,
515 body,
516 move_data: &move_data,
517 location_table: &location_table,
518 movable_coroutine,
519 fn_self_span_reported: Default::default(),
520 access_place_error_reported: Default::default(),
521 reservation_error_reported: Default::default(),
522 uninitialized_error_reported: Default::default(),
523 regioncx: ®ioncx,
524 used_mut: Default::default(),
525 used_mut_upvars: SmallVec::new(),
526 borrow_set: &borrow_set,
527 upvars: tcx.closure_captures(def),
528 local_names: OnceCell::new(),
529 region_names: RefCell::default(),
530 next_region_name: RefCell::new(1),
531 move_errors: Vec::new(),
532 diags_buffer,
533 polonius_output: polonius_output.as_deref(),
534 polonius_context: polonius_context.as_ref(),
535 };
536
537 if nll_errors.is_empty() {
539 mbcx.report_opaque_type_errors(deferred_opaque_type_errors);
540 } else {
541 mbcx.report_region_errors(nll_errors);
542 }
543
544 let flow_results = get_flow_results(tcx, body, &move_data, &borrow_set, ®ioncx);
545 visit_results(
546 body,
547 traversal::reverse_postorder(body).map(|(bb, _)| bb),
548 &flow_results,
549 &mut mbcx,
550 );
551
552 mbcx.report_move_errors();
553
554 let temporary_used_locals: FxIndexSet<Local> = mbcx
560 .used_mut
561 .iter()
562 .filter(|&local| !mbcx.body.local_decls[*local].is_user_variable())
563 .cloned()
564 .collect();
565 let unused_mut_locals =
569 mbcx.body.mut_vars_iter().filter(|local| !mbcx.used_mut.contains(local)).collect();
570 mbcx.gather_used_muts(temporary_used_locals, unused_mut_locals);
571
572 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:572",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(572u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("mbcx.used_mut: {0:?}",
mbcx.used_mut) as &dyn Value))])
});
} else { ; }
};debug!("mbcx.used_mut: {:?}", mbcx.used_mut);
573 mbcx.lint_unused_mut();
574 if let Some(guar) = mbcx.emit_errors() {
575 mbcx.root_cx.set_tainted_by_errors(guar);
576 }
577
578 let result = PropagatedBorrowCheckResults {
579 closure_requirements: opt_closure_req,
580 used_mut_upvars: mbcx.used_mut_upvars,
581 };
582
583 if let Some(consumer) = &mut root_cx.consumer {
584 consumer.insert_body(
585 def,
586 BodyWithBorrowckFacts {
587 body: body_owned,
588 promoted,
589 borrow_set,
590 region_inference_context: regioncx,
591 location_table: polonius_input.as_ref().map(|_| location_table),
592 input_facts: polonius_input,
593 output_facts: polonius_output,
594 },
595 );
596 }
597
598 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:598",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(598u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("do_mir_borrowck: result = {0:#?}",
result) as &dyn Value))])
});
} else { ; }
};debug!("do_mir_borrowck: result = {:#?}", result);
599
600 result
601}
602
603fn get_flow_results<'a, 'tcx>(
604 tcx: TyCtxt<'tcx>,
605 body: &'a Body<'tcx>,
606 move_data: &'a MoveData<'tcx>,
607 borrow_set: &'a BorrowSet<'tcx>,
608 regioncx: &RegionInferenceContext<'tcx>,
609) -> Results<'tcx, Borrowck<'a, 'tcx>> {
610 let borrows = Borrows::new(tcx, body, regioncx, borrow_set).iterate_to_fixpoint(
613 tcx,
614 body,
615 Some("borrowck"),
616 );
617 let uninits = MaybeUninitializedPlaces::new(tcx, body, move_data).iterate_to_fixpoint(
618 tcx,
619 body,
620 Some("borrowck"),
621 );
622 let ever_inits = EverInitializedPlaces::new(body, move_data).iterate_to_fixpoint(
623 tcx,
624 body,
625 Some("borrowck"),
626 );
627
628 let analysis = Borrowck {
629 borrows: borrows.analysis,
630 uninits: uninits.analysis,
631 ever_inits: ever_inits.analysis,
632 };
633
634 match (&borrows.entry_states.len(), &uninits.entry_states.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(borrows.entry_states.len(), uninits.entry_states.len());
635 match (&borrows.entry_states.len(), &ever_inits.entry_states.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(borrows.entry_states.len(), ever_inits.entry_states.len());
636 let entry_states: EntryStates<_> =
637 ::itertools::__std_iter::IntoIterator::into_iter(borrows.entry_states).zip(uninits.entry_states).zip(ever_inits.entry_states).map(|((a,
b), b)| (a, b, b))itertools::izip!(borrows.entry_states, uninits.entry_states, ever_inits.entry_states)
638 .map(|(borrows, uninits, ever_inits)| BorrowckDomain { borrows, uninits, ever_inits })
639 .collect();
640
641 Results { analysis, entry_states }
642}
643
644pub(crate) struct BorrowckInferCtxt<'tcx> {
645 pub(crate) infcx: InferCtxt<'tcx>,
646 pub(crate) root_def_id: LocalDefId,
647 pub(crate) param_env: ParamEnv<'tcx>,
648 pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
649}
650
651impl<'tcx> BorrowckInferCtxt<'tcx> {
652 pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, root_def_id: LocalDefId) -> Self {
653 let typing_mode = if tcx.use_typing_mode_borrowck() {
654 TypingMode::borrowck(tcx, def_id)
655 } else {
656 TypingMode::analysis_in_body(tcx, def_id)
657 };
658 let infcx = tcx.infer_ctxt().build(typing_mode);
659 let param_env = tcx.param_env(def_id);
660 BorrowckInferCtxt {
661 infcx,
662 root_def_id,
663 reg_var_to_origin: RefCell::new(Default::default()),
664 param_env,
665 }
666 }
667
668 pub(crate) fn next_region_var<F>(
669 &self,
670 origin: RegionVariableOrigin<'tcx>,
671 get_ctxt_fn: F,
672 ) -> ty::Region<'tcx>
673 where
674 F: Fn() -> RegionCtxt,
675 {
676 let next_region = self.infcx.next_region_var(origin);
677 let vid = next_region.as_var();
678
679 if truecfg!(debug_assertions) {
680 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:680",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(680u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("inserting vid {0:?} with origin {1:?} into var_to_origin",
vid, origin) as &dyn Value))])
});
} else { ; }
};debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
681 let ctxt = get_ctxt_fn();
682 let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
683 match (&var_to_origin.insert(vid, ctxt), &None) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(var_to_origin.insert(vid, ctxt), None);
684 }
685
686 next_region
687 }
688
689 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("next_nll_region_var",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(689u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["origin"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::Region<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let next_region = self.infcx.next_nll_region_var(origin);
let vid = next_region.as_var();
if true {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:702",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(702u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::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!("inserting vid {0:?} with origin {1:?} into var_to_origin",
vid, origin) as &dyn Value))])
});
} else { ; }
};
let ctxt = get_ctxt_fn();
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
match (&var_to_origin.insert(vid, ctxt), &None) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
}
next_region
}
}
}#[instrument(skip(self, get_ctxt_fn), level = "debug")]
690 pub(crate) fn next_nll_region_var<F>(
691 &self,
692 origin: NllRegionVariableOrigin<'tcx>,
693 get_ctxt_fn: F,
694 ) -> ty::Region<'tcx>
695 where
696 F: Fn() -> RegionCtxt,
697 {
698 let next_region = self.infcx.next_nll_region_var(origin);
699 let vid = next_region.as_var();
700
701 if cfg!(debug_assertions) {
702 debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
703 let ctxt = get_ctxt_fn();
704 let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
705 assert_eq!(var_to_origin.insert(vid, ctxt), None);
706 }
707
708 next_region
709 }
710}
711
712impl<'tcx> Deref for BorrowckInferCtxt<'tcx> {
713 type Target = InferCtxt<'tcx>;
714
715 fn deref(&self) -> &Self::Target {
716 &self.infcx
717 }
718}
719
720pub(crate) struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
721 root_cx: &'a mut BorrowCheckRootCtxt<'tcx>,
722 infcx: &'infcx BorrowckInferCtxt<'tcx>,
723 body: &'a Body<'tcx>,
724 move_data: &'a MoveData<'tcx>,
725
726 location_table: &'a PoloniusLocationTable,
729
730 movable_coroutine: bool,
731 access_place_error_reported: FxIndexSet<(Place<'tcx>, Span)>,
737 reservation_error_reported: FxIndexSet<Place<'tcx>>,
745 fn_self_span_reported: FxIndexSet<Span>,
749 uninitialized_error_reported: FxIndexSet<Local>,
752 used_mut: FxIndexSet<Local>,
755 used_mut_upvars: SmallVec<[FieldIdx; 8]>,
758 regioncx: &'a RegionInferenceContext<'tcx>,
761
762 borrow_set: &'a BorrowSet<'tcx>,
764
765 upvars: &'tcx [&'tcx ty::CapturedPlace<'tcx>],
767
768 local_names: OnceCell<IndexVec<Local, Option<Symbol>>>,
770
771 region_names: RefCell<FxIndexMap<RegionVid, RegionName>>,
774
775 next_region_name: RefCell<usize>,
777
778 diags_buffer: &'a mut BorrowckDiagnosticsBuffer<'infcx, 'tcx>,
779 move_errors: Vec<MoveError<'tcx>>,
780
781 polonius_output: Option<&'a PoloniusOutput>,
783 polonius_context: Option<&'a PoloniusContext>,
785}
786
787impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a, '_, 'tcx> {
793 fn visit_after_early_statement_effect(
794 &mut self,
795 _analysis: &Borrowck<'a, 'tcx>,
796 state: &BorrowckDomain,
797 stmt: &Statement<'tcx>,
798 location: Location,
799 ) {
800 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:800",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(800u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("MirBorrowckCtxt::process_statement({0:?}, {1:?}): {2:?}",
location, stmt, state) as &dyn Value))])
});
} else { ; }
};debug!("MirBorrowckCtxt::process_statement({:?}, {:?}): {:?}", location, stmt, state);
801 let span = stmt.source_info.span;
802
803 self.check_activations(location, span, state);
804
805 match &stmt.kind {
806 StatementKind::Assign((lhs, rhs)) => {
807 self.consume_rvalue(location, (rhs, span), state);
808
809 self.mutate_place(location, (*lhs, span), Shallow(None), state);
810 }
811 StatementKind::FakeRead((_, place)) => {
812 self.check_if_path_or_subpath_is_moved(
823 location,
824 InitializationRequiringAction::Use,
825 (place.as_ref(), span),
826 state,
827 );
828 }
829 StatementKind::Intrinsic(kind) => match kind {
830 NonDivergingIntrinsic::Assume(op) => {
831 self.consume_operand(location, (op, span), state);
832 }
833 NonDivergingIntrinsic::CopyNonOverlapping(..) => ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("Unexpected CopyNonOverlapping, should only appear after lower_intrinsics"))span_bug!(
834 span,
835 "Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
836 ),
837 },
838 StatementKind::AscribeUserType(..) => {}
840 StatementKind::PlaceMention(..) => {}
842 StatementKind::Coverage(..) => {}
844 StatementKind::ConstEvalCounter | StatementKind::StorageLive(..) => {}
846 StatementKind::BackwardIncompatibleDropHint {
848 place,
849 reason: BackwardIncompatibleDropReason::Edition2024,
850 } => {
851 self.check_backward_incompatible_drop(location, **place, state);
852 }
853 StatementKind::StorageDead(local) => {
854 self.access_place(
855 location,
856 (Place::from(*local), span),
857 (Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
858 LocalMutationIsAllowed::Yes,
859 state,
860 );
861 }
862 StatementKind::Nop | StatementKind::SetDiscriminant { .. } => {
863 ::rustc_middle::util::bug::bug_fmt(format_args!("Statement not allowed in this MIR phase"))bug!("Statement not allowed in this MIR phase")
864 }
865 }
866 }
867
868 fn visit_after_early_terminator_effect(
869 &mut self,
870 _analysis: &Borrowck<'a, 'tcx>,
871 state: &BorrowckDomain,
872 term: &Terminator<'tcx>,
873 loc: Location,
874 ) {
875 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:875",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(875u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("MirBorrowckCtxt::process_terminator({0:?}, {1:?}): {2:?}",
loc, term, state) as &dyn Value))])
});
} else { ; }
};debug!("MirBorrowckCtxt::process_terminator({:?}, {:?}): {:?}", loc, term, state);
876 let span = term.source_info.span;
877
878 self.check_activations(loc, span, state);
879
880 match &term.kind {
881 TerminatorKind::SwitchInt { discr, targets: _ } => {
882 self.consume_operand(loc, (discr, span), state);
883 }
884 TerminatorKind::Drop {
885 place,
886 target: _,
887 unwind: _,
888 replace,
889 drop: _,
890 async_fut: _,
891 } => {
892 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:892",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(892u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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_drop loc: {0:?} term: {1:?} place: {2:?} span: {3:?}",
loc, term, place, span) as &dyn Value))])
});
} else { ; }
};debug!(
893 "visit_terminator_drop \
894 loc: {:?} term: {:?} place: {:?} span: {:?}",
895 loc, term, place, span
896 );
897
898 let write_kind =
899 if *replace { WriteKind::Replace } else { WriteKind::StorageDeadOrDrop };
900 self.access_place(
901 loc,
902 (*place, span),
903 (AccessDepth::Drop, Write(write_kind)),
904 LocalMutationIsAllowed::Yes,
905 state,
906 );
907 }
908 TerminatorKind::Call {
909 func,
910 args,
911 destination,
912 target: _,
913 unwind: _,
914 call_source: _,
915 fn_span: _,
916 } => {
917 self.consume_operand(loc, (func, span), state);
918 for arg in args {
919 self.consume_operand(loc, (&arg.node, arg.span), state);
920 }
921 self.mutate_place(loc, (*destination, span), Deep, state);
922 }
923 TerminatorKind::TailCall { func, args, fn_span: _ } => {
924 self.consume_operand(loc, (func, span), state);
925 for arg in args {
926 self.consume_operand(loc, (&arg.node, arg.span), state);
927 }
928 }
929 TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
930 self.consume_operand(loc, (cond, span), state);
931 if let AssertKind::BoundsCheck { len, index } = &**msg {
932 self.consume_operand(loc, (len, span), state);
933 self.consume_operand(loc, (index, span), state);
934 }
935 }
936
937 TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => {
938 self.consume_operand(loc, (value, span), state);
939 self.mutate_place(loc, (*resume_arg, span), Deep, state);
940 }
941
942 TerminatorKind::InlineAsm {
943 asm_macro: _,
944 template: _,
945 operands,
946 options: _,
947 line_spans: _,
948 targets: _,
949 unwind: _,
950 } => {
951 for op in operands {
952 match op {
953 InlineAsmOperand::In { reg: _, value } => {
954 self.consume_operand(loc, (value, span), state);
955 }
956 InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
957 if let Some(place) = place {
958 self.mutate_place(loc, (*place, span), Shallow(None), state);
959 }
960 }
961 InlineAsmOperand::InOut { reg: _, late: _, in_value, out_place } => {
962 self.consume_operand(loc, (in_value, span), state);
963 if let &Some(out_place) = out_place {
964 self.mutate_place(loc, (out_place, span), Shallow(None), state);
965 }
966 }
967 InlineAsmOperand::Const { value: _ }
968 | InlineAsmOperand::SymFn { value: _ }
969 | InlineAsmOperand::SymStatic { def_id: _ }
970 | InlineAsmOperand::Label { target_index: _ } => {}
971 }
972 }
973 }
974
975 TerminatorKind::Goto { target: _ }
976 | TerminatorKind::UnwindTerminate(_)
977 | TerminatorKind::Unreachable
978 | TerminatorKind::UnwindResume
979 | TerminatorKind::Return
980 | TerminatorKind::CoroutineDrop
981 | TerminatorKind::FalseEdge { real_target: _, imaginary_target: _ }
982 | TerminatorKind::FalseUnwind { real_target: _, unwind: _ } => {
983 }
985 }
986 }
987
988 fn visit_after_primary_terminator_effect(
989 &mut self,
990 _analysis: &Borrowck<'a, 'tcx>,
991 state: &BorrowckDomain,
992 term: &Terminator<'tcx>,
993 loc: Location,
994 ) {
995 let span = term.source_info.span;
996
997 match term.kind {
998 TerminatorKind::Yield { value: _, resume: _, resume_arg: _, drop: _ } => {
999 if self.movable_coroutine {
1000 for i in state.borrows.iter() {
1002 let borrow = &self.borrow_set[i];
1003 self.check_for_local_borrow(borrow, span);
1004 }
1005 }
1006 }
1007
1008 TerminatorKind::UnwindResume
1009 | TerminatorKind::Return
1010 | TerminatorKind::TailCall { .. }
1011 | TerminatorKind::CoroutineDrop => {
1012 match self.borrow_set.locals_state_at_exit() {
1013 LocalsStateAtExit::AllAreInvalidated => {
1014 for i in state.borrows.iter() {
1019 let borrow = &self.borrow_set[i];
1020 self.check_for_invalidation_at_exit(loc, borrow, span);
1021 }
1022 }
1023 LocalsStateAtExit::SomeAreInvalidated { has_storage_dead_or_moved: _ } => {}
1026 }
1027 }
1028
1029 TerminatorKind::UnwindTerminate(_)
1030 | TerminatorKind::Assert { .. }
1031 | TerminatorKind::Call { .. }
1032 | TerminatorKind::Drop { .. }
1033 | TerminatorKind::FalseEdge { real_target: _, imaginary_target: _ }
1034 | TerminatorKind::FalseUnwind { real_target: _, unwind: _ }
1035 | TerminatorKind::Goto { .. }
1036 | TerminatorKind::SwitchInt { .. }
1037 | TerminatorKind::Unreachable
1038 | TerminatorKind::InlineAsm { .. } => {}
1039 }
1040 }
1041}
1042
1043use self::AccessDepth::{Deep, Shallow};
1044use self::ReadOrWrite::{Activation, Read, Reservation, Write};
1045
1046#[derive(#[automatically_derived]
impl ::core::marker::Copy for ArtificialField { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ArtificialField {
#[inline]
fn clone(&self) -> ArtificialField { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ArtificialField {
#[inline]
fn eq(&self, other: &ArtificialField) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ArtificialField {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for ArtificialField {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ArtificialField::ArrayLength => "ArrayLength",
ArtificialField::FakeBorrow => "FakeBorrow",
})
}
}Debug)]
1047enum ArtificialField {
1048 ArrayLength,
1049 FakeBorrow,
1050}
1051
1052#[derive(#[automatically_derived]
impl ::core::marker::Copy for AccessDepth { }Copy, #[automatically_derived]
impl ::core::clone::Clone for AccessDepth {
#[inline]
fn clone(&self) -> AccessDepth {
let _: ::core::clone::AssertParamIsClone<Option<ArtificialField>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for AccessDepth {
#[inline]
fn eq(&self, other: &AccessDepth) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(AccessDepth::Shallow(__self_0),
AccessDepth::Shallow(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AccessDepth {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Option<ArtificialField>>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for AccessDepth {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AccessDepth::Shallow(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Shallow", &__self_0),
AccessDepth::Deep => ::core::fmt::Formatter::write_str(f, "Deep"),
AccessDepth::Drop => ::core::fmt::Formatter::write_str(f, "Drop"),
}
}
}Debug)]
1053enum AccessDepth {
1054 Shallow(Option<ArtificialField>),
1060
1061 Deep,
1065
1066 Drop,
1069}
1070
1071#[derive(#[automatically_derived]
impl ::core::marker::Copy for ReadOrWrite { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ReadOrWrite {
#[inline]
fn clone(&self) -> ReadOrWrite {
let _: ::core::clone::AssertParamIsClone<ReadKind>;
let _: ::core::clone::AssertParamIsClone<WriteKind>;
let _: ::core::clone::AssertParamIsClone<BorrowIndex>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ReadOrWrite {
#[inline]
fn eq(&self, other: &ReadOrWrite) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ReadOrWrite::Read(__self_0), ReadOrWrite::Read(__arg1_0)) =>
__self_0 == __arg1_0,
(ReadOrWrite::Write(__self_0), ReadOrWrite::Write(__arg1_0))
=> __self_0 == __arg1_0,
(ReadOrWrite::Reservation(__self_0),
ReadOrWrite::Reservation(__arg1_0)) => __self_0 == __arg1_0,
(ReadOrWrite::Activation(__self_0, __self_1),
ReadOrWrite::Activation(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ReadOrWrite {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ReadKind>;
let _: ::core::cmp::AssertParamIsEq<WriteKind>;
let _: ::core::cmp::AssertParamIsEq<BorrowIndex>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for ReadOrWrite {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ReadOrWrite::Read(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Read",
&__self_0),
ReadOrWrite::Write(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Write",
&__self_0),
ReadOrWrite::Reservation(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Reservation", &__self_0),
ReadOrWrite::Activation(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"Activation", __self_0, &__self_1),
}
}
}Debug)]
1074enum ReadOrWrite {
1075 Read(ReadKind),
1078
1079 Write(WriteKind),
1083
1084 Reservation(WriteKind),
1088 Activation(WriteKind, BorrowIndex),
1089}
1090
1091#[derive(#[automatically_derived]
impl ::core::marker::Copy for ReadKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ReadKind {
#[inline]
fn clone(&self) -> ReadKind {
let _: ::core::clone::AssertParamIsClone<BorrowKind>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ReadKind {
#[inline]
fn eq(&self, other: &ReadKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ReadKind::Borrow(__self_0), ReadKind::Borrow(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ReadKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<BorrowKind>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for ReadKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ReadKind::Borrow(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Borrow",
&__self_0),
ReadKind::Copy => ::core::fmt::Formatter::write_str(f, "Copy"),
}
}
}Debug)]
1094enum ReadKind {
1095 Borrow(BorrowKind),
1096 Copy,
1097}
1098
1099#[derive(#[automatically_derived]
impl ::core::marker::Copy for WriteKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for WriteKind {
#[inline]
fn clone(&self) -> WriteKind {
let _: ::core::clone::AssertParamIsClone<BorrowKind>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for WriteKind {
#[inline]
fn eq(&self, other: &WriteKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(WriteKind::MutableBorrow(__self_0),
WriteKind::MutableBorrow(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for WriteKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<BorrowKind>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for WriteKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
WriteKind::StorageDeadOrDrop =>
::core::fmt::Formatter::write_str(f, "StorageDeadOrDrop"),
WriteKind::Replace =>
::core::fmt::Formatter::write_str(f, "Replace"),
WriteKind::MutableBorrow(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"MutableBorrow", &__self_0),
WriteKind::Mutate =>
::core::fmt::Formatter::write_str(f, "Mutate"),
WriteKind::Move => ::core::fmt::Formatter::write_str(f, "Move"),
}
}
}Debug)]
1102enum WriteKind {
1103 StorageDeadOrDrop,
1104 Replace,
1105 MutableBorrow(BorrowKind),
1106 Mutate,
1107 Move,
1108}
1109
1110#[derive(#[automatically_derived]
impl ::core::marker::Copy for LocalMutationIsAllowed { }Copy, #[automatically_derived]
impl ::core::clone::Clone for LocalMutationIsAllowed {
#[inline]
fn clone(&self) -> LocalMutationIsAllowed { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for LocalMutationIsAllowed {
#[inline]
fn eq(&self, other: &LocalMutationIsAllowed) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for LocalMutationIsAllowed {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for LocalMutationIsAllowed {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
LocalMutationIsAllowed::Yes => "Yes",
LocalMutationIsAllowed::ExceptUpvars => "ExceptUpvars",
LocalMutationIsAllowed::No => "No",
})
}
}Debug)]
1118enum LocalMutationIsAllowed {
1119 Yes,
1120 ExceptUpvars,
1123 No,
1124}
1125
1126#[derive(#[automatically_derived]
impl ::core::marker::Copy for InitializationRequiringAction { }Copy, #[automatically_derived]
impl ::core::clone::Clone for InitializationRequiringAction {
#[inline]
fn clone(&self) -> InitializationRequiringAction { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for InitializationRequiringAction {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
InitializationRequiringAction::Borrow => "Borrow",
InitializationRequiringAction::MatchOn => "MatchOn",
InitializationRequiringAction::Use => "Use",
InitializationRequiringAction::Assignment => "Assignment",
InitializationRequiringAction::PartialAssignment =>
"PartialAssignment",
})
}
}Debug)]
1127enum InitializationRequiringAction {
1128 Borrow,
1129 MatchOn,
1130 Use,
1131 Assignment,
1132 PartialAssignment,
1133}
1134
1135#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for RootPlace<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "RootPlace",
"place_local", &self.place_local, "place_projection",
&self.place_projection, "is_local_mutation_allowed",
&&self.is_local_mutation_allowed)
}
}Debug)]
1136struct RootPlace<'tcx> {
1137 place_local: Local,
1138 place_projection: &'tcx [PlaceElem<'tcx>],
1139 is_local_mutation_allowed: LocalMutationIsAllowed,
1140}
1141
1142impl InitializationRequiringAction {
1143 fn as_noun(self) -> &'static str {
1144 match self {
1145 InitializationRequiringAction::Borrow => "borrow",
1146 InitializationRequiringAction::MatchOn => "use", InitializationRequiringAction::Use => "use",
1148 InitializationRequiringAction::Assignment => "assign",
1149 InitializationRequiringAction::PartialAssignment => "assign to part",
1150 }
1151 }
1152
1153 fn as_verb_in_past_tense(self) -> &'static str {
1154 match self {
1155 InitializationRequiringAction::Borrow => "borrowed",
1156 InitializationRequiringAction::MatchOn => "matched on",
1157 InitializationRequiringAction::Use => "used",
1158 InitializationRequiringAction::Assignment => "assigned",
1159 InitializationRequiringAction::PartialAssignment => "partially assigned",
1160 }
1161 }
1162
1163 fn as_general_verb_in_past_tense(self) -> &'static str {
1164 match self {
1165 InitializationRequiringAction::Borrow
1166 | InitializationRequiringAction::MatchOn
1167 | InitializationRequiringAction::Use => "used",
1168 InitializationRequiringAction::Assignment => "assigned",
1169 InitializationRequiringAction::PartialAssignment => "partially assigned",
1170 }
1171 }
1172}
1173
1174impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
1175 fn body(&self) -> &'a Body<'tcx> {
1176 self.body
1177 }
1178
1179 fn access_place(
1186 &mut self,
1187 location: Location,
1188 place_span: (Place<'tcx>, Span),
1189 kind: (AccessDepth, ReadOrWrite),
1190 is_local_mutation_allowed: LocalMutationIsAllowed,
1191 state: &BorrowckDomain,
1192 ) {
1193 let (sd, rw) = kind;
1194
1195 if let Activation(_, borrow_index) = rw {
1196 if self.reservation_error_reported.contains(&place_span.0) {
1197 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1197",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1197u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("skipping access_place for activation of invalid reservation place: {0:?} borrow_index: {1:?}",
place_span.0, borrow_index) as &dyn Value))])
});
} else { ; }
};debug!(
1198 "skipping access_place for activation of invalid reservation \
1199 place: {:?} borrow_index: {:?}",
1200 place_span.0, borrow_index
1201 );
1202 return;
1203 }
1204 }
1205
1206 if !self.access_place_error_reported.is_empty()
1209 && self.access_place_error_reported.contains(&(place_span.0, place_span.1))
1210 {
1211 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1211",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1211u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("access_place: suppressing error place_span=`{0:?}` kind=`{1:?}`",
place_span, kind) as &dyn Value))])
});
} else { ; }
};debug!(
1212 "access_place: suppressing error place_span=`{:?}` kind=`{:?}`",
1213 place_span, kind
1214 );
1215
1216 if rw == ReadOrWrite::Write(WriteKind::Mutate)
1220 && let Ok(root_place) =
1221 self.is_mutable(place_span.0.as_ref(), is_local_mutation_allowed)
1222 {
1223 self.add_used_mut(root_place, state);
1224 }
1225
1226 return;
1227 }
1228
1229 let mutability_error = self.check_access_permissions(
1230 place_span,
1231 rw,
1232 is_local_mutation_allowed,
1233 state,
1234 location,
1235 );
1236 let conflict_error = self.check_access_for_conflict(location, place_span, sd, rw, state);
1237
1238 if conflict_error || mutability_error {
1239 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1239",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1239u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("access_place: logging error place_span=`{0:?}` kind=`{1:?}`",
place_span, kind) as &dyn Value))])
});
} else { ; }
};debug!("access_place: logging error place_span=`{:?}` kind=`{:?}`", place_span, kind);
1240 self.access_place_error_reported.insert((place_span.0, place_span.1));
1241 }
1242 }
1243
1244 fn borrows_in_scope<'s>(
1245 &self,
1246 location: Location,
1247 state: &'s BorrowckDomain,
1248 ) -> Cow<'s, MixedBitSet<BorrowIndex>> {
1249 if let Some(polonius) = &self.polonius_output {
1250 let location = self.location_table.start_index(location);
1252 let mut polonius_output = MixedBitSet::new_empty(self.borrow_set.len());
1253 for &idx in polonius.errors_at(location) {
1254 polonius_output.insert(idx);
1255 }
1256 Cow::Owned(polonius_output)
1257 } else {
1258 Cow::Borrowed(&state.borrows)
1259 }
1260 }
1261
1262 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("check_access_for_conflict",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1262u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["location",
"place_span", "sd", "rw"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place_span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sd)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rw)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: bool = loop {};
return __tracing_attr_fake_return;
}
{
let mut error_reported = false;
let borrows_in_scope = self.borrows_in_scope(location, state);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1274",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1274u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["borrows_in_scope",
"location"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::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(&debug(&borrows_in_scope)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&location)
as &dyn Value))])
});
} else { ; }
};
each_borrow_involving_path(self, self.infcx.tcx, self.body,
(sd, place_span.0), self.borrow_set,
|borrow_index| borrows_in_scope.contains(borrow_index),
|this, borrow_index, borrow|
match (rw, borrow.kind) {
(Activation(_, activating), _) if activating == borrow_index
=> {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1291",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1291u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::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!("check_access_for_conflict place_span: {0:?} sd: {1:?} rw: {2:?} skipping {3:?} b/c activation of same borrow_index",
place_span, sd, rw, (borrow_index, borrow)) as
&dyn Value))])
});
} else { ; }
};
ControlFlow::Continue(())
}
(Read(_), BorrowKind::Shared | BorrowKind::Fake(_)) |
(Read(ReadKind::Borrow(BorrowKind::Fake(FakeBorrowKind::Shallow))),
BorrowKind::Mut { .. }) => ControlFlow::Continue(()),
(Reservation(_), BorrowKind::Fake(_) | BorrowKind::Shared)
=> {
ControlFlow::Continue(())
}
(Write(WriteKind::Move),
BorrowKind::Fake(FakeBorrowKind::Shallow)) => {
ControlFlow::Continue(())
}
(Read(kind), BorrowKind::Mut { .. }) => {
if !is_active(this.dominators(), borrow, location) {
if !borrow.kind.is_two_phase_borrow() {
::core::panicking::panic("assertion failed: borrow.kind.is_two_phase_borrow()")
};
return ControlFlow::Continue(());
}
error_reported = true;
match kind {
ReadKind::Copy => {
let err =
this.report_use_while_mutably_borrowed(location, place_span,
borrow);
this.buffer_error(err);
}
ReadKind::Borrow(bk) => {
let err =
this.report_conflicting_borrow(location, place_span, bk,
borrow);
this.buffer_error(err);
}
}
ControlFlow::Break(())
}
(Reservation(kind) | Activation(kind, _) | Write(kind), _)
=> {
match rw {
Reservation(..) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1345",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1345u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::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!("recording invalid reservation of place: {0:?}",
place_span.0) as &dyn Value))])
});
} else { ; }
};
this.reservation_error_reported.insert(place_span.0);
}
Activation(_, activating) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1353",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1353u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::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!("observing check_place for activation of borrow_index: {0:?}",
activating) as &dyn Value))])
});
} else { ; }
};
}
Read(..) | Write(..) => {}
}
error_reported = true;
match kind {
WriteKind::MutableBorrow(bk) => {
let err =
this.report_conflicting_borrow(location, place_span, bk,
borrow);
this.buffer_error(err);
}
WriteKind::StorageDeadOrDrop =>
this.report_borrowed_value_does_not_live_long_enough(location,
borrow, place_span, Some(WriteKind::StorageDeadOrDrop)),
WriteKind::Mutate => {
this.report_illegal_mutation_of_borrowed(location,
place_span, borrow)
}
WriteKind::Move => {
this.report_move_out_while_borrowed(location, place_span,
borrow)
}
WriteKind::Replace => {
this.report_illegal_mutation_of_borrowed(location,
place_span, borrow)
}
}
ControlFlow::Break(())
}
});
error_reported
}
}
}#[instrument(level = "debug", skip(self, state))]
1263 fn check_access_for_conflict(
1264 &mut self,
1265 location: Location,
1266 place_span: (Place<'tcx>, Span),
1267 sd: AccessDepth,
1268 rw: ReadOrWrite,
1269 state: &BorrowckDomain,
1270 ) -> bool {
1271 let mut error_reported = false;
1272
1273 let borrows_in_scope = self.borrows_in_scope(location, state);
1274 debug!(?borrows_in_scope, ?location);
1275
1276 each_borrow_involving_path(
1277 self,
1278 self.infcx.tcx,
1279 self.body,
1280 (sd, place_span.0),
1281 self.borrow_set,
1282 |borrow_index| borrows_in_scope.contains(borrow_index),
1283 |this, borrow_index, borrow| match (rw, borrow.kind) {
1284 (Activation(_, activating), _) if activating == borrow_index => {
1291 debug!(
1292 "check_access_for_conflict place_span: {:?} sd: {:?} rw: {:?} \
1293 skipping {:?} b/c activation of same borrow_index",
1294 place_span,
1295 sd,
1296 rw,
1297 (borrow_index, borrow),
1298 );
1299 ControlFlow::Continue(())
1300 }
1301
1302 (Read(_), BorrowKind::Shared | BorrowKind::Fake(_))
1303 | (
1304 Read(ReadKind::Borrow(BorrowKind::Fake(FakeBorrowKind::Shallow))),
1305 BorrowKind::Mut { .. },
1306 ) => ControlFlow::Continue(()),
1307
1308 (Reservation(_), BorrowKind::Fake(_) | BorrowKind::Shared) => {
1309 ControlFlow::Continue(())
1312 }
1313
1314 (Write(WriteKind::Move), BorrowKind::Fake(FakeBorrowKind::Shallow)) => {
1315 ControlFlow::Continue(())
1317 }
1318
1319 (Read(kind), BorrowKind::Mut { .. }) => {
1320 if !is_active(this.dominators(), borrow, location) {
1322 assert!(borrow.kind.is_two_phase_borrow());
1323 return ControlFlow::Continue(());
1324 }
1325
1326 error_reported = true;
1327 match kind {
1328 ReadKind::Copy => {
1329 let err = this
1330 .report_use_while_mutably_borrowed(location, place_span, borrow);
1331 this.buffer_error(err);
1332 }
1333 ReadKind::Borrow(bk) => {
1334 let err =
1335 this.report_conflicting_borrow(location, place_span, bk, borrow);
1336 this.buffer_error(err);
1337 }
1338 }
1339 ControlFlow::Break(())
1340 }
1341
1342 (Reservation(kind) | Activation(kind, _) | Write(kind), _) => {
1343 match rw {
1344 Reservation(..) => {
1345 debug!(
1346 "recording invalid reservation of \
1347 place: {:?}",
1348 place_span.0
1349 );
1350 this.reservation_error_reported.insert(place_span.0);
1351 }
1352 Activation(_, activating) => {
1353 debug!(
1354 "observing check_place for activation of \
1355 borrow_index: {:?}",
1356 activating
1357 );
1358 }
1359 Read(..) | Write(..) => {}
1360 }
1361
1362 error_reported = true;
1363 match kind {
1364 WriteKind::MutableBorrow(bk) => {
1365 let err =
1366 this.report_conflicting_borrow(location, place_span, bk, borrow);
1367 this.buffer_error(err);
1368 }
1369 WriteKind::StorageDeadOrDrop => this
1370 .report_borrowed_value_does_not_live_long_enough(
1371 location,
1372 borrow,
1373 place_span,
1374 Some(WriteKind::StorageDeadOrDrop),
1375 ),
1376 WriteKind::Mutate => {
1377 this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
1378 }
1379 WriteKind::Move => {
1380 this.report_move_out_while_borrowed(location, place_span, borrow)
1381 }
1382 WriteKind::Replace => {
1383 this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
1384 }
1385 }
1386 ControlFlow::Break(())
1387 }
1388 },
1389 );
1390
1391 error_reported
1392 }
1393
1394 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("check_backward_incompatible_drop",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1396u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["location", "place"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.infcx.tcx;
let sd =
if place.ty(self.body,
tcx).ty.needs_drop(tcx, self.body.typing_env(tcx)) {
AccessDepth::Drop
} else { AccessDepth::Shallow(None) };
let borrows_in_scope = self.borrows_in_scope(location, state);
each_borrow_involving_path(self, self.infcx.tcx, self.body,
(sd, place), self.borrow_set,
|borrow_index| borrows_in_scope.contains(borrow_index),
|this, _borrow_index, borrow|
{
if #[allow(non_exhaustive_omitted_patterns)] match borrow.kind
{
BorrowKind::Fake(_) => true,
_ => false,
} {
return ControlFlow::Continue(());
}
let borrowed =
this.retrieve_borrow_spans(borrow).var_or_use_path_span();
let explain =
this.explain_why_borrow_contains_point(location, borrow,
Some((WriteKind::StorageDeadOrDrop, place)));
this.infcx.tcx.emit_node_span_lint(TAIL_EXPR_DROP_ORDER,
CRATE_HIR_ID, borrowed,
session_diagnostics::TailExprDropOrder {
borrowed,
callback: |diag|
{
explain.add_explanation_to_diagnostic(&this, diag, "", None,
None);
},
});
ControlFlow::Break(())
});
}
}
}#[instrument(level = "debug", skip(self, state))]
1397 fn check_backward_incompatible_drop(
1398 &mut self,
1399 location: Location,
1400 place: Place<'tcx>,
1401 state: &BorrowckDomain,
1402 ) {
1403 let tcx = self.infcx.tcx;
1404 let sd = if place.ty(self.body, tcx).ty.needs_drop(tcx, self.body.typing_env(tcx)) {
1408 AccessDepth::Drop
1409 } else {
1410 AccessDepth::Shallow(None)
1411 };
1412
1413 let borrows_in_scope = self.borrows_in_scope(location, state);
1414
1415 each_borrow_involving_path(
1418 self,
1419 self.infcx.tcx,
1420 self.body,
1421 (sd, place),
1422 self.borrow_set,
1423 |borrow_index| borrows_in_scope.contains(borrow_index),
1424 |this, _borrow_index, borrow| {
1425 if matches!(borrow.kind, BorrowKind::Fake(_)) {
1426 return ControlFlow::Continue(());
1427 }
1428 let borrowed = this.retrieve_borrow_spans(borrow).var_or_use_path_span();
1429 let explain = this.explain_why_borrow_contains_point(
1430 location,
1431 borrow,
1432 Some((WriteKind::StorageDeadOrDrop, place)),
1433 );
1434 this.infcx.tcx.emit_node_span_lint(
1435 TAIL_EXPR_DROP_ORDER,
1436 CRATE_HIR_ID,
1437 borrowed,
1438 session_diagnostics::TailExprDropOrder {
1439 borrowed,
1440 callback: |diag| {
1441 explain.add_explanation_to_diagnostic(&this, diag, "", None, None);
1442 },
1443 },
1444 );
1445 ControlFlow::Break(())
1447 },
1448 );
1449 }
1450
1451 fn mutate_place(
1452 &mut self,
1453 location: Location,
1454 place_span: (Place<'tcx>, Span),
1455 kind: AccessDepth,
1456 state: &BorrowckDomain,
1457 ) {
1458 self.check_if_assigned_path_is_moved(location, place_span, state);
1460
1461 self.access_place(
1462 location,
1463 place_span,
1464 (kind, Write(WriteKind::Mutate)),
1465 LocalMutationIsAllowed::No,
1466 state,
1467 );
1468 }
1469
1470 fn consume_rvalue(
1471 &mut self,
1472 location: Location,
1473 (rvalue, span): (&Rvalue<'tcx>, Span),
1474 state: &BorrowckDomain,
1475 ) {
1476 match rvalue {
1477 &Rvalue::Ref(_ , bk, place) => {
1478 let access_kind = match bk {
1479 BorrowKind::Fake(FakeBorrowKind::Shallow) => {
1480 (Shallow(Some(ArtificialField::FakeBorrow)), Read(ReadKind::Borrow(bk)))
1481 }
1482 BorrowKind::Shared | BorrowKind::Fake(FakeBorrowKind::Deep) => {
1483 (Deep, Read(ReadKind::Borrow(bk)))
1484 }
1485 BorrowKind::Mut { .. } => {
1486 let wk = WriteKind::MutableBorrow(bk);
1487 if bk.is_two_phase_borrow() {
1488 (Deep, Reservation(wk))
1489 } else {
1490 (Deep, Write(wk))
1491 }
1492 }
1493 };
1494
1495 self.access_place(
1496 location,
1497 (place, span),
1498 access_kind,
1499 LocalMutationIsAllowed::No,
1500 state,
1501 );
1502
1503 let action = if bk == BorrowKind::Fake(FakeBorrowKind::Shallow) {
1504 InitializationRequiringAction::MatchOn
1505 } else {
1506 InitializationRequiringAction::Borrow
1507 };
1508
1509 self.check_if_path_or_subpath_is_moved(
1510 location,
1511 action,
1512 (place.as_ref(), span),
1513 state,
1514 );
1515 }
1516
1517 &Rvalue::Reborrow(_target, mutability, place) => {
1518 let access_kind = (
1519 Deep,
1520 if mutability == Mutability::Mut {
1521 Write(WriteKind::MutableBorrow(BorrowKind::Mut {
1522 kind: MutBorrowKind::Default,
1523 }))
1524 } else {
1525 Read(ReadKind::Borrow(BorrowKind::Shared))
1526 },
1527 );
1528
1529 self.access_place(
1530 location,
1531 (place, span),
1532 access_kind,
1533 LocalMutationIsAllowed::Yes,
1534 state,
1535 );
1536
1537 let action = InitializationRequiringAction::Borrow;
1538
1539 self.check_if_path_or_subpath_is_moved(
1540 location,
1541 action,
1542 (place.as_ref(), span),
1543 state,
1544 );
1545 }
1546
1547 &Rvalue::RawPtr(kind, place) => {
1548 let access_kind = match kind {
1549 RawPtrKind::Mut => (
1550 Deep,
1551 Write(WriteKind::MutableBorrow(BorrowKind::Mut {
1552 kind: MutBorrowKind::Default,
1553 })),
1554 ),
1555 RawPtrKind::Const => (Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
1556 RawPtrKind::FakeForPtrMetadata => {
1557 (Shallow(Some(ArtificialField::ArrayLength)), Read(ReadKind::Copy))
1558 }
1559 };
1560
1561 self.access_place(
1562 location,
1563 (place, span),
1564 access_kind,
1565 LocalMutationIsAllowed::No,
1566 state,
1567 );
1568
1569 self.check_if_path_or_subpath_is_moved(
1570 location,
1571 InitializationRequiringAction::Borrow,
1572 (place.as_ref(), span),
1573 state,
1574 );
1575 }
1576
1577 Rvalue::ThreadLocalRef(_) => {}
1578
1579 Rvalue::Use(operand, _)
1580 | Rvalue::Repeat(operand, _)
1581 | Rvalue::UnaryOp(_ , operand)
1582 | Rvalue::Cast(_ , operand, _ ) => {
1583 self.consume_operand(location, (operand, span), state)
1584 }
1585
1586 &Rvalue::Discriminant(place) => {
1587 let af = match *rvalue {
1588 Rvalue::Discriminant(..) => None,
1589 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1590 };
1591 self.access_place(
1592 location,
1593 (place, span),
1594 (Shallow(af), Read(ReadKind::Copy)),
1595 LocalMutationIsAllowed::No,
1596 state,
1597 );
1598 self.check_if_path_or_subpath_is_moved(
1599 location,
1600 InitializationRequiringAction::Use,
1601 (place.as_ref(), span),
1602 state,
1603 );
1604 }
1605
1606 Rvalue::BinaryOp(_bin_op, (operand1, operand2)) => {
1607 self.consume_operand(location, (operand1, span), state);
1608 self.consume_operand(location, (operand2, span), state);
1609 }
1610
1611 Rvalue::Aggregate(aggregate_kind, operands) => {
1612 match **aggregate_kind {
1616 AggregateKind::Closure(def_id, _)
1617 | AggregateKind::CoroutineClosure(def_id, _)
1618 | AggregateKind::Coroutine(def_id, _) => {
1619 let def_id = def_id.expect_local();
1620 let used_mut_upvars = self.root_cx.used_mut_upvars(def_id);
1621 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1621",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1621u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("{0:?} used_mut_upvars={1:?}",
def_id, used_mut_upvars) as &dyn Value))])
});
} else { ; }
};debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars);
1622 for field in used_mut_upvars.clone() {
1626 self.propagate_closure_used_mut_upvar(&operands[field]);
1627 }
1628 }
1629 AggregateKind::Adt(..)
1630 | AggregateKind::Array(..)
1631 | AggregateKind::Tuple { .. }
1632 | AggregateKind::RawPtr(..) => (),
1633 }
1634
1635 for operand in operands {
1636 self.consume_operand(location, (operand, span), state);
1637 }
1638 }
1639
1640 Rvalue::WrapUnsafeBinder(op, _) => {
1641 self.consume_operand(location, (op, span), state);
1642 }
1643
1644 Rvalue::CopyForDeref(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("`CopyForDeref` in borrowck"))bug!("`CopyForDeref` in borrowck"),
1645 }
1646 }
1647
1648 fn propagate_closure_used_mut_upvar(&mut self, operand: &Operand<'tcx>) {
1649 let propagate_closure_used_mut_place = |this: &mut Self, place: Place<'tcx>| {
1650 if let Some(field) = this.is_upvar_field_projection(place.as_ref()) {
1658 this.used_mut_upvars.push(field);
1659 return;
1660 }
1661
1662 for (place_ref, proj) in place.iter_projections().rev() {
1663 if proj == ProjectionElem::Deref {
1665 match place_ref.ty(this.body(), this.infcx.tcx).ty.kind() {
1666 ty::Ref(_, _, hir::Mutability::Mut) => return,
1668
1669 _ => {}
1670 }
1671 }
1672
1673 if let Some(field) = this.is_upvar_field_projection(place_ref) {
1675 this.used_mut_upvars.push(field);
1676 return;
1677 }
1678 }
1679
1680 this.used_mut.insert(place.local);
1682 };
1683
1684 match *operand {
1688 Operand::Move(place) | Operand::Copy(place) => {
1689 match place.as_local() {
1690 Some(local) if !self.body.local_decls[local].is_user_variable() => {
1691 if self.body.local_decls[local].ty.is_mutable_ptr() {
1692 return;
1694 }
1695 let Some(temp_mpi) = self.move_data.rev_lookup.find_local(local) else {
1711 ::rustc_middle::util::bug::bug_fmt(format_args!("temporary should be tracked"));bug!("temporary should be tracked");
1712 };
1713 let init = if let [init_index] = *self.move_data.init_path_map[temp_mpi] {
1714 &self.move_data.inits[init_index]
1715 } else {
1716 ::rustc_middle::util::bug::bug_fmt(format_args!("temporary should be initialized exactly once"))bug!("temporary should be initialized exactly once")
1717 };
1718
1719 let InitLocation::Statement(loc) = init.location else {
1720 ::rustc_middle::util::bug::bug_fmt(format_args!("temporary initialized in arguments"))bug!("temporary initialized in arguments")
1721 };
1722
1723 let body = self.body;
1724 let bbd = &body[loc.block];
1725 let stmt = &bbd.statements[loc.statement_index];
1726 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1726",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1726u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("temporary assigned in: stmt={0:?}",
stmt) as &dyn Value))])
});
} else { ; }
};debug!("temporary assigned in: stmt={:?}", stmt);
1727
1728 match stmt.kind {
1729 StatementKind::Assign((
1730 _,
1731 Rvalue::Ref(_, _, source)
1732 | Rvalue::Use(Operand::Copy(source) | Operand::Move(source), _),
1733 )) => {
1734 propagate_closure_used_mut_place(self, source);
1735 }
1736 _ => {
1737 ::rustc_middle::util::bug::bug_fmt(format_args!("closures should only capture user variables or references to user variables"));bug!(
1738 "closures should only capture user variables \
1739 or references to user variables"
1740 );
1741 }
1742 }
1743 }
1744 _ => propagate_closure_used_mut_place(self, place),
1745 }
1746 }
1747 Operand::Constant(..) | Operand::RuntimeChecks(_) => {}
1748 }
1749 }
1750
1751 fn consume_operand(
1752 &mut self,
1753 location: Location,
1754 (operand, span): (&Operand<'tcx>, Span),
1755 state: &BorrowckDomain,
1756 ) {
1757 match *operand {
1758 Operand::Copy(place) => {
1759 self.access_place(
1762 location,
1763 (place, span),
1764 (Deep, Read(ReadKind::Copy)),
1765 LocalMutationIsAllowed::No,
1766 state,
1767 );
1768
1769 self.check_if_path_or_subpath_is_moved(
1771 location,
1772 InitializationRequiringAction::Use,
1773 (place.as_ref(), span),
1774 state,
1775 );
1776 }
1777 Operand::Move(place) => {
1778 self.check_movable_place(location, place);
1780
1781 self.access_place(
1783 location,
1784 (place, span),
1785 (Deep, Write(WriteKind::Move)),
1786 LocalMutationIsAllowed::Yes,
1787 state,
1788 );
1789
1790 self.check_if_path_or_subpath_is_moved(
1792 location,
1793 InitializationRequiringAction::Use,
1794 (place.as_ref(), span),
1795 state,
1796 );
1797 }
1798 Operand::Constant(_) | Operand::RuntimeChecks(_) => {}
1799 }
1800 }
1801
1802 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("check_for_invalidation_at_exit",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1804u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["location", "borrow",
"span"], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&borrow)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let place = borrow.borrowed_place;
let mut root_place =
PlaceRef { local: place.local, projection: &[] };
let might_be_alive =
if self.body.local_decls[root_place.local].is_ref_to_thread_local()
{
root_place.projection = TyCtxtConsts::DEREF_PROJECTION;
true
} else { false };
let sd = if might_be_alive { Deep } else { Shallow(None) };
if places_conflict::borrow_conflicts_with_place(self.infcx.tcx,
self.body, place, borrow.kind, root_place, sd,
places_conflict::PlaceConflictBias::Overlap) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1840",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1840u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::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!("check_for_invalidation_at_exit({0:?}): INVALID",
place) as &dyn Value))])
});
} else { ; }
};
let span = self.infcx.tcx.sess.source_map().end_point(span);
self.report_borrowed_value_does_not_live_long_enough(location,
borrow, (place, span), None)
}
}
}
}#[instrument(level = "debug", skip(self))]
1805 fn check_for_invalidation_at_exit(
1806 &mut self,
1807 location: Location,
1808 borrow: &BorrowData<'tcx>,
1809 span: Span,
1810 ) {
1811 let place = borrow.borrowed_place;
1812 let mut root_place = PlaceRef { local: place.local, projection: &[] };
1813
1814 let might_be_alive = if self.body.local_decls[root_place.local].is_ref_to_thread_local() {
1820 root_place.projection = TyCtxtConsts::DEREF_PROJECTION;
1824 true
1825 } else {
1826 false
1827 };
1828
1829 let sd = if might_be_alive { Deep } else { Shallow(None) };
1830
1831 if places_conflict::borrow_conflicts_with_place(
1832 self.infcx.tcx,
1833 self.body,
1834 place,
1835 borrow.kind,
1836 root_place,
1837 sd,
1838 places_conflict::PlaceConflictBias::Overlap,
1839 ) {
1840 debug!("check_for_invalidation_at_exit({:?}): INVALID", place);
1841 let span = self.infcx.tcx.sess.source_map().end_point(span);
1844 self.report_borrowed_value_does_not_live_long_enough(
1845 location,
1846 borrow,
1847 (place, span),
1848 None,
1849 )
1850 }
1851 }
1852
1853 fn check_for_local_borrow(&mut self, borrow: &BorrowData<'tcx>, yield_span: Span) {
1856 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:1856",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1856u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("check_for_local_borrow({0:?})",
borrow) as &dyn Value))])
});
} else { ; }
};debug!("check_for_local_borrow({:?})", borrow);
1857
1858 if borrow_of_local_data(borrow.borrowed_place) {
1859 let err = self.cannot_borrow_across_coroutine_yield(
1860 self.retrieve_borrow_spans(borrow).var_or_use(),
1861 yield_span,
1862 );
1863
1864 self.buffer_error(err);
1865 }
1866 }
1867
1868 fn check_activations(&mut self, location: Location, span: Span, state: &BorrowckDomain) {
1869 for &borrow_index in self.borrow_set.activations_at_location(location) {
1873 let borrow = &self.borrow_set[borrow_index];
1874
1875 if !match borrow.kind {
BorrowKind::Shared | BorrowKind::Fake(_) => false,
BorrowKind::Mut { .. } => true,
} {
::core::panicking::panic("assertion failed: match borrow.kind {\n BorrowKind::Shared | BorrowKind::Fake(_) => false,\n BorrowKind::Mut { .. } => true,\n}")
};assert!(match borrow.kind {
1877 BorrowKind::Shared | BorrowKind::Fake(_) => false,
1878 BorrowKind::Mut { .. } => true,
1879 });
1880
1881 self.access_place(
1882 location,
1883 (borrow.borrowed_place, span),
1884 (Deep, Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index)),
1885 LocalMutationIsAllowed::No,
1886 state,
1887 );
1888 }
1892 }
1893
1894 fn check_movable_place(&mut self, location: Location, place: Place<'tcx>) {
1895 use IllegalMoveOriginKind::*;
1896
1897 let body = self.body;
1898 let tcx = self.infcx.tcx;
1899 let mut place_ty = PlaceTy::from_ty(body.local_decls[place.local].ty);
1900 for (place_ref, elem) in place.iter_projections() {
1901 match elem {
1902 ProjectionElem::Deref => match place_ty.ty.kind() {
1903 ty::Ref(..) | ty::RawPtr(..) => {
1904 self.move_errors.push(MoveError::new(
1905 place,
1906 location,
1907 BorrowedContent {
1908 target_place: place_ref.project_deeper(&[elem], tcx),
1909 },
1910 ));
1911 return;
1912 }
1913 ty::Adt(adt, _) => {
1914 if !adt.is_box() {
1915 ::rustc_middle::util::bug::bug_fmt(format_args!("Adt should be a box type when Place is deref"));bug!("Adt should be a box type when Place is deref");
1916 }
1917 }
1918 ty::Bool
1919 | ty::Char
1920 | ty::Int(_)
1921 | ty::Uint(_)
1922 | ty::Float(_)
1923 | ty::Foreign(_)
1924 | ty::Str
1925 | ty::Array(_, _)
1926 | ty::Pat(_, _)
1927 | ty::Slice(_)
1928 | ty::FnDef(_, _)
1929 | ty::FnPtr(..)
1930 | ty::Dynamic(_, _)
1931 | ty::Closure(_, _)
1932 | ty::CoroutineClosure(_, _)
1933 | ty::Coroutine(_, _)
1934 | ty::CoroutineWitness(..)
1935 | ty::Never
1936 | ty::Tuple(_)
1937 | ty::UnsafeBinder(_)
1938 | ty::Alias(_)
1939 | ty::Param(_)
1940 | ty::Bound(_, _)
1941 | ty::Infer(_)
1942 | ty::Error(_)
1943 | ty::Placeholder(_) => {
1944 ::rustc_middle::util::bug::bug_fmt(format_args!("When Place is Deref it\'s type shouldn\'t be {0:#?}",
place_ty))bug!("When Place is Deref it's type shouldn't be {place_ty:#?}")
1945 }
1946 },
1947 ProjectionElem::Field(_, _) => match place_ty.ty.kind() {
1948 ty::Adt(adt, _) => {
1949 if adt.has_dtor(tcx) {
1950 self.move_errors.push(MoveError::new(
1951 place,
1952 location,
1953 InteriorOfTypeWithDestructor { container_ty: place_ty.ty },
1954 ));
1955 return;
1956 }
1957 }
1958 ty::Closure(..)
1959 | ty::CoroutineClosure(..)
1960 | ty::Coroutine(_, _)
1961 | ty::Tuple(_) => (),
1962 ty::Bool
1963 | ty::Char
1964 | ty::Int(_)
1965 | ty::Uint(_)
1966 | ty::Float(_)
1967 | ty::Foreign(_)
1968 | ty::Str
1969 | ty::Array(_, _)
1970 | ty::Pat(_, _)
1971 | ty::Slice(_)
1972 | ty::RawPtr(_, _)
1973 | ty::Ref(_, _, _)
1974 | ty::FnDef(_, _)
1975 | ty::FnPtr(..)
1976 | ty::Dynamic(_, _)
1977 | ty::CoroutineWitness(..)
1978 | ty::Never
1979 | ty::UnsafeBinder(_)
1980 | ty::Alias(_)
1981 | ty::Param(_)
1982 | ty::Bound(_, _)
1983 | ty::Infer(_)
1984 | ty::Error(_)
1985 | ty::Placeholder(_) => ::rustc_middle::util::bug::bug_fmt(format_args!("When Place contains ProjectionElem::Field it\'s type shouldn\'t be {0:#?}",
place_ty))bug!(
1986 "When Place contains ProjectionElem::Field it's type shouldn't be {place_ty:#?}"
1987 ),
1988 },
1989 ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
1990 match place_ty.ty.kind() {
1991 ty::Slice(_) => {
1992 self.move_errors.push(MoveError::new(
1993 place,
1994 location,
1995 InteriorOfSliceOrArray { ty: place_ty.ty, is_index: false },
1996 ));
1997 return;
1998 }
1999 ty::Array(_, _) => (),
2000 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("Unexpected type {0:#?}",
place_ty.ty))bug!("Unexpected type {:#?}", place_ty.ty),
2001 }
2002 }
2003 ProjectionElem::Index(_) => match place_ty.ty.kind() {
2004 ty::Array(..) | ty::Slice(..) => {
2005 self.move_errors.push(MoveError::new(
2006 place,
2007 location,
2008 InteriorOfSliceOrArray { ty: place_ty.ty, is_index: true },
2009 ));
2010 return;
2011 }
2012 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("Unexpected type {0:#?}",
place_ty))bug!("Unexpected type {place_ty:#?}"),
2013 },
2014 ProjectionElem::OpaqueCast(_)
2018 | ProjectionElem::Downcast(_, _)
2019 | ProjectionElem::UnwrapUnsafeBinder(_) => (),
2020 }
2021
2022 place_ty = place_ty.projection_ty(tcx, elem);
2023 }
2024 }
2025
2026 fn check_if_full_path_is_moved(
2027 &mut self,
2028 location: Location,
2029 desired_action: InitializationRequiringAction,
2030 place_span: (PlaceRef<'tcx>, Span),
2031 state: &BorrowckDomain,
2032 ) {
2033 let maybe_uninits = &state.uninits;
2034
2035 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2070",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2070u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("check_if_full_path_is_moved place: {0:?}",
place_span.0) as &dyn Value))])
});
} else { ; }
};debug!("check_if_full_path_is_moved place: {:?}", place_span.0);
2071 let (prefix, mpi) = self.move_path_closest_to(place_span.0);
2072 if maybe_uninits.contains(mpi) {
2073 self.report_use_of_moved_or_uninitialized(
2074 location,
2075 desired_action,
2076 (prefix, place_span.0, place_span.1),
2077 mpi,
2078 );
2079 } }
2086
2087 fn check_if_subslice_element_is_moved(
2093 &mut self,
2094 location: Location,
2095 desired_action: InitializationRequiringAction,
2096 place_span: (PlaceRef<'tcx>, Span),
2097 maybe_uninits: &MixedBitSet<MovePathIndex>,
2098 from: u64,
2099 to: u64,
2100 ) {
2101 if let Some(mpi) = self.move_path_for_place(place_span.0) {
2102 let move_paths = &self.move_data.move_paths;
2103
2104 let root_path = &move_paths[mpi];
2105 for (child_mpi, child_move_path) in root_path.children(move_paths) {
2106 let last_proj = child_move_path.place.projection.last().unwrap();
2107 if let ProjectionElem::ConstantIndex { offset, from_end, .. } = last_proj {
2108 if true {
if !!from_end {
{
::core::panicking::panic_fmt(format_args!("Array constant indexing shouldn\'t be `from_end`."));
}
};
};debug_assert!(!from_end, "Array constant indexing shouldn't be `from_end`.");
2109
2110 if (from..to).contains(offset) {
2111 let uninit_child =
2112 self.move_data.find_in_move_path_or_its_descendants(child_mpi, |mpi| {
2113 maybe_uninits.contains(mpi)
2114 });
2115
2116 if let Some(uninit_child) = uninit_child {
2117 self.report_use_of_moved_or_uninitialized(
2118 location,
2119 desired_action,
2120 (place_span.0, place_span.0, place_span.1),
2121 uninit_child,
2122 );
2123 return; }
2125 }
2126 }
2127 }
2128 }
2129 }
2130
2131 fn check_if_path_or_subpath_is_moved(
2132 &mut self,
2133 location: Location,
2134 desired_action: InitializationRequiringAction,
2135 place_span: (PlaceRef<'tcx>, Span),
2136 state: &BorrowckDomain,
2137 ) {
2138 let maybe_uninits = &state.uninits;
2139
2140 self.check_if_full_path_is_moved(location, desired_action, place_span, state);
2156
2157 if let Some((place_base, ProjectionElem::Subslice { from, to, from_end: false })) =
2158 place_span.0.last_projection()
2159 {
2160 let place_ty = place_base.ty(self.body(), self.infcx.tcx);
2161 if let ty::Array(..) = place_ty.ty.kind() {
2162 self.check_if_subslice_element_is_moved(
2163 location,
2164 desired_action,
2165 (place_base, place_span.1),
2166 maybe_uninits,
2167 from,
2168 to,
2169 );
2170 return;
2171 }
2172 }
2173
2174 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2183",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2183u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("check_if_path_or_subpath_is_moved place: {0:?}",
place_span.0) as &dyn Value))])
});
} else { ; }
};debug!("check_if_path_or_subpath_is_moved place: {:?}", place_span.0);
2184 if let Some(mpi) = self.move_path_for_place(place_span.0) {
2185 let uninit_mpi = self
2186 .move_data
2187 .find_in_move_path_or_its_descendants(mpi, |mpi| maybe_uninits.contains(mpi));
2188
2189 if let Some(uninit_mpi) = uninit_mpi {
2190 self.report_use_of_moved_or_uninitialized(
2191 location,
2192 desired_action,
2193 (place_span.0, place_span.0, place_span.1),
2194 uninit_mpi,
2195 );
2196 return; }
2198 }
2199 }
2200
2201 fn move_path_closest_to(&mut self, place: PlaceRef<'tcx>) -> (PlaceRef<'tcx>, MovePathIndex) {
2212 match self.move_data.rev_lookup.find(place) {
2213 LookupResult::Parent(Some(mpi)) | LookupResult::Exact(mpi) => {
2214 (self.move_data.move_paths[mpi].place.as_ref(), mpi)
2215 }
2216 LookupResult::Parent(None) => {
::core::panicking::panic_fmt(format_args!("should have move path for every Local"));
}panic!("should have move path for every Local"),
2217 }
2218 }
2219
2220 fn move_path_for_place(&mut self, place: PlaceRef<'tcx>) -> Option<MovePathIndex> {
2221 match self.move_data.rev_lookup.find(place) {
2226 LookupResult::Parent(_) => None,
2227 LookupResult::Exact(mpi) => Some(mpi),
2228 }
2229 }
2230
2231 fn check_if_assigned_path_is_moved(
2232 &mut self,
2233 location: Location,
2234 (place, span): (Place<'tcx>, Span),
2235 state: &BorrowckDomain,
2236 ) {
2237 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2237",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2237u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("check_if_assigned_path_is_moved place: {0:?}",
place) as &dyn Value))])
});
} else { ; }
};debug!("check_if_assigned_path_is_moved place: {:?}", place);
2238
2239 for (place_base, elem) in place.iter_projections().rev() {
2241 match elem {
2242 ProjectionElem::Index(_)
2243 | ProjectionElem::OpaqueCast(_)
2244 | ProjectionElem::ConstantIndex { .. }
2246 | ProjectionElem::Downcast(_, _) =>
2250 {}
2251
2252 ProjectionElem::UnwrapUnsafeBinder(_) => {
2253 check_parent_of_field(self, location, place_base, span, state);
2254 }
2255
2256 ProjectionElem::Deref => {
2258 self.check_if_full_path_is_moved(
2259 location,
2260 InitializationRequiringAction::Use,
2261 (place_base, span),
2262 state,
2263 );
2264 break;
2267 }
2268
2269 ProjectionElem::Subslice { .. } => {
2270 {
::core::panicking::panic_fmt(format_args!("we don\'t allow assignments to subslices, location: {0:?}",
location));
};panic!("we don't allow assignments to subslices, location: {location:?}");
2271 }
2272
2273 ProjectionElem::Field(..) => {
2274 let tcx = self.infcx.tcx;
2278 let base_ty = place_base.ty(self.body(), tcx).ty;
2279 match base_ty.kind() {
2280 ty::Adt(def, _) if def.has_dtor(tcx) => {
2281 self.check_if_path_or_subpath_is_moved(
2282 location,
2283 InitializationRequiringAction::Assignment,
2284 (place_base, span),
2285 state,
2286 );
2287
2288 break;
2291 }
2292
2293 ty::Adt(..) | ty::Tuple(..) => {
2296 check_parent_of_field(self, location, place_base, span, state);
2297 }
2298
2299 _ => {}
2300 }
2301 }
2302 }
2303 }
2304
2305 fn check_parent_of_field<'a, 'tcx>(
2306 this: &mut MirBorrowckCtxt<'a, '_, 'tcx>,
2307 location: Location,
2308 base: PlaceRef<'tcx>,
2309 span: Span,
2310 state: &BorrowckDomain,
2311 ) {
2312 let maybe_uninits = &state.uninits;
2344
2345 let mut shortest_uninit_seen = None;
2348 for prefix in this.prefixes(base, PrefixSet::Shallow) {
2349 let Some(mpi) = this.move_path_for_place(prefix) else { continue };
2350
2351 if maybe_uninits.contains(mpi) {
2352 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2352",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2352u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("check_parent_of_field updating shortest_uninit_seen from {0:?} to {1:?}",
shortest_uninit_seen, Some((prefix, mpi))) as &dyn Value))])
});
} else { ; }
};debug!(
2353 "check_parent_of_field updating shortest_uninit_seen from {:?} to {:?}",
2354 shortest_uninit_seen,
2355 Some((prefix, mpi))
2356 );
2357 shortest_uninit_seen = Some((prefix, mpi));
2358 } else {
2359 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2359",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2359u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("check_parent_of_field {0:?} is definitely initialized",
(prefix, mpi)) as &dyn Value))])
});
} else { ; }
};debug!("check_parent_of_field {:?} is definitely initialized", (prefix, mpi));
2360 }
2361 }
2362
2363 if let Some((prefix, mpi)) = shortest_uninit_seen {
2364 let tcx = this.infcx.tcx;
2370 if base.ty(this.body(), tcx).ty.is_union()
2371 && this.move_data.path_map[mpi].iter().any(|moi| {
2372 this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
2373 })
2374 {
2375 return;
2376 }
2377
2378 this.report_use_of_moved_or_uninitialized(
2379 location,
2380 InitializationRequiringAction::PartialAssignment,
2381 (prefix, base, span),
2382 mpi,
2383 );
2384
2385 this.used_mut.insert(base.local);
2389 }
2390 }
2391 }
2392
2393 fn check_access_permissions(
2397 &mut self,
2398 (place, span): (Place<'tcx>, Span),
2399 kind: ReadOrWrite,
2400 is_local_mutation_allowed: LocalMutationIsAllowed,
2401 state: &BorrowckDomain,
2402 location: Location,
2403 ) -> bool {
2404 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2404",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2404u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("check_access_permissions({0:?}, {1:?}, is_local_mutation_allowed: {2:?})",
place, kind, is_local_mutation_allowed) as &dyn Value))])
});
} else { ; }
};debug!(
2405 "check_access_permissions({:?}, {:?}, is_local_mutation_allowed: {:?})",
2406 place, kind, is_local_mutation_allowed
2407 );
2408
2409 let error_access;
2410 let the_place_err;
2411
2412 match kind {
2413 Reservation(WriteKind::MutableBorrow(BorrowKind::Mut { kind: mut_borrow_kind }))
2414 | Write(WriteKind::MutableBorrow(BorrowKind::Mut { kind: mut_borrow_kind })) => {
2415 let is_local_mutation_allowed = match mut_borrow_kind {
2416 MutBorrowKind::ClosureCapture => LocalMutationIsAllowed::Yes,
2420 MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow => {
2421 is_local_mutation_allowed
2422 }
2423 };
2424 match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
2425 Ok(root_place) => {
2426 self.add_used_mut(root_place, state);
2427 return false;
2428 }
2429 Err(place_err) => {
2430 error_access = AccessKind::MutableBorrow;
2431 the_place_err = place_err;
2432 }
2433 }
2434 }
2435 Reservation(WriteKind::Mutate) | Write(WriteKind::Mutate) => {
2436 match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
2437 Ok(root_place) => {
2438 self.add_used_mut(root_place, state);
2439 return false;
2440 }
2441 Err(place_err) => {
2442 error_access = AccessKind::Mutate;
2443 the_place_err = place_err;
2444 }
2445 }
2446 }
2447
2448 Reservation(
2449 WriteKind::Move
2450 | WriteKind::Replace
2451 | WriteKind::StorageDeadOrDrop
2452 | WriteKind::MutableBorrow(BorrowKind::Shared)
2453 | WriteKind::MutableBorrow(BorrowKind::Fake(_)),
2454 )
2455 | Write(
2456 WriteKind::Move
2457 | WriteKind::Replace
2458 | WriteKind::StorageDeadOrDrop
2459 | WriteKind::MutableBorrow(BorrowKind::Shared)
2460 | WriteKind::MutableBorrow(BorrowKind::Fake(_)),
2461 ) => {
2462 if self.is_mutable(place.as_ref(), is_local_mutation_allowed).is_err()
2463 && !self.has_buffered_diags()
2464 {
2465 self.dcx().span_delayed_bug(
2471 span,
2472 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Accessing `{0:?}` with the kind `{1:?}` shouldn\'t be possible",
place, kind))
})format!(
2473 "Accessing `{place:?}` with the kind `{kind:?}` shouldn't be possible",
2474 ),
2475 );
2476 }
2477 return false;
2478 }
2479 Activation(..) => {
2480 return false;
2482 }
2483 Read(
2484 ReadKind::Borrow(BorrowKind::Mut { .. } | BorrowKind::Shared | BorrowKind::Fake(_))
2485 | ReadKind::Copy,
2486 ) => {
2487 return false;
2489 }
2490 }
2491
2492 let previously_initialized = self.is_local_ever_initialized(place.local, state);
2497
2498 if let Some(init_index) = previously_initialized {
2500 if let (AccessKind::Mutate, Some(_)) = (error_access, place.as_local()) {
2501 let init = &self.move_data.inits[init_index];
2504 let assigned_span = init.span(self.body);
2505 self.report_illegal_reassignment((place, span), assigned_span, place);
2506 } else {
2507 self.report_mutability_error(place, span, the_place_err, error_access, location)
2508 }
2509 true
2510 } else {
2511 false
2512 }
2513 }
2514
2515 fn is_local_ever_initialized(&self, local: Local, state: &BorrowckDomain) -> Option<InitIndex> {
2516 let mpi = self.move_data.rev_lookup.find_local(local)?;
2517 let ii = &self.move_data.init_path_map[mpi];
2518 ii.into_iter().find(|&&index| state.ever_inits.contains(index)).copied()
2519 }
2520
2521 fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, state: &BorrowckDomain) {
2523 match root_place {
2524 RootPlace { place_local: local, place_projection: [], is_local_mutation_allowed } => {
2525 if is_local_mutation_allowed != LocalMutationIsAllowed::Yes
2529 && self.is_local_ever_initialized(local, state).is_some()
2530 {
2531 self.used_mut.insert(local);
2532 }
2533 }
2534 RootPlace {
2535 place_local: _,
2536 place_projection: _,
2537 is_local_mutation_allowed: LocalMutationIsAllowed::Yes,
2538 } => {}
2539 RootPlace {
2540 place_local,
2541 place_projection: place_projection @ [.., _],
2542 is_local_mutation_allowed: _,
2543 } => {
2544 if let Some(field) = self.is_upvar_field_projection(PlaceRef {
2545 local: place_local,
2546 projection: place_projection,
2547 }) {
2548 self.used_mut_upvars.push(field);
2549 }
2550 }
2551 }
2552 }
2553
2554 fn is_mutable(
2557 &self,
2558 place: PlaceRef<'tcx>,
2559 is_local_mutation_allowed: LocalMutationIsAllowed,
2560 ) -> Result<RootPlace<'tcx>, PlaceRef<'tcx>> {
2561 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2561",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2561u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("is_mutable: place={0:?}, is_local...={1:?}",
place, is_local_mutation_allowed) as &dyn Value))])
});
} else { ; }
};debug!("is_mutable: place={:?}, is_local...={:?}", place, is_local_mutation_allowed);
2562 match place.last_projection() {
2563 None => {
2564 let local = &self.body.local_decls[place.local];
2565 match local.mutability {
2566 Mutability::Not => match is_local_mutation_allowed {
2567 LocalMutationIsAllowed::Yes => Ok(RootPlace {
2568 place_local: place.local,
2569 place_projection: place.projection,
2570 is_local_mutation_allowed: LocalMutationIsAllowed::Yes,
2571 }),
2572 LocalMutationIsAllowed::ExceptUpvars => Ok(RootPlace {
2573 place_local: place.local,
2574 place_projection: place.projection,
2575 is_local_mutation_allowed: LocalMutationIsAllowed::ExceptUpvars,
2576 }),
2577 LocalMutationIsAllowed::No => Err(place),
2578 },
2579 Mutability::Mut => Ok(RootPlace {
2580 place_local: place.local,
2581 place_projection: place.projection,
2582 is_local_mutation_allowed,
2583 }),
2584 }
2585 }
2586 Some((place_base, elem)) => {
2587 match elem {
2588 ProjectionElem::Deref => {
2589 let base_ty = place_base.ty(self.body(), self.infcx.tcx).ty;
2590
2591 match base_ty.kind() {
2593 ty::Ref(_, _, mutbl) => {
2594 match mutbl {
2595 hir::Mutability::Not => Err(place),
2597 hir::Mutability::Mut => {
2600 let mode = match self.is_upvar_field_projection(place) {
2601 Some(field)
2602 if self.upvars[field.index()].is_by_ref() =>
2603 {
2604 is_local_mutation_allowed
2605 }
2606 _ => LocalMutationIsAllowed::Yes,
2607 };
2608
2609 self.is_mutable(place_base, mode)
2610 }
2611 }
2612 }
2613 ty::RawPtr(_, mutbl) => {
2614 match mutbl {
2615 hir::Mutability::Not => Err(place),
2617 hir::Mutability::Mut => Ok(RootPlace {
2620 place_local: place.local,
2621 place_projection: place.projection,
2622 is_local_mutation_allowed,
2623 }),
2624 }
2625 }
2626 _ if base_ty.is_box() => {
2628 self.is_mutable(place_base, is_local_mutation_allowed)
2629 }
2630 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("Deref of unexpected type: {0:?}",
base_ty))bug!("Deref of unexpected type: {:?}", base_ty),
2632 }
2633 }
2634 ProjectionElem::Field(FieldIdx::ZERO, _)
2637 if let Some(adt) =
2638 place_base.ty(self.body(), self.infcx.tcx).ty.ty_adt_def()
2639 && adt.is_pin()
2640 && self.infcx.tcx.features().pin_ergonomics() =>
2641 {
2642 self.is_mutable(place_base, is_local_mutation_allowed)
2643 }
2644 ProjectionElem::Field(..)
2647 | ProjectionElem::Index(..)
2648 | ProjectionElem::ConstantIndex { .. }
2649 | ProjectionElem::Subslice { .. }
2650 | ProjectionElem::OpaqueCast { .. }
2651 | ProjectionElem::Downcast(..)
2652 | ProjectionElem::UnwrapUnsafeBinder(_) => {
2653 let upvar_field_projection = self.is_upvar_field_projection(place);
2654 if let Some(field) = upvar_field_projection {
2655 let upvar = &self.upvars[field.index()];
2656 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/lib.rs:2656",
"rustc_borrowck", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2656u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::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!("is_mutable: upvar.mutability={0:?} local_mutation_is_allowed={1:?} place={2:?}, place_base={3:?}",
upvar, is_local_mutation_allowed, place, place_base) as
&dyn Value))])
});
} else { ; }
};debug!(
2657 "is_mutable: upvar.mutability={:?} local_mutation_is_allowed={:?} \
2658 place={:?}, place_base={:?}",
2659 upvar, is_local_mutation_allowed, place, place_base
2660 );
2661 match (upvar.mutability, is_local_mutation_allowed) {
2662 (
2663 Mutability::Not,
2664 LocalMutationIsAllowed::No
2665 | LocalMutationIsAllowed::ExceptUpvars,
2666 ) => Err(place),
2667 (Mutability::Not, LocalMutationIsAllowed::Yes)
2668 | (Mutability::Mut, _) => {
2669 let _ =
2688 self.is_mutable(place_base, is_local_mutation_allowed)?;
2689 Ok(RootPlace {
2690 place_local: place.local,
2691 place_projection: place.projection,
2692 is_local_mutation_allowed,
2693 })
2694 }
2695 }
2696 } else {
2697 self.is_mutable(place_base, is_local_mutation_allowed)
2698 }
2699 }
2700 }
2701 }
2702 }
2703 }
2704
2705 fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<FieldIdx> {
2710 path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body())
2711 }
2712
2713 fn dominators(&self) -> &Dominators<BasicBlock> {
2714 self.body.basic_blocks.dominators()
2716 }
2717
2718 fn lint_unused_mut(&self) {
2719 let tcx = self.infcx.tcx;
2720 let body = self.body;
2721 for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
2722 let local_decl = &body.local_decls[local];
2723 let ClearCrossCrate::Set(SourceScopeLocalData { lint_root, .. }) =
2724 body.source_scopes[local_decl.source_info.scope].local_data
2725 else {
2726 continue;
2727 };
2728
2729 if self.local_excluded_from_unused_mut_lint(local) {
2731 continue;
2732 }
2733
2734 let span = local_decl.source_info.span;
2735 if span.desugaring_kind().is_some() {
2736 continue;
2738 }
2739
2740 let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
2741
2742 tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
2743 }
2744 }
2745}
2746
2747enum Overlap {
2749 Arbitrary,
2755 EqualOrDisjoint,
2760 Disjoint,
2763}