Skip to content

Commit d1b4b45

Browse files
committed
some additional refactor
also, treat placeholders equal to params
1 parent 8a08020 commit d1b4b45

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

compiler/rustc_middle/src/ty/util.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_index::bit_set::GrowableBitSet;
1919
use rustc_macros::HashStable;
2020
use rustc_session::Limit;
2121
use rustc_span::sym;
22-
use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout};
22+
use rustc_target::abi::{Integer, IntegerType, Size};
2323
use rustc_target::spec::abi::Abi;
2424
use smallvec::SmallVec;
2525
use std::{fmt, iter};
@@ -1085,7 +1085,7 @@ impl<'tcx> Ty<'tcx> {
10851085
#[inline]
10861086
pub fn needs_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
10871087
// Avoid querying in simple cases.
1088-
match needs_drop_components(self, &tcx.data_layout) {
1088+
match needs_drop_components(tcx, self) {
10891089
Err(AlwaysRequiresDrop) => true,
10901090
Ok(components) => {
10911091
let query_ty = match *components {
@@ -1118,7 +1118,7 @@ impl<'tcx> Ty<'tcx> {
11181118
#[inline]
11191119
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
11201120
// Avoid querying in simple cases.
1121-
match needs_drop_components(self, &tcx.data_layout) {
1121+
match needs_drop_components(tcx, self) {
11221122
Err(AlwaysRequiresDrop) => true,
11231123
Ok(components) => {
11241124
let query_ty = match *components {
@@ -1278,10 +1278,10 @@ impl<'tcx> ExplicitSelf<'tcx> {
12781278
/// *any* of the returned types need drop. Returns `Err(AlwaysRequiresDrop)` if
12791279
/// this type always needs drop.
12801280
pub fn needs_drop_components<'tcx>(
1281+
tcx: TyCtxt<'tcx>,
12811282
ty: Ty<'tcx>,
1282-
target_layout: &TargetDataLayout,
12831283
) -> Result<SmallVec<[Ty<'tcx>; 2]>, AlwaysRequiresDrop> {
1284-
match ty.kind() {
1284+
match *ty.kind() {
12851285
ty::Infer(ty::FreshIntTy(_))
12861286
| ty::Infer(ty::FreshFloatTy(_))
12871287
| ty::Bool
@@ -1303,11 +1303,11 @@ pub fn needs_drop_components<'tcx>(
13031303

13041304
ty::Dynamic(..) | ty::Error(_) => Err(AlwaysRequiresDrop),
13051305

1306-
ty::Slice(ty) => needs_drop_components(*ty, target_layout),
1306+
ty::Slice(ty) => needs_drop_components(tcx, ty),
13071307
ty::Array(elem_ty, size) => {
1308-
match needs_drop_components(*elem_ty, target_layout) {
1308+
match needs_drop_components(tcx, elem_ty) {
13091309
Ok(v) if v.is_empty() => Ok(v),
1310-
res => match size.try_to_bits(target_layout.pointer_size) {
1310+
res => match size.try_to_target_usize(tcx) {
13111311
// Arrays of size zero don't need drop, even if their element
13121312
// type does.
13131313
Some(0) => Ok(SmallVec::new()),
@@ -1321,7 +1321,7 @@ pub fn needs_drop_components<'tcx>(
13211321
}
13221322
// If any field needs drop, then the whole tuple does.
13231323
ty::Tuple(fields) => fields.iter().try_fold(SmallVec::new(), move |mut acc, elem| {
1324-
acc.extend(needs_drop_components(elem, target_layout)?);
1324+
acc.extend(needs_drop_components(tcx, elem)?);
13251325
Ok(acc)
13261326
}),
13271327

compiler/rustc_ty_utils/src/needs_drop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
return Some(Err(AlwaysRequiresDrop));
9797
}
9898

99-
let components = match needs_drop_components(ty, &tcx.data_layout) {
99+
let components = match needs_drop_components(tcx, ty) {
100100
Err(e) => return Some(Err(e)),
101101
Ok(components) => components,
102102
};
@@ -160,7 +160,7 @@ where
160160
queue_type(self, required);
161161
}
162162
}
163-
ty::Array(..) | ty::Alias(..) | ty::Param(_) => {
163+
ty::Alias(..) | ty::Array(..) | ty::Placeholder(_) | ty::Param(_) => {
164164
if ty == component {
165165
// Return the type to the caller: they may be able
166166
// to normalize further than we can.
@@ -173,7 +173,7 @@ where
173173
}
174174
}
175175

176-
ty::Foreign(_) | ty::Dynamic(..) | ty::Placeholder(_) => {
176+
ty::Foreign(_) | ty::Dynamic(..) => {
177177
return Some(Err(AlwaysRequiresDrop));
178178
}
179179

0 commit comments

Comments
 (0)