Skip to content

Commit

Permalink
Use new boxed_ty to replace is_box + old boxed_ty
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Sep 9, 2024
1 parent 001b4f6 commit 059fb9b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/monomorphize_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,11 @@ pub fn find_vtable_types_for_unsizing<'tcx>(
match (&source_ty.kind(), &target_ty.kind()) {
(&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(b, _))
| (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => ptr_vtable(*a, *b),
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
ptr_vtable(source_ty.boxed_ty(), target_ty.boxed_ty())
(_, _)
if let Some(source_boxed) = source_ty.boxed_ty()
&& let Some(target_boxed) = target_ty.boxed_ty() =>
{
ptr_vtable(source_boxed, target_boxed)
}

// T as dyn* Trait
Expand Down
4 changes: 2 additions & 2 deletions src/preempt_count/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ memoize!(
return Ok(adj);
}

ty::Adt(def, args) if def.is_box() => {
let adj = cx.drop_adjustment(param_env.and(args.type_at(0)))?;
_ if let Some(boxed_ty) = ty.boxed_ty() => {
let adj = cx.drop_adjustment(param_env.and(boxed_ty))?;
let drop_trait = cx.require_lang_item(LangItem::Drop, None);
let drop_fn = cx.associated_item_def_ids(drop_trait)[0];
let box_free =
Expand Down
4 changes: 2 additions & 2 deletions src/preempt_count/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ memoize!(
return Ok(());
}

ty::Adt(def, args) if def.is_box() => {
cx.drop_check(param_env.and(args.type_at(0)))?;
_ if let Some(boxed_ty) = ty.boxed_ty() => {
cx.drop_check(param_env.and(boxed_ty))?;
let drop_trait = cx.require_lang_item(LangItem::Drop, None);
let drop_fn = cx.associated_item_def_ids(drop_trait)[0];
let box_free =
Expand Down
23 changes: 9 additions & 14 deletions src/preempt_count/expectation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,13 @@ impl<'tcx> AnalysisCtxt<'tcx> {

ty::Tuple(_list) => (),

ty::Adt(def, args) if def.is_box() => {
let exp = self.drop_expectation(param_env.and(args.type_at(0)))?;
_ if let Some(boxed_ty) = ty.boxed_ty() => {
let exp = self.drop_expectation(param_env.and(boxed_ty))?;
if !exp.contains_range(expected) {
return self.report_drop_expectation_error(
param_env,
args.type_at(0),
expected,
span,
diag,
);
return self
.report_drop_expectation_error(param_env, boxed_ty, expected, span, diag);
}
let adj = self.drop_adjustment(param_env.and(args.type_at(0)))?;
let adj = self.drop_adjustment(param_env.and(boxed_ty))?;

let drop_trait = self.require_lang_item(LangItem::Drop, None);
let drop_fn = self.associated_item_def_ids(drop_trait)[0];
Expand Down Expand Up @@ -675,8 +670,8 @@ memoize!(

ty::Tuple(_list) => (),

ty::Adt(def, args) if def.is_box() => {
let exp = cx.drop_expectation(param_env.and(args.type_at(0)))?;
_ if let Some(boxed_ty) = ty.boxed_ty() => {
let exp = cx.drop_expectation(param_env.and(boxed_ty))?;
let drop_trait = cx.require_lang_item(LangItem::Drop, None);
let drop_fn = cx.associated_item_def_ids(drop_trait)[0];
let box_free =
Expand All @@ -690,7 +685,7 @@ memoize!(
return Ok(exp);
}

let adj = cx.drop_adjustment(param_env.and(args.type_at(0)))?;
let adj = cx.drop_adjustment(param_env.and(boxed_ty))?;
let adj_bound = AdjustmentBounds::single_value(adj);

let mut expected = box_free_exp - adj_bound;
Expand All @@ -704,7 +699,7 @@ memoize!(
"but the possible preemption count after dropping the content is {}",
exp + adj_bound
));
diag.note(format!("content being dropped is `{}`", args.type_at(0)));
diag.note(format!("content being dropped is `{}`", boxed_ty));
return Err(Error::Error(cx.emit_with_use_site_info(diag)));
}

Expand Down

0 comments on commit 059fb9b

Please sign in to comment.