Make is_block_tail a variant of LocalInfo.
This commit is contained in:
parent
bcb161def7
commit
d31386a52b
6 changed files with 26 additions and 39 deletions
|
@ -6,8 +6,8 @@ use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
Body, CastKind, ConstraintCategory, FakeReadCause, Local, Location, Operand, Place, Rvalue,
|
Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place,
|
||||||
Statement, StatementKind, TerminatorKind,
|
Rvalue, Statement, StatementKind, TerminatorKind,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::adjustment::PointerCast;
|
use rustc_middle::ty::adjustment::PointerCast;
|
||||||
use rustc_middle::ty::{self, RegionVid, TyCtxt};
|
use rustc_middle::ty::{self, RegionVid, TyCtxt};
|
||||||
|
@ -220,7 +220,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||||
);
|
);
|
||||||
err.span_label(body.source_info(drop_loc).span, message);
|
err.span_label(body.source_info(drop_loc).span, message);
|
||||||
|
|
||||||
if let Some(info) = &local_decl.is_block_tail {
|
if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
|
||||||
if info.tail_result_is_ignored {
|
if info.tail_result_is_ignored {
|
||||||
// #85581: If the first mutable borrow's scope contains
|
// #85581: If the first mutable borrow's scope contains
|
||||||
// the second borrow, this suggestion isn't helpful.
|
// the second borrow, this suggestion isn't helpful.
|
||||||
|
|
|
@ -785,13 +785,6 @@ pub struct LocalDecl<'tcx> {
|
||||||
/// generator.
|
/// generator.
|
||||||
pub internal: bool,
|
pub internal: bool,
|
||||||
|
|
||||||
/// If this local is a temporary and `is_block_tail` is `Some`,
|
|
||||||
/// then it is a temporary created for evaluation of some
|
|
||||||
/// subexpression of some block's tail expression (with no
|
|
||||||
/// intervening statement context).
|
|
||||||
// FIXME(matthewjasper) Don't store in this in `Body`
|
|
||||||
pub is_block_tail: Option<BlockTailInfo>,
|
|
||||||
|
|
||||||
/// The type of this local.
|
/// The type of this local.
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
|
|
||||||
|
@ -905,6 +898,10 @@ pub enum LocalInfo<'tcx> {
|
||||||
/// A temporary created during the creation of an aggregate
|
/// A temporary created during the creation of an aggregate
|
||||||
/// (e.g. a temporary for `foo` in `MyStruct { my_field: foo }`)
|
/// (e.g. a temporary for `foo` in `MyStruct { my_field: foo }`)
|
||||||
AggregateTemp,
|
AggregateTemp,
|
||||||
|
/// A temporary created for evaluation of some subexpression of some block's tail expression
|
||||||
|
/// (with no intervening statement context).
|
||||||
|
// FIXME(matthewjasper) Don't store in this in `Body`
|
||||||
|
BlockTailTemp(BlockTailInfo),
|
||||||
/// A temporary created during the pass `Derefer` to avoid it's retagging
|
/// A temporary created during the pass `Derefer` to avoid it's retagging
|
||||||
DerefTemp,
|
DerefTemp,
|
||||||
/// A temporary created for borrow checking.
|
/// A temporary created for borrow checking.
|
||||||
|
@ -1018,7 +1015,6 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
mutability: Mutability::Mut,
|
mutability: Mutability::Mut,
|
||||||
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::Boring)),
|
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::Boring)),
|
||||||
internal: false,
|
internal: false,
|
||||||
is_block_tail: None,
|
|
||||||
ty,
|
ty,
|
||||||
user_ty: None,
|
user_ty: None,
|
||||||
source_info,
|
source_info,
|
||||||
|
@ -1038,14 +1034,6 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
self.mutability = Mutability::Not;
|
self.mutability = Mutability::Not;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts `self` into same `LocalDecl` except tagged as internal temporary.
|
|
||||||
#[inline]
|
|
||||||
pub fn block_tail(mut self, info: BlockTailInfo) -> Self {
|
|
||||||
assert!(self.is_block_tail.is_none());
|
|
||||||
self.is_block_tail = Some(info);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||||
|
@ -3106,7 +3094,7 @@ mod size_asserts {
|
||||||
use rustc_data_structures::static_assert_size;
|
use rustc_data_structures::static_assert_size;
|
||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
static_assert_size!(BasicBlockData<'_>, 144);
|
static_assert_size!(BasicBlockData<'_>, 144);
|
||||||
static_assert_size!(LocalDecl<'_>, 56);
|
static_assert_size!(LocalDecl<'_>, 40);
|
||||||
static_assert_size!(Statement<'_>, 32);
|
static_assert_size!(Statement<'_>, 32);
|
||||||
static_assert_size!(StatementKind<'_>, 16);
|
static_assert_size!(StatementKind<'_>, 16);
|
||||||
static_assert_size!(Terminator<'_>, 112);
|
static_assert_size!(Terminator<'_>, 112);
|
||||||
|
|
|
@ -804,7 +804,6 @@ macro_rules! make_mir_visitor {
|
||||||
source_info,
|
source_info,
|
||||||
internal: _,
|
internal: _,
|
||||||
local_info: _,
|
local_info: _,
|
||||||
is_block_tail: _,
|
|
||||||
} = local_decl;
|
} = local_decl;
|
||||||
|
|
||||||
self.visit_ty($(& $mutability)? *ty, TyContext::LocalDecl {
|
self.visit_ty($(& $mutability)? *ty, TyContext::LocalDecl {
|
||||||
|
|
|
@ -124,9 +124,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
Category::Constant | Category::Place | Category::Rvalue(..) => {
|
Category::Constant | Category::Place | Category::Rvalue(..) => {
|
||||||
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
|
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
|
||||||
let decl_info = this.local_decls[operand].local_info.as_mut().assert_crate_local();
|
// Overwrite temp local info if we have something more interesting to record.
|
||||||
if let LocalInfo::Boring = **decl_info {
|
if !matches!(local_info, LocalInfo::Boring) {
|
||||||
**decl_info = local_info;
|
let decl_info = this.local_decls[operand].local_info.as_mut().assert_crate_local();
|
||||||
|
if let LocalInfo::Boring | LocalInfo::BlockTailTemp(_) = **decl_info {
|
||||||
|
**decl_info = local_info;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
block.and(Operand::Move(Place::from(operand)))
|
block.and(Operand::Move(Place::from(operand)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,29 +49,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("creating temp {:?} with block_context: {:?}", local_decl, this.block_context);
|
debug!("creating temp {:?} with block_context: {:?}", local_decl, this.block_context);
|
||||||
// Find out whether this temp is being created within the
|
let local_info = match expr.kind {
|
||||||
// tail expression of a block whose result is ignored.
|
|
||||||
if let Some(tail_info) = this.block_context.currently_in_block_tail() {
|
|
||||||
local_decl = local_decl.block_tail(tail_info);
|
|
||||||
}
|
|
||||||
match expr.kind {
|
|
||||||
ExprKind::StaticRef { def_id, .. } => {
|
ExprKind::StaticRef { def_id, .. } => {
|
||||||
assert!(!this.tcx.is_thread_local_static(def_id));
|
assert!(!this.tcx.is_thread_local_static(def_id));
|
||||||
local_decl.internal = true;
|
local_decl.internal = true;
|
||||||
**local_decl.local_info.as_mut().assert_crate_local() =
|
LocalInfo::StaticRef { def_id, is_thread_local: false }
|
||||||
LocalInfo::StaticRef { def_id, is_thread_local: false };
|
|
||||||
}
|
}
|
||||||
ExprKind::ThreadLocalRef(def_id) => {
|
ExprKind::ThreadLocalRef(def_id) => {
|
||||||
assert!(this.tcx.is_thread_local_static(def_id));
|
assert!(this.tcx.is_thread_local_static(def_id));
|
||||||
local_decl.internal = true;
|
local_decl.internal = true;
|
||||||
**local_decl.local_info.as_mut().assert_crate_local() =
|
LocalInfo::StaticRef { def_id, is_thread_local: true }
|
||||||
LocalInfo::StaticRef { def_id, is_thread_local: true };
|
|
||||||
}
|
}
|
||||||
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {
|
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {
|
||||||
**local_decl.local_info.as_mut().assert_crate_local() = LocalInfo::ConstRef { def_id };
|
LocalInfo::ConstRef { def_id }
|
||||||
}
|
}
|
||||||
_ => {}
|
// Find out whether this temp is being created within the
|
||||||
}
|
// tail expression of a block whose result is ignored.
|
||||||
|
_ if let Some(tail_info) = this.block_context.currently_in_block_tail() => {
|
||||||
|
LocalInfo::BlockTailTemp(tail_info)
|
||||||
|
}
|
||||||
|
_ => LocalInfo::Boring,
|
||||||
|
};
|
||||||
|
**local_decl.local_info.as_mut().assert_crate_local() = local_info;
|
||||||
this.local_decls.push(local_decl)
|
this.local_decls.push(local_decl)
|
||||||
};
|
};
|
||||||
let temp_place = Place::from(temp);
|
let temp_place = Place::from(temp);
|
||||||
|
|
|
@ -2224,7 +2224,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) },
|
user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) },
|
||||||
source_info,
|
source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_block_tail: None,
|
|
||||||
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var(
|
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var(
|
||||||
VarBindingForm {
|
VarBindingForm {
|
||||||
binding_mode,
|
binding_mode,
|
||||||
|
@ -2253,7 +2252,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
user_ty: None,
|
user_ty: None,
|
||||||
source_info,
|
source_info,
|
||||||
internal: false,
|
internal: false,
|
||||||
is_block_tail: None,
|
|
||||||
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::RefForGuard))),
|
local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::RefForGuard))),
|
||||||
});
|
});
|
||||||
self.var_debug_info.push(VarDebugInfo {
|
self.var_debug_info.push(VarDebugInfo {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue