some additional refactor
also, treat placeholders equal to params
This commit is contained in:
parent
8a0802089c
commit
d1b4b458c0
@ -19,7 +19,7 @@ use rustc_index::bit_set::GrowableBitSet;
|
|||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_session::Limit;
|
use rustc_session::Limit;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout};
|
use rustc_target::abi::{Integer, IntegerType, Size};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{fmt, iter};
|
use std::{fmt, iter};
|
||||||
@ -1085,7 +1085,7 @@ impl<'tcx> Ty<'tcx> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn needs_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
|
pub fn needs_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
|
||||||
// Avoid querying in simple cases.
|
// Avoid querying in simple cases.
|
||||||
match needs_drop_components(self, &tcx.data_layout) {
|
match needs_drop_components(tcx, self) {
|
||||||
Err(AlwaysRequiresDrop) => true,
|
Err(AlwaysRequiresDrop) => true,
|
||||||
Ok(components) => {
|
Ok(components) => {
|
||||||
let query_ty = match *components {
|
let query_ty = match *components {
|
||||||
@ -1118,7 +1118,7 @@ impl<'tcx> Ty<'tcx> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
|
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
|
||||||
// Avoid querying in simple cases.
|
// Avoid querying in simple cases.
|
||||||
match needs_drop_components(self, &tcx.data_layout) {
|
match needs_drop_components(tcx, self) {
|
||||||
Err(AlwaysRequiresDrop) => true,
|
Err(AlwaysRequiresDrop) => true,
|
||||||
Ok(components) => {
|
Ok(components) => {
|
||||||
let query_ty = match *components {
|
let query_ty = match *components {
|
||||||
@ -1278,10 +1278,10 @@ impl<'tcx> ExplicitSelf<'tcx> {
|
|||||||
/// *any* of the returned types need drop. Returns `Err(AlwaysRequiresDrop)` if
|
/// *any* of the returned types need drop. Returns `Err(AlwaysRequiresDrop)` if
|
||||||
/// this type always needs drop.
|
/// this type always needs drop.
|
||||||
pub fn needs_drop_components<'tcx>(
|
pub fn needs_drop_components<'tcx>(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
target_layout: &TargetDataLayout,
|
|
||||||
) -> Result<SmallVec<[Ty<'tcx>; 2]>, AlwaysRequiresDrop> {
|
) -> Result<SmallVec<[Ty<'tcx>; 2]>, AlwaysRequiresDrop> {
|
||||||
match ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Infer(ty::FreshIntTy(_))
|
ty::Infer(ty::FreshIntTy(_))
|
||||||
| ty::Infer(ty::FreshFloatTy(_))
|
| ty::Infer(ty::FreshFloatTy(_))
|
||||||
| ty::Bool
|
| ty::Bool
|
||||||
@ -1303,11 +1303,11 @@ pub fn needs_drop_components<'tcx>(
|
|||||||
|
|
||||||
ty::Dynamic(..) | ty::Error(_) => Err(AlwaysRequiresDrop),
|
ty::Dynamic(..) | ty::Error(_) => Err(AlwaysRequiresDrop),
|
||||||
|
|
||||||
ty::Slice(ty) => needs_drop_components(*ty, target_layout),
|
ty::Slice(ty) => needs_drop_components(tcx, ty),
|
||||||
ty::Array(elem_ty, size) => {
|
ty::Array(elem_ty, size) => {
|
||||||
match needs_drop_components(*elem_ty, target_layout) {
|
match needs_drop_components(tcx, elem_ty) {
|
||||||
Ok(v) if v.is_empty() => Ok(v),
|
Ok(v) if v.is_empty() => Ok(v),
|
||||||
res => match size.try_to_bits(target_layout.pointer_size) {
|
res => match size.try_to_target_usize(tcx) {
|
||||||
// Arrays of size zero don't need drop, even if their element
|
// Arrays of size zero don't need drop, even if their element
|
||||||
// type does.
|
// type does.
|
||||||
Some(0) => Ok(SmallVec::new()),
|
Some(0) => Ok(SmallVec::new()),
|
||||||
@ -1321,7 +1321,7 @@ pub fn needs_drop_components<'tcx>(
|
|||||||
}
|
}
|
||||||
// If any field needs drop, then the whole tuple does.
|
// If any field needs drop, then the whole tuple does.
|
||||||
ty::Tuple(fields) => fields.iter().try_fold(SmallVec::new(), move |mut acc, elem| {
|
ty::Tuple(fields) => fields.iter().try_fold(SmallVec::new(), move |mut acc, elem| {
|
||||||
acc.extend(needs_drop_components(elem, target_layout)?);
|
acc.extend(needs_drop_components(tcx, elem)?);
|
||||||
Ok(acc)
|
Ok(acc)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ where
|
|||||||
return Some(Err(AlwaysRequiresDrop));
|
return Some(Err(AlwaysRequiresDrop));
|
||||||
}
|
}
|
||||||
|
|
||||||
let components = match needs_drop_components(ty, &tcx.data_layout) {
|
let components = match needs_drop_components(tcx, ty) {
|
||||||
Err(e) => return Some(Err(e)),
|
Err(e) => return Some(Err(e)),
|
||||||
Ok(components) => components,
|
Ok(components) => components,
|
||||||
};
|
};
|
||||||
@ -160,7 +160,7 @@ where
|
|||||||
queue_type(self, required);
|
queue_type(self, required);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::Array(..) | ty::Alias(..) | ty::Param(_) => {
|
ty::Alias(..) | ty::Array(..) | ty::Placeholder(_) | ty::Param(_) => {
|
||||||
if ty == component {
|
if ty == component {
|
||||||
// Return the type to the caller: they may be able
|
// Return the type to the caller: they may be able
|
||||||
// to normalize further than we can.
|
// to normalize further than we can.
|
||||||
@ -173,7 +173,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Foreign(_) | ty::Dynamic(..) | ty::Placeholder(_) => {
|
ty::Foreign(_) | ty::Dynamic(..) => {
|
||||||
return Some(Err(AlwaysRequiresDrop));
|
return Some(Err(AlwaysRequiresDrop));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user