Remove the explicit box_free type check
Because box_free is now passed a pointer instead of a Box, we can stop relying on TypeChecked::check_box_free_inputs, because TypeChecker::check_call_inputs should be enough, like for all other function calls. It seems it was not actually reached anyways in cases where it would have made a difference. (issue #50071)
This commit is contained in:
parent
43b24c6c83
commit
dfa611146c
1 changed files with 1 additions and 69 deletions
|
|
@ -918,11 +918,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
));
|
||||
}
|
||||
|
||||
if self.is_box_free(func) {
|
||||
self.check_box_free_inputs(mir, term, &sig, args, term_location);
|
||||
} else {
|
||||
self.check_call_inputs(mir, term, &sig, args, term_location);
|
||||
}
|
||||
self.check_call_inputs(mir, term, &sig, args, term_location);
|
||||
}
|
||||
TerminatorKind::Assert {
|
||||
ref cond, ref msg, ..
|
||||
|
|
@ -1026,70 +1022,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_box_free(&self, operand: &Operand<'tcx>) -> bool {
|
||||
match *operand {
|
||||
Operand::Constant(ref c) => match c.ty.sty {
|
||||
ty::TyFnDef(ty_def_id, _) => {
|
||||
Some(ty_def_id) == self.tcx().lang_items().box_free_fn()
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn check_box_free_inputs(
|
||||
&mut self,
|
||||
mir: &Mir<'tcx>,
|
||||
term: &Terminator<'tcx>,
|
||||
sig: &ty::FnSig<'tcx>,
|
||||
args: &[Operand<'tcx>],
|
||||
term_location: Location,
|
||||
) {
|
||||
debug!("check_box_free_inputs");
|
||||
|
||||
// box_free takes a Box as a pointer. Allow for that.
|
||||
|
||||
if sig.inputs().len() != 1 {
|
||||
span_mirbug!(self, term, "box_free should take 1 argument");
|
||||
return;
|
||||
}
|
||||
|
||||
let pointee_ty = match sig.inputs()[0].sty {
|
||||
ty::TyRawPtr(mt) => mt.ty,
|
||||
_ => {
|
||||
span_mirbug!(self, term, "box_free should take a raw ptr");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if args.len() != 1 {
|
||||
span_mirbug!(self, term, "box_free called with wrong # of args");
|
||||
return;
|
||||
}
|
||||
|
||||
let ty = args[0].ty(mir, self.tcx());
|
||||
let arg_ty = match ty.sty {
|
||||
ty::TyRawPtr(mt) => mt.ty,
|
||||
ty::TyAdt(def, _) if def.is_box() => ty.boxed_ty(),
|
||||
_ => {
|
||||
span_mirbug!(self, term, "box_free called with bad arg ty");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(terr) = self.sub_types(arg_ty, pointee_ty, term_location.at_self()) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
term,
|
||||
"bad box_free arg ({:?} <- {:?}): {:?}",
|
||||
pointee_ty,
|
||||
arg_ty,
|
||||
terr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_iscleanup(&mut self, mir: &Mir<'tcx>, block_data: &BasicBlockData<'tcx>) {
|
||||
let is_cleanup = block_data.is_cleanup;
|
||||
self.last_span = block_data.terminator().source_info.span;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue