Add docs, remove code, change subtyper code
This commit is contained in:
parent
3148e6a993
commit
cd7f471931
24 changed files with 106 additions and 363 deletions
|
@ -16,6 +16,8 @@ use rustc_target::spec::abi::Abi;
|
|||
|
||||
use crate::util::is_within_packed;
|
||||
|
||||
use crate::util::is_subtype;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
enum EdgeKind {
|
||||
Unwind,
|
||||
|
@ -602,35 +604,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
return true;
|
||||
}
|
||||
|
||||
crate::util::is_subtype(self.tcx, self.param_env, src, dest)
|
||||
return crate::util::is_subtype(self.tcx, self.param_env, src, dest);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
|
||||
match operand {
|
||||
Operand::Copy(place) | Operand::Move(place) => {
|
||||
if let Some(stmt) = self.body.stmt_at(location).left() {
|
||||
match &stmt.kind {
|
||||
StatementKind::Assign(box (lval, rvalue)) => {
|
||||
let place_ty = place.ty(&self.body.local_decls, self.tcx).ty;
|
||||
let lval_ty = lval.ty(&self.body.local_decls, self.tcx).ty;
|
||||
|
||||
if !place.is_subtype()
|
||||
&& place_ty != lval_ty
|
||||
&& rvalue.ty(&self.body.local_decls, self.tcx) != lval_ty
|
||||
&& (rvalue.ty(&self.body.local_decls, self.tcx).is_closure()
|
||||
!= lval_ty.is_closure())
|
||||
{
|
||||
self.fail(location, format!("Subtyping is not allowed between types {place_ty:#?} and {lval_ty:#?}"))
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
// This check is somewhat expensive, so only run it when -Zvalidate-mir is passed.
|
||||
if self.tcx.sess.opts.unstable_opts.validate_mir
|
||||
&& self.mir_phase < MirPhase::Runtime(RuntimePhase::Initial)
|
||||
|
@ -776,6 +755,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ProjectionElem::Subtype(ty) => {
|
||||
if !is_subtype(
|
||||
self.tcx,
|
||||
self.param_env,
|
||||
ty,
|
||||
place_ref.ty(&self.body.local_decls, self.tcx).ty,
|
||||
) {
|
||||
self.fail(
|
||||
location,
|
||||
format!(
|
||||
"Failed subtyping {ty:#?} and {:#?}",
|
||||
place_ref.ty(&self.body.local_decls, self.tcx).ty
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.super_projection_elem(place_ref, elem, context, location);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue