X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_infer%2Fsrc%2Finfer%2Fcombine.rs;h=cf895ed0d3e598ba23eb5effcb52345e75982045;hb=d1449560e31f7f801d81268a3dad783181656dff;hp=c2552561c42dfda9f7f99c54da006ad3457a5eb4;hpb=20d6a44334e189989a99f2f914b243dd81e88968;p=rust.git diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index c2552561c42..cf895ed0d3e 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -450,6 +450,15 @@ pub fn add_const_equate_obligation( ty::Binder::dummy(predicate), )); } + + pub fn mark_ambiguous(&mut self) { + self.obligations.push(Obligation::new( + self.tcx(), + self.trace.cause.clone(), + self.param_env, + ty::Binder::dummy(ty::PredicateKind::Ambiguous), + )); + } } struct Generalizer<'cx, 'tcx> { @@ -521,6 +530,11 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } + + fn intercrate(&self) -> bool { + self.infcx.intercrate + } + fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env } @@ -533,6 +547,10 @@ fn a_is_expected(&self) -> bool { true } + fn mark_ambiguous(&mut self) { + span_bug!(self.cause.span, "opaque types are handled in `tys`"); + } + fn binders( &mut self, a: ty::Binder<'tcx, T>, @@ -657,6 +675,10 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { // relatable. Ok(t) } + ty::Opaque(def_id, substs) => { + let s = self.relate(substs, substs)?; + Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) }) + } _ => relate::super_relate_tys(self, t, t), }?; @@ -731,7 +753,7 @@ fn consts( origin: var_value.origin, val: ConstVariableValue::Unknown { universe: self.for_universe }, }); - Ok(self.tcx().mk_const_var(new_var_id, c.ty())) + Ok(self.tcx().mk_const(new_var_id, c.ty())) } } } @@ -743,10 +765,7 @@ fn consts( substs, substs, )?; - Ok(self.tcx().mk_const( - ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }), - c.ty(), - )) + Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty())) } _ => relate::super_relate_consts(self, c, c), } @@ -799,6 +818,11 @@ fn tcx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } + fn intercrate(&self) -> bool { + assert!(!self.infcx.intercrate); + false + } + fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env } @@ -811,6 +835,10 @@ fn a_is_expected(&self) -> bool { true } + fn mark_ambiguous(&mut self) { + bug!() + } + fn relate_with_variance>( &mut self, _variance: ty::Variance, @@ -944,7 +972,7 @@ fn consts( }, }, ); - Ok(self.tcx().mk_const_var(new_var_id, c.ty())) + Ok(self.tcx().mk_const(new_var_id, c.ty())) } } } @@ -957,10 +985,7 @@ fn consts( substs, )?; - Ok(self.tcx().mk_const( - ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }), - c.ty(), - )) + Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty())) } _ => relate::super_relate_consts(self, c, c), }