Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,14 @@ fn field_tys_satisfy_relation_after_normalization_and_resolution<'tcx>(
match relation {
FieldRelation::Equal => {
if infcx
.at(&cause, param_env)
.relate(DefineOpaqueTypes::Yes, source_ty, ty::Variance::Invariant, target_ty)
.relate(
&cause,
param_env,
DefineOpaqueTypes::Yes,
source_ty,
ty::Variance::Invariant,
target_ty,
)
.is_err()
{
return false;
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,8 @@ fn orphan_check<'tcx>(
for (arg, id_arg) in
std::iter::zip(args, ty::GenericArgs::identity_for_item(tcx, impl_def_id))
{
let _ = infcx.at(&cause, ty::ParamEnv::empty()).eq(
DefineOpaqueTypes::No,
arg,
id_arg,
);
let _ =
infcx.eq(&cause, ty::ParamEnv::empty(), DefineOpaqueTypes::No, arg, id_arg);
}
infcx.deeply_resolve_ignoring_regions(tys)
});
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// adjustments search for mapped arguments.
let cause = self.cause(call_expr.span, ObligationCauseCode::Misc);
if self
.at(&cause, self.param_env)
.sup(DefineOpaqueTypes::Yes, formal_input_tys[0], adjusted_arg_type)
.sup(
&cause,
self.param_env,
DefineOpaqueTypes::Yes,
formal_input_tys[0],
adjusted_arg_type,
)
.is_err()
{
return do_check();
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
// This is `fcx.demand_eqtype`, but inlined to give a better error.
let cause = fcx.misc(self.span);
if fcx
.at(&cause, fcx.param_env)
.eq(DefineOpaqueTypes::Yes, src_obj, dst_obj)
.eq(&cause, fcx.param_env, DefineOpaqueTypes::Yes, src_obj, dst_obj)
.map(|infer_ok| fcx.register_infer_ok_obligations(infer_ok))
.is_err()
{
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
// Check that E' = S'.
let cause = self.misc(hir_ty.span);
let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq(
let InferOk { value: (), obligations } = self.eq(
&cause,
self.param_env,
DefineOpaqueTypes::Yes,
*expected_ty,
supplied_ty,
Expand All @@ -808,7 +810,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let supplied_output_ty = supplied_sig.output();
let cause = &self.misc(decl.output.span());
let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq(
let InferOk { value: (), obligations } = self.eq(
cause,
self.param_env,
DefineOpaqueTypes::Yes,
expected_sigs.liberated_sig.output(),
supplied_output_ty,
Expand Down
43 changes: 22 additions & 21 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
self.commit_if_ok(|snapshot| {
let outer_universe = self.infcx.universe();

let at = self.at(&self.cause, self.fcx.param_env);

let res = if self.use_lub {
at.lub(b, a)
self.lub(&self.cause, self.fcx.param_env, b, a)
} else {
at.sup(DefineOpaqueTypes::Yes, b, a)
self.sup(&self.cause, self.fcx.param_env, DefineOpaqueTypes::Yes, b, a)
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
};

Expand Down Expand Up @@ -1045,9 +1043,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
match b.kind() {
ty::FnPtr(_, b_hdr) => {
let a_sig = self.sig_for_fn_def_coercion(a, Some(b_hdr.safety()))?;

let InferOk { value: a_sig, mut obligations } =
self.at(&self.cause, self.param_env).normalize(Unnormalized::new_wip(a_sig));
let InferOk { value: a_sig, mut obligations } = NormalizeExt::normalize(
&self.infcx,
&self.cause,
self.param_env.clone(),
Unnormalized::new_wip(a_sig),
);
let a = Ty::new_fn_ptr(self.tcx, a_sig);

let adjust = Adjust::Pointer(PointerCoercion::ReifyFnPointer(b_hdr.safety()));
Expand Down Expand Up @@ -1372,7 +1373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(TypeError::Mismatch)
}
} else {
self.at(cause, self.param_env).lub(prev_ty, new_ty)
self.lub(cause, self.param_env, prev_ty, new_ty)
};

self.leak_check(outer_universe, Some(snapshot))?;
Expand Down Expand Up @@ -1411,8 +1412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// The signature must match.
let (a_sig, b_sig) = self.normalize(new.span, Unnormalized::new_wip((a_sig, b_sig)));
let sig = self
.at(cause, self.param_env)
.lub(a_sig, b_sig)
.lub(cause, self.param_env, a_sig, b_sig)
.map(|ok| self.register_infer_ok_obligations(ok))?;

// Reify both sides and return the reified fn pointer type.
Expand Down Expand Up @@ -1726,17 +1726,18 @@ impl<'tcx> CoerceMany<'tcx> {
//
// Another example is `break` with no argument expression.
assert!(expression_ty.is_unit(), "if let hack without unit type");
fcx.at(cause, fcx.param_env)
.eq(
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
DefineOpaqueTypes::Yes,
expected,
found,
)
.map(|infer_ok| {
fcx.register_infer_ok_obligations(infer_ok);
expression_ty
})
fcx.eq(
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs

@lcnr lcnr Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment should stay on DefineOpaqueTypes::Yes

also. Why are we using at here. We should be using some FnCtxt::eq method 🤔 we have FnCtxt::demand_eq but no eq which doesn't eagerly error. I guess that makes sense as eq outside of a probe always taints the root context. I guess that's separate from this PR 😁 so nothing to do here

View changes since the review

cause,
fcx.param_env,
DefineOpaqueTypes::Yes,
expected,
found,
)
.map(|infer_ok| {
fcx.register_infer_ok_obligations(infer_ok);
expression_ty
})
};

debug!(?result);
Expand Down
24 changes: 16 additions & 8 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Ty<'tcx>,
actual: Ty<'tcx>,
) -> Result<(), Diag<'a>> {
self.at(cause, self.param_env)
.sup(DefineOpaqueTypes::Yes, expected, actual)
self.sup(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual)
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
.map_err(|e| {
self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e)
Expand Down Expand Up @@ -219,8 +218,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Ty<'tcx>,
actual: Ty<'tcx>,
) -> Result<(), Diag<'a>> {
self.at(cause, self.param_env)
.eq(DefineOpaqueTypes::Yes, expected, actual)
self.eq(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual)
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
.map_err(|e| {
self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e)
Expand Down Expand Up @@ -416,8 +414,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};
let _ = self
.at(&ObligationCause::dummy(), self.param_env)
.eq(DefineOpaqueTypes::Yes, *input_arg, arg_ty)
.eq(
&ObligationCause::dummy(),
self.param_env,
DefineOpaqueTypes::Yes,
*input_arg,
arg_ty,
)
.ok()?;
self.select_obligations_where_possible(|errs| {
// Yeet the errors, we're already reporting errors.
Expand Down Expand Up @@ -498,8 +501,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.ok()
.and_then(|method| {
let _ = self
.at(&ObligationCause::dummy(), self.param_env)
.eq(DefineOpaqueTypes::Yes, ideal_rcvr_ty, expected_ty)
.eq(
&ObligationCause::dummy(),
self.param_env,
DefineOpaqueTypes::Yes,
ideal_rcvr_ty,
expected_ty,
)
.ok()?;
Some(method)
});
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2101,11 +2101,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(_) = remaining_fields.remove(&ident) {
let target_ty = self.field_ty(base_expr.span, f, args);
let cause = self.misc(base_expr.span);
match self.at(&cause, self.param_env).sup(
match self.sup(
// We're already using inference variables for any params,
// and don't allow converting between different structs,
// so there is no way this ever actually defines an opaque
// type. Thus choosing `Yes` is fine.
&cause,
self.param_env,
DefineOpaqueTypes::Yes,
target_ty,
fru_ty,
Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
self.register_infer_ok_obligations(
self.at(&self.misc(span), self.param_env).normalize(value),
)
self.register_infer_ok_obligations(self.infcx.normalize(
&self.misc(span),
self.param_env,
value,
))
}

pub(crate) fn require_type_meets(
Expand Down Expand Up @@ -1447,7 +1449,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// This also occurs for an enum variant on a type alias.
let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args));
let self_ty = self.normalize(span, Unnormalized::new_wip(self_ty));
match self.at(&self.misc(span), self.param_env).eq(
match self.eq(
&self.misc(span),
self.param_env,
DefineOpaqueTypes::Yes,
impl_ty,
self_ty,
Expand Down Expand Up @@ -1520,9 +1524,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We need to use a separate variable here as otherwise the temporary for
// `self.fulfillment_cx.borrow_mut()` is alive in the `Err` branch, resulting
// in a reentrant borrow, causing an ICE.
let result = self.at(&self.misc(sp), self.param_env).structurally_normalize_const(
let result = self.structurally_normalize_const(
Unnormalized::new_wip(ct),
&mut *self.fulfillment_cx.borrow_mut(),
self.param_env,
&self.misc(sp),
);
match result {
Ok(normalized_ct) => normalized_ct,
Expand Down
15 changes: 11 additions & 4 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// 3. Check if the formal type is actually equal to the checked one
// and register any such obligations for future type checks.
let formal_ty_error = self.at(&self.misc(provided_arg.span), self.param_env).eq(
let formal_ty_error = self.eq(
&self.misc(provided_arg.span),
self.param_env,
DefineOpaqueTypes::Yes,
formal_input_ty,
coerced_ty,
Expand Down Expand Up @@ -3223,9 +3225,14 @@ impl<'a, 'tcx> ArgMatchingCtxt<'a, 'tcx> {

// Using probe here, since we don't want this subtyping to affect inference.
let subtyping_error = self.probe(|_| {
self.at(&self.misc(arg_span), self.param_env)
.sup(DefineOpaqueTypes::Yes, formal_input_ty, coerced_ty)
.err()
self.sup(
&self.misc(arg_span),
self.param_env,
DefineOpaqueTypes::Yes,
formal_input_ty,
coerced_ty,
)
.err()
});

// Same as above: if either the coerce type or the checked type is an error type,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
self_ty, method_self_ty, self.span, pick
);
let cause = self.cause(self.self_expr.span, ObligationCauseCode::Misc);
match self.at(&cause, self.param_env).sup(DefineOpaqueTypes::Yes, method_self_ty, self_ty) {
match self.sup(&cause, self.param_env, DefineOpaqueTypes::Yes, method_self_ty, self_ty) {
Ok(InferOk { obligations, value: () }) => {
self.register_predicates(obligations);
}
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn_sig,
);

let InferOk { value: fn_sig, obligations: o } =
self.at(&obligation.cause, self.param_env).normalize(Unnormalized::new_wip(fn_sig));
let InferOk { value: fn_sig, obligations: o } = NormalizeExt::normalize(
&self.infcx,
&obligation.cause,
self.param_env,
Unnormalized::new_wip(fn_sig),
);
obligations.extend(o);

// Register obligations for the parameters. This will include the
Expand All @@ -447,7 +451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
move |_, _| predicates_cause.clone(),
|clause| {
let InferOk { value: pred, obligations: o } =
self.at(&obligation.cause, self.param_env).normalize(clause);
NormalizeExt::normalize(&self.infcx, &obligation.cause, self.param_env, clause);
normalization_obligations.extend(o);
assert!(!pred.has_escaping_bound_vars());
pred
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
// Guide the trait selection to show impls that have methods whose type matches
// up with the `self` parameter of the method.
let _ = self.at(&ObligationCause::dummy(), self.param_env).sup(
let _ = self.sup(
&ObligationCause::dummy(),
self.param_env,
DefineOpaqueTypes::Yes,
xform_self_ty,
self_ty,
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
}

let cause = ObligationCause::misc(hidden_type.span, self.body_def_id);
let at = self.at(&cause, self.param_env);
let hidden_type = match solve::deeply_normalize(at, Unnormalized::new_wip(hidden_type)) {
let hidden_type = match solve::deeply_normalize(
&self.infcx,
Unnormalized::new_wip(hidden_type),
self.param_env,
&cause,
) {
Ok(hidden_type) => hidden_type,
Err(errors) => {
let guar = self.err_ctxt().report_fulfillment_errors(errors);
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,13 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
let mut value = if self.should_normalize && self.fcx.next_trait_solver() {
let body_def_id = tcx.hir_body_owner_def_id(self.body.id());
let cause = ObligationCause::misc(self.span.to_span(tcx), body_def_id);
let at = self.fcx.at(&cause, self.fcx.param_env);
let universes = vec![None; outer_exclusive_binder(&value).as_usize()];
match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
at,
&self.fcx.infcx,
Unnormalized::new_wip(value),
universes,
self.fcx.param_env,
&cause,
) {
Ok((value, goals)) => {
self.nested_goals.extend(goals);
Expand Down
Loading
Loading