X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_borrowck%2Fsrc%2Ftype_check%2Fmod.rs;h=e5aed1b60ddc1fe56a3e9b451346315ea1077246;hb=fafccdced349d655db83e0ec30e91b85dcf65cf7;hp=34bc87b20c79a4316bfa097fac2df65fe273d710;hpb=f33601e753613a91bfadce0a5086bcd1cb60934e;p=rust.git diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 34bc87b20c7..e5aed1b60dd 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -162,6 +162,8 @@ pub(crate) fn type_check<'mir, 'tcx>( &mut constraints, ); + debug!(?normalized_inputs_and_output); + for u in ty::UniverseIndex::ROOT..infcx.universe() { let info = UniverseInfo::other(); constraints.universe_causes.insert(u, info); @@ -185,6 +187,7 @@ pub(crate) fn type_check<'mir, 'tcx>( implicit_region_bound, &mut borrowck_context, |mut cx| { + debug!("inside extra closure of type_check_internal"); cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output); liveness::generate( &mut cx, @@ -257,6 +260,7 @@ fn type_check_internal<'a, 'tcx, R>( borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, extra: impl FnOnce(TypeChecker<'a, 'tcx>) -> R, ) -> R { + debug!("body: {:#?}", body); let mut checker = TypeChecker::new( infcx, body, @@ -935,7 +939,7 @@ pub(crate) struct MirTypeckRegionConstraints<'tcx> { pub(crate) member_constraints: MemberConstraintSet<'tcx, RegionVid>, pub(crate) closure_bounds_mapping: - FxHashMap>, + FxHashMap, Span)>>, pub(crate) universe_causes: FxHashMap>, @@ -1125,7 +1129,7 @@ fn check_user_type_annotations(&mut self) { fn push_region_constraints( &mut self, locations: Locations, - category: ConstraintCategory, + category: ConstraintCategory<'tcx>, data: &QueryRegionConstraints<'tcx>, ) { debug!("constraints generated: {:#?}", data); @@ -1150,7 +1154,7 @@ fn sub_types( sub: Ty<'tcx>, sup: Ty<'tcx>, locations: Locations, - category: ConstraintCategory, + category: ConstraintCategory<'tcx>, ) -> Fallible<()> { // Use this order of parameters because the sup type is usually the // "expected" type in diagnostics. @@ -1163,7 +1167,7 @@ fn eq_types( expected: Ty<'tcx>, found: Ty<'tcx>, locations: Locations, - category: ConstraintCategory, + category: ConstraintCategory<'tcx>, ) -> Fallible<()> { self.relate_types(expected, ty::Variance::Invariant, found, locations, category) } @@ -1175,7 +1179,7 @@ fn relate_type_and_user_type( v: ty::Variance, user_ty: &UserTypeProjection, locations: Locations, - category: ConstraintCategory, + category: ConstraintCategory<'tcx>, ) -> Fallible<()> { let annotated_type = self.user_type_annotations[user_ty.base].inferred_ty; let mut curr_projected_ty = PlaceTy::from_ty(annotated_type); @@ -1212,6 +1216,7 @@ fn tcx(&self) -> TyCtxt<'tcx> { #[instrument(skip(self, body, location), level = "debug")] fn check_stmt(&mut self, body: &Body<'tcx>, stmt: &Statement<'tcx>, location: Location) { let tcx = self.tcx(); + debug!("stmt kind: {:?}", stmt.kind); match stmt.kind { StatementKind::Assign(box (ref place, ref rv)) => { // Assignments to temporaries are not "interesting"; @@ -1251,9 +1256,13 @@ fn check_stmt(&mut self, body: &Body<'tcx>, stmt: &Statement<'tcx>, location: Lo ); let place_ty = place.ty(body, tcx).ty; + debug!(?place_ty); let place_ty = self.normalize(place_ty, location); + debug!("place_ty normalized: {:?}", place_ty); let rv_ty = rv.ty(body, tcx); + debug!(?rv_ty); let rv_ty = self.normalize(rv_ty, location); + debug!("normalized rv_ty: {:?}", rv_ty); if let Err(terr) = self.sub_types(rv_ty, place_ty, location.to_locations(), category) { @@ -1347,6 +1356,7 @@ fn check_terminator( term_location: Location, ) { let tcx = self.tcx(); + debug!("terminator kind: {:?}", term.kind); match term.kind { TerminatorKind::Goto { .. } | TerminatorKind::Resume @@ -1404,7 +1414,12 @@ fn check_terminator( // FIXME: check the values } TerminatorKind::Call { - ref func, ref args, destination, target, from_hir_call, .. + ref func, + ref args, + ref destination, + from_hir_call, + target, + .. } => { self.check_operand(func, term_location); for arg in args { @@ -1412,7 +1427,8 @@ fn check_terminator( } let func_ty = func.ty(body, tcx); - debug!("check_terminator: call, func_ty={:?}", func_ty); + debug!("func_ty.kind: {:?}", func_ty.kind()); + let sig = match func_ty.kind() { ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx), _ => { @@ -1425,8 +1441,9 @@ fn check_terminator( LateBoundRegionConversionTime::FnCall, sig, ); + debug!(?sig); let sig = self.normalize(sig, term_location); - self.check_call_dest(body, term, &sig, destination, target, term_location); + self.check_call_dest(body, term, &sig, *destination, target, term_location); self.prove_predicates( sig.inputs_and_output @@ -1585,11 +1602,20 @@ fn check_call_inputs( if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic) { span_mirbug!(self, term, "call to {:?} with wrong # of args", sig); } + + let func_ty = if let TerminatorKind::Call { func, .. } = &term.kind { + Some(func.ty(body, self.infcx.tcx)) + } else { + None + }; + debug!(?func_ty); + for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() { let op_arg_ty = op_arg.ty(body, self.tcx()); + let op_arg_ty = self.normalize(op_arg_ty, term_location); let category = if from_hir_call { - ConstraintCategory::CallArgument + ConstraintCategory::CallArgument(func_ty) } else { ConstraintCategory::Boring }; @@ -1841,6 +1867,7 @@ fn check_operand(&mut self, op: &Operand<'tcx>, location: Location) { } } + #[instrument(skip(self, body), level = "debug")] fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { let tcx = self.tcx(); @@ -2120,24 +2147,62 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L } } - CastKind::Misc => { + CastKind::PointerExposeAddress => { + let ty_from = op.ty(body, tcx); + let cast_ty_from = CastTy::from_ty(ty_from); + let cast_ty_to = CastTy::from_ty(*ty); + match (cast_ty_from, cast_ty_to) { + (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => (), + _ => { + span_mirbug!( + self, + rvalue, + "Invalid PointerExposeAddress cast {:?} -> {:?}", + ty_from, + ty + ) + } + } + } + + CastKind::PointerFromExposedAddress => { let ty_from = op.ty(body, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { - (None, _) - | (_, None | Some(CastTy::FnPtr)) - | (Some(CastTy::Float), Some(CastTy::Ptr(_))) - | (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Float)) => { - span_mirbug!(self, rvalue, "Invalid cast {:?} -> {:?}", ty_from, ty,) + (Some(CastTy::Int(_)), Some(CastTy::Ptr(_))) => (), + _ => { + span_mirbug!( + self, + rvalue, + "Invalid PointerFromExposedAddress cast {:?} -> {:?}", + ty_from, + ty + ) } + } + } + + CastKind::Misc => { + let ty_from = op.ty(body, tcx); + let cast_ty_from = CastTy::from_ty(ty_from); + let cast_ty_to = CastTy::from_ty(*ty); + // Misc casts are either between floats and ints, or one ptr type to another. + match (cast_ty_from, cast_ty_to) { ( - Some(CastTy::Int(_)), - Some(CastTy::Int(_) | CastTy::Float | CastTy::Ptr(_)), + Some(CastTy::Int(_) | CastTy::Float), + Some(CastTy::Int(_) | CastTy::Float), ) - | (Some(CastTy::Float), Some(CastTy::Int(_) | CastTy::Float)) - | (Some(CastTy::Ptr(_)), Some(CastTy::Int(_) | CastTy::Ptr(_))) - | (Some(CastTy::FnPtr), Some(CastTy::Int(_) | CastTy::Ptr(_))) => (), + | (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Ptr(_))) => (), + _ => { + span_mirbug!( + self, + rvalue, + "Invalid Misc cast {:?} -> {:?}", + ty_from, + ty, + ) + } } } }