Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
));
let can_subst = |ty: Ty<'tcx>| {
// Normalize before comparing to see through type aliases and projections.
let old_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args);
let new_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, new_args);
let old_ty = ty::EarlyBinder::bind(tcx, ty).instantiate(tcx, generic_args);
let new_ty = ty::EarlyBinder::bind(tcx, ty).instantiate(tcx, new_args);
if let Ok(old_ty) = tcx.try_normalize_erasing_regions(
self.infcx.typing_env(self.infcx.param_env),
old_ty,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
"non-defining use of `{}` in the defining scope",
Ty::new_opaque(
infcx.tcx,
ty::IsRigid::No,
opaque_type_key.def_id.to_def_id(),
opaque_type_key.args
)
Expand Down Expand Up @@ -220,7 +221,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
// If we find an opaque in a local ty, then for each of its captured regions,
// try to find a path between that captured regions and our borrow region...
if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *ty.kind()
if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *ty.kind()
&& let hir::OpaqueTyOrigin::FnReturn { parent, in_trait_or_impl: None } =
self.tcx.opaque_ty_origin(def_id)
{
Expand Down Expand Up @@ -277,7 +278,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CheckExplicitRegionMentionAndCollectGen

fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
match *ty.kind() {
ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
if self.seen_opaques.insert(def_id) {
for (bound, _) in self
.tcx
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;

let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *output_ty.kind() {
if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *output_ty.kind() {
output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity().skip_norm_wip()
};

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
| ty::Never
| ty::Tuple(_)
| ty::UnsafeBinder(_)
| ty::Alias(_)
| ty::Alias(_, _)
| ty::Param(_)
| ty::Bound(_, _)
| ty::Infer(_)
Expand Down Expand Up @@ -1970,7 +1970,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
| ty::CoroutineWitness(..)
| ty::Never
| ty::UnsafeBinder(_)
| ty::Alias(_)
| ty::Alias(_, _)
| ty::Param(_)
| ty::Bound(_, _)
| ty::Infer(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectMemberConstraintsVisitor<'_, '_,
| ty::CoroutineClosure(def_id, args)
| ty::Coroutine(def_id, args) => self.visit_closure_args(def_id, args),

ty::Alias(ty::AliasTy { kind, args, .. })
ty::Alias(_, ty::AliasTy { kind, args, .. })
if let Some(variances) = self.cx().opt_alias_variances(kind) =>
{
// Skip lifetime parameters that are not captured, since they do
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
// usage of the opaque type and we can ignore it. This check is mirrored in typeck's
// writeback.
if !rcx.infcx.tcx.use_typing_mode_post_typeck_until_borrowck() {
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
hidden_type.ty.skip_binder().kind()
&& def_id == opaque_type_key.def_id.to_def_id()
&& args == opaque_type_key.args
Expand Down Expand Up @@ -500,7 +500,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
Ty::new_coroutine(tcx, def_id, self.fold_closure_args(def_id, args)?)
}

ty::Alias(ty::AliasTy { kind, args, .. })
ty::Alias(_, ty::AliasTy { kind, args, .. })
if let Some(variances) = tcx.opt_alias_variances(kind) =>
{
let args = tcx.mk_args_from_iter(std::iter::zip(variances, args.iter()).map(
Expand All @@ -512,7 +512,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
}
},
))?;
ty::AliasTy::new_from_args(tcx, kind, args).to_ty(tcx)
ty::AliasTy::new_from_args(tcx, kind, args).to_ty(tcx, ty::IsRigid::No)
}

_ => ty.try_super_fold_with(self)?,
Expand Down Expand Up @@ -541,7 +541,7 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>(
for &(key, hidden_type) in opaque_types {
let Some(expected) = hidden_types.get(&key.def_id) else {
if !tcx.use_typing_mode_post_typeck_until_borrowck() {
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
hidden_type.ty.kind()
&& def_id == key.def_id.to_def_id()
&& args == key.args
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Necessary for non-trivial patterns whose user-type annotation is an opaque type,
// e.g. `let (_a,): Tait = whatever`, see #105897
if !self.infcx.next_trait_solver()
&& let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
&& let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
curr_projected_ty.ty.kind()
{
// There is nothing that we can compare here if we go through an opaque type.
Expand Down Expand Up @@ -1760,7 +1760,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
let tcx = self.tcx();
let maybe_uneval = match constant.const_ {
Const::Ty(_, ct) => match ct.kind() {
ty::ConstKind::Unevaluated(uv) => match uv.kind {
ty::ConstKind::Unevaluated(_, uv) => match uv.kind {
ty::UnevaluatedConstKind::Projection { def_id }
| ty::UnevaluatedConstKind::Inherent { def_id }
| ty::UnevaluatedConstKind::Free { def_id }
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
};

let (a, b) = match (a.kind(), b.kind()) {
(&ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => {
(&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => {
(a, enable_subtyping(b, true)?)
}
(_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) => {
(_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) => {
(enable_subtyping(a, false)?, b)
}
_ => unreachable!(
Expand Down Expand Up @@ -386,8 +386,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
}

(
&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }),
&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }),
&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }),
&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }),
) if a_def_id == b_def_id || infcx.next_trait_solver() => {
super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| {
// This behavior is only there for the old solver, the new solver
Expand All @@ -401,8 +401,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
})?;
}
(&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _)
| (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }))
(&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _)
| (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }))
if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() =>
{
self.relate_opaques(a, b)?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
self.instance.instantiate_mir_and_normalize_erasing_regions(
self.tcx,
ty::TypingEnv::fully_monomorphized(),
ty::EarlyBinder::bind(value),
ty::EarlyBinder::bind(self.tcx, value),
)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.instance.instantiate_mir_and_normalize_erasing_regions(
self.cx.tcx(),
self.cx.typing_env(),
ty::EarlyBinder::bind(value),
ty::EarlyBinder::bind(self.cx.tcx(), value),
)
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let monomorphized_mir = instance.instantiate_mir_and_normalize_erasing_regions(
tcx,
ty::TypingEnv::fully_monomorphized(),
ty::EarlyBinder::bind(mir.clone()),
ty::EarlyBinder::bind(tcx, mir.clone()),
);
mir = tcx.arena.alloc(optimize_use_clone::<Bx>(cx, monomorphized_mir));
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL
.instantiate_mir_and_normalize_erasing_regions(
cx.tcx(),
cx.typing_env(),
ty::EarlyBinder::bind(value.const_),
ty::EarlyBinder::bind(cx.tcx(), value.const_),
)
.eval(cx.tcx(), cx.typing_env(), value.span)
.expect("erroneous constant missed by mono item collection");

let mono_type = instance.instantiate_mir_and_normalize_erasing_regions(
cx.tcx(),
cx.typing_env(),
ty::EarlyBinder::bind(value.ty()),
ty::EarlyBinder::bind(cx.tcx(), value.ty()),
);

let string = common::asm_const_to_str(
Expand All @@ -91,7 +91,7 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL
let mono_type = instance.instantiate_mir_and_normalize_erasing_regions(
cx.tcx(),
cx.typing_env(),
ty::EarlyBinder::bind(value.ty()),
ty::EarlyBinder::bind(cx.tcx(), value.ty()),
);

let instance = match mono_type.kind() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ where
Const::Ty(_, ct) => match ct.kind() {
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
// Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`).
ty::ConstKind::Unevaluated(_) => None,
ty::ConstKind::Unevaluated(_, _) => None,
// FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
// strict, and if instead we should be doing some kind of value-based analysis.
ty::ConstKind::Value(_) => None,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
body: &'tcx mir::Body<'tcx>,
) -> InterpResult<'tcx, R> {
let tcx = *ecx.tcx;
let layout =
ecx.layout_of(body.bound_return_ty().instantiate(tcx, cid.instance.args).skip_norm_wip())?;
let layout = ecx
.layout_of(body.bound_return_ty(tcx).instantiate(tcx, cid.instance.args).skip_norm_wip())?;
let (intern_kind, ret) = setup_for_eval(ecx, cid, layout)?;

trace!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
.try_instantiate_mir_and_normalize_erasing_regions(
*self.tcx,
self.typing_env,
ty::EarlyBinder::bind(value),
ty::EarlyBinder::bind(self.tcx.tcx, value),

@BoxyUwU BoxyUwU Jun 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

TyCtxtAt

)
.map_err(|_| ErrorHandled::TooGeneric(self.cur_span()))
}
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,21 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
// Types with identity (print the module path).
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
| ty::FnDef(def_id, args)
| ty::Alias(ty::AliasTy {
kind: ty::Projection { def_id } | ty::Opaque { def_id },
args,
..
})
| ty::Alias(
_,
ty::AliasTy {
kind: ty::Projection { def_id } | ty::Opaque { def_id }, args, ..
},
)
| ty::Closure(def_id, args)
| ty::CoroutineClosure(def_id, args)
| ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => {
ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => {
bug!("type_name: unexpected free alias")
}
ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
bug!("type_name: unexpected inherent projection")
}
ty::CoroutineWitness(..) => bug!("type_name: unexpected `CoroutineWitness`"),
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
return None;
}

let (normalized_ty, obligations) = self
.normalize_ty(Unnormalized::new(Ty::new_projection(tcx, trait_target_def_id, [ty])))?;
let (normalized_ty, obligations) = self.normalize_ty(Unnormalized::new(
Ty::new_projection(tcx, ty::IsRigid::No, trait_target_def_id, [ty]),
))?;
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
self.state.obligations.extend(obligations);

Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_analysis/src/check/always_applicable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ fn ensure_all_fields_are_const_destruct<'tcx>(
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);

let impl_span = tcx.def_span(impl_def_id.to_def_id());
let env =
ty::EarlyBinder::bind(tcx.param_env(impl_def_id)).instantiate_identity().skip_norm_wip();
let env = ty::EarlyBinder::bind(tcx, tcx.param_env(impl_def_id))
.instantiate_identity()
.skip_norm_wip();
let args = ty::GenericArgs::identity_for_item(tcx, impl_def_id);
let destruct_trait = tcx.lang_items().destruct_trait().unwrap();
for field in tcx.adt_def(adt_def_id).all_fields() {
Expand Down Expand Up @@ -281,7 +282,7 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>(
// reference the params from the ADT instead of from the impl which is bad UX. To resolve
// this we "rename" the ADT's params to be the impl's params which should not affect behaviour.
let impl_adt_ty = Ty::new_adt(tcx, tcx.adt_def(adt_def_id), adt_to_impl_args);
let adt_env = ty::EarlyBinder::bind(tcx.param_env(adt_def_id))
let adt_env = ty::EarlyBinder::bind(tcx, tcx.param_env(adt_def_id))
.instantiate(tcx, adt_to_impl_args)
.skip_norm_wip();

Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn check_opaque_meets_bounds<'tcx>(
}),
};

let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args);
let opaque_ty = Ty::new_opaque(tcx, ty::IsRigid::No, def_id.to_def_id(), args);

// `ReErased` regions appear in the "parent_args" of closures/coroutines.
// We're ignoring them here and replacing them with fresh region variables.
Expand Down Expand Up @@ -534,7 +534,7 @@ fn sanity_check_found_hidden_type<'tcx>(
// Nothing was actually constrained.
return Ok(());
}
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = ty.ty.kind() {
if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = ty.ty.kind() {
if def_id == key.def_id.to_def_id() && args == key.args {
// Nothing was actually constrained, this is an opaque usage that was
// only discovered to be opaque after inference vars resolved.
Expand Down Expand Up @@ -778,7 +778,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
if has_default {
// need to store default and type of default
let ct = tcx.const_param_default(param.def_id).skip_binder();
if let ty::ConstKind::Unevaluated(uv) = ct.kind()
if let ty::ConstKind::Unevaluated(_, uv) = ct.kind()
&& let Some(def_id) = uv.kind.opt_def_id()
{
tcx.ensure_ok().type_of(def_id);
Expand Down Expand Up @@ -2191,7 +2191,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG
impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector {
fn visit_ty(&mut self, t: Ty<'tcx>) {
match *t.kind() {
ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => {
ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => {
self.opaques.push(def);
}
ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => {
Expand Down Expand Up @@ -2224,10 +2224,13 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG
let mut label_match = |ty: Ty<'_>, span| {
for arg in ty.walk() {
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& let ty::Alias(ty::AliasTy {
kind: ty::Opaque { def_id: captured_def_id },
..
}) = *ty.kind()
&& let ty::Alias(
_,
ty::AliasTy {
kind: ty::Opaque { def_id: captured_def_id },
..
},
) = *ty.kind()
&& captured_def_id == opaque_def_id.to_def_id()
{
err.span_label(
Expand Down
Loading
Loading