Skip to content

Commit c52e51d

Browse files
committed
normalize types in ADT constructor
Fixes #45940
1 parent 10b8fac commit c52e51d

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed

src/librustc_mir/shim.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,16 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
825825
-> Mir<'tcx>
826826
{
827827
let tcx = infcx.tcx;
828+
let gcx = tcx.global_tcx();
828829
let def_id = tcx.hir.local_def_id(ctor_id);
829-
let sig = tcx.no_late_bound_regions(&tcx.fn_sig(def_id))
830+
let sig = gcx.no_late_bound_regions(&gcx.fn_sig(def_id))
830831
.expect("LBR in ADT constructor signature");
831-
let sig = tcx.erase_regions(&sig);
832+
let sig = gcx.erase_regions(&sig);
833+
let param_env = gcx.param_env(def_id);
834+
835+
// Normalize the sig now that we have liberated the late-bound
836+
// regions.
837+
let sig = gcx.normalize_associated_type_in_env(&sig, param_env);
832838

833839
let (adt_def, substs) = match sig.output().sty {
834840
ty::TyAdt(adt_def, substs) => (adt_def, substs),

src/librustc_mir/transform/nll/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn compute_regions<'a, 'gcx, 'tcx>(
4747

4848
// Run the MIR type-checker.
4949
let mir_node_id = infcx.tcx.hir.as_local_node_id(def_id).unwrap();
50-
let constraint_sets = &type_check::type_check(infcx, mir_node_id, param_env, mir, def_id);
50+
let constraint_sets = &type_check::type_check(infcx, mir_node_id, param_env, mir);
5151

5252
// Create the region inference context, taking ownership of the region inference
5353
// data that was contained in `infcx`.

src/librustc_mir/transform/type_check.rs

+3-29
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
//! This pass type-checks the MIR to ensure it is not broken.
1212
#![allow(unreachable_code)]
1313

14-
use rustc::hir::def_id::DefId;
15-
use rustc::hir::map::DefPathData;
1614
use rustc::infer::{InferCtxt, InferOk, InferResult, LateBoundRegionConversionTime, UnitResult};
1715
use rustc::infer::region_constraints::RegionConstraintData;
1816
use rustc::traits::{self, FulfillmentContext};
@@ -43,9 +41,8 @@ pub fn type_check<'a, 'gcx, 'tcx>(
4341
body_id: ast::NodeId,
4442
param_env: ty::ParamEnv<'gcx>,
4543
mir: &Mir<'tcx>,
46-
mir_def_id: DefId,
4744
) -> MirTypeckRegionConstraints<'tcx> {
48-
let mut checker = TypeChecker::new(infcx, body_id, param_env, mir_def_id);
45+
let mut checker = TypeChecker::new(infcx, body_id, param_env);
4946
let errors_reported = {
5047
let mut verifier = TypeVerifier::new(&mut checker, mir);
5148
verifier.visit_mir(mir);
@@ -411,11 +408,6 @@ pub struct TypeChecker<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
411408
body_id: ast::NodeId,
412409
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
413410
constraints: MirTypeckRegionConstraints<'tcx>,
414-
415-
// FIXME(#45940) - True if this is a MIR shim or ADT constructor
416-
// (e.g., for a tuple struct.) In that case, the internal types of
417-
// operands and things require normalization.
418-
is_adt_constructor: bool,
419411
}
420412

421413
/// A collection of region constraints that must be satisfied for the
@@ -467,22 +459,14 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
467459
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
468460
body_id: ast::NodeId,
469461
param_env: ty::ParamEnv<'gcx>,
470-
mir_def_id: DefId,
471462
) -> Self {
472-
let def_key = infcx.tcx.def_key(mir_def_id);
473-
let is_adt_constructor = match def_key.disambiguated_data.data {
474-
DefPathData::StructCtor => true,
475-
_ => false,
476-
};
477-
478463
TypeChecker {
479464
infcx,
480465
last_span: DUMMY_SP,
481466
body_id,
482467
param_env,
483468
reported_errors: FxHashSet(),
484469
constraints: MirTypeckRegionConstraints::default(),
485-
is_adt_constructor,
486470
}
487471
}
488472

@@ -1099,17 +1083,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10991083
continue;
11001084
}
11011085
};
1102-
let op_ty = match op {
1103-
Operand::Consume(lv) => {
1104-
let lv_ty = lv.ty(mir, tcx).to_ty(tcx);
1105-
if self.is_adt_constructor {
1106-
self.normalize(&lv_ty, location)
1107-
} else {
1108-
lv_ty
1109-
}
1110-
}
1111-
Operand::Constant(c) => c.ty,
1112-
};
1086+
let op_ty = op.ty(mir, tcx);
11131087
if let Err(terr) = self.sub_types(
11141088
op_ty,
11151089
field_ty,
@@ -1198,7 +1172,7 @@ impl MirPass for TypeckMir {
11981172
}
11991173
let param_env = tcx.param_env(def_id);
12001174
tcx.infer_ctxt().enter(|infcx| {
1201-
let _region_constraint_sets = type_check(&infcx, id, param_env, mir, def_id);
1175+
let _region_constraint_sets = type_check(&infcx, id, param_env, mir);
12021176

12031177
// For verification purposes, we just ignore the resulting
12041178
// region constraint sets. Not our problem. =)

0 commit comments

Comments
 (0)