Skip to content
Draft
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 @@ -721,8 +721,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
Original file line number Diff line number Diff line change
Expand Up @@ -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, ty::IsRigid::No).to_ty(tcx)
}

_ => ty.try_super_fold_with(self)?,
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(tcx, value),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn make_mir_scope<'ll, 'tcx>(
let callee = cx.tcx.instantiate_and_normalize_erasing_regions(
instance.args,
cx.typing_env(),
ty::EarlyBinder::bind(callee),
ty::EarlyBinder::bind(cx.tcx, callee),
);
debug_context.inlined_function_scopes.entry(callee).or_insert_with(|| {
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
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 @@ -134,7 +134,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 @@ -194,7 +194,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
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 @@ -70,8 +70,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 @@ -355,7 +355,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),
)
.map_err(|_| ErrorHandled::TooGeneric(self.cur_span()))
}
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
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,8 @@ pub(super) fn check_potentially_region_dependent_goals<'tcx>(
let predicate = fold_regions(tcx, *predicate, |_, _| {
infcx.next_region_var(RegionVariableOrigin::Misc(cause.span))
});
// FIXME: perhaps not here.
let predicate = ty::reset_rigid_aliases(tcx, predicate);
ocx.register_obligation(Obligation::new(tcx, cause.clone(), param_env, predicate));
}

Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
Ok(ty) => ty,
Err(guar) => Ty::new_error(tcx, guar),
};
remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
remapped_types.insert(def_id, ty::EarlyBinder::bind(tcx, ty));
}
Err(err) => {
// This code path is not reached in any tests, but may be
Expand All @@ -783,11 +783,14 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
if !remapped_types.contains_key(assoc_item) {
remapped_types.insert(
*assoc_item,
ty::EarlyBinder::bind(Ty::new_error_with_message(
ty::EarlyBinder::bind(
tcx,
return_span,
"missing synthetic item for RPITIT",
)),
Ty::new_error_with_message(
tcx,
return_span,
"missing synthetic item for RPITIT",
),
),
);
}
}
Expand Down Expand Up @@ -2739,6 +2742,7 @@ fn param_env_with_gat_bounds<'tcx>(
tcx,
trait_ty.def_id,
rebased_args,
ty::IsRigid::No,
),
term: normalize_impl_ty.into(),
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
}
let mut param_count = CountParams::default();
let has_region = pred.visit_with(&mut param_count).is_break();
let instantiated_pred = ty::EarlyBinder::bind(pred).instantiate(tcx, args);
let instantiated_pred = ty::EarlyBinder::bind(tcx, pred).instantiate(tcx, args);
// Don't check non-defaulted params, dependent defaults (including lifetimes)
// or preds with multiple params.
if instantiated_pred.skip_normalization().has_non_region_param()
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
bug!("unexpected sort of node in fn_sig(): {:?}", x);
}
};
ty::EarlyBinder::bind(output)
ty::EarlyBinder::bind(tcx, output)
}

fn lower_fn_sig_recovering_infer_ret_ty<'tcx>(
Expand Down Expand Up @@ -1380,7 +1380,7 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader
let trait_ref = icx.lowerer().lower_impl_trait_ref(&of_trait.trait_ref, selfty);

ty::ImplTraitHeader {
trait_ref: ty::EarlyBinder::bind(trait_ref),
trait_ref: ty::EarlyBinder::bind(tcx, trait_ref),
safety: of_trait.safety,
polarity: polarity_of_impl(tcx, of_trait, is_rustc_reservation),
constness: impl_.constness,
Expand Down Expand Up @@ -1600,7 +1600,7 @@ fn const_param_default<'tcx>(
default_ct,
tcx.type_of(def_id).instantiate(tcx, identity_args).skip_norm_wip(),
);
ty::EarlyBinder::bind(ct)
ty::EarlyBinder::bind(tcx, ct)
}

fn anon_const_kind<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ty::AnonConstKind {
Expand Down Expand Up @@ -1708,7 +1708,7 @@ fn const_of_item<'tcx>(
tcx.def_span(def_id),
"cannot call const_of_item on a non-type_const",
);
return ty::EarlyBinder::bind(Const::new_error(tcx, e));
return ty::EarlyBinder::bind(tcx, Const::new_error(tcx, e));
}
};
let icx = ItemCtxt::new(tcx, def_id);
Expand All @@ -1720,8 +1720,8 @@ fn const_of_item<'tcx>(
if let Err(e) = icx.check_tainted_by_errors()
&& !ct.references_error()
{
ty::EarlyBinder::bind(Const::new_error(tcx, e))
ty::EarlyBinder::bind(tcx, Const::new_error(tcx, e))
} else {
ty::EarlyBinder::bind(ct)
ty::EarlyBinder::bind(tcx, ct)
}
}
11 changes: 7 additions & 4 deletions compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ pub(super) fn explicit_item_bounds_with_filter(
let opaque_ty = tcx.hir_node_by_def_id(opaque_def_id.expect_local()).expect_opaque_ty();
let bounds =
associated_type_bounds(tcx, def_id, opaque_ty.bounds, opaque_ty.span, filter);
return ty::EarlyBinder::bind(bounds);
return ty::EarlyBinder::bind_no_rigid_aliases(bounds);
}
Some(ty::ImplTraitInTraitData::Impl { .. }) => {
span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds")
Expand Down Expand Up @@ -486,7 +486,7 @@ pub(super) fn explicit_item_bounds_with_filter(
node => bug!("item_bounds called on {def_id:?} => {node:?}"),
};

ty::EarlyBinder::bind(bounds)
ty::EarlyBinder::bind_no_rigid_aliases(bounds)
}

pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
Expand Down Expand Up @@ -515,9 +515,12 @@ pub(super) fn item_non_self_bounds(
let all_bounds: FxIndexSet<_> = tcx.item_bounds(def_id).skip_binder().iter().collect();
let own_bounds: FxIndexSet<_> = tcx.item_self_bounds(def_id).skip_binder().iter().collect();
if all_bounds.len() == own_bounds.len() {
ty::EarlyBinder::bind(ty::ListWithCachedTypeInfo::empty())
ty::EarlyBinder::bind(tcx, ty::ListWithCachedTypeInfo::empty())
} else {
ty::EarlyBinder::bind(tcx.mk_clauses_from_iter(all_bounds.difference(&own_bounds).copied()))
ty::EarlyBinder::bind(
tcx,
tcx.mk_clauses_from_iter(all_bounds.difference(&own_bounds).copied()),
)
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(

assert_only_contains_predicates_from(filter, implied_bounds, tcx.types.self_param);

ty::EarlyBinder::bind(implied_bounds)
ty::EarlyBinder::bind_no_rigid_aliases(implied_bounds)
}

// Make sure when elaborating supertraits, probing for associated types, etc.,
Expand Down Expand Up @@ -922,7 +922,7 @@ pub(super) fn type_param_predicates<'tcx>(
let icx = ItemCtxt::new(tcx, parent);
icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident)
} else {
ty::EarlyBinder::bind(&[] as &[_])
ty::EarlyBinder::bind_no_rigid_aliases(&[] as &[_])
};
let mut extend = None;

Expand Down Expand Up @@ -970,7 +970,7 @@ pub(super) fn type_param_predicates<'tcx>(
self_ty,
);

ty::EarlyBinder::bind(bounds)
ty::EarlyBinder::bind_no_rigid_aliases(bounds)
}

impl<'tcx> ItemCtxt<'tcx> {
Expand Down
26 changes: 16 additions & 10 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
return map[&trait_item_def_id];
}
Err(_) => {
return ty::EarlyBinder::bind(Ty::new_error_with_message(
return ty::EarlyBinder::bind(
tcx,
DUMMY_SP,
"Could not collect return position impl trait in trait tys",
));
Ty::new_error_with_message(
tcx,
DUMMY_SP,
"Could not collect return position impl trait in trait tys",
),
);
}
}
}
// For an RPITIT in a trait, just return the corresponding opaque.
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
return ty::EarlyBinder::bind(Ty::new_opaque(
return ty::EarlyBinder::bind(
tcx,
opaque_def_id,
ty::GenericArgs::identity_for_item(tcx, opaque_def_id),
));
Ty::new_opaque(
tcx,
opaque_def_id,
ty::GenericArgs::identity_for_item(tcx, opaque_def_id),
),
);
}
None => {}
}
Expand Down Expand Up @@ -239,9 +245,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
if let Err(e) = icx.check_tainted_by_errors()
&& !output.references_error()
{
ty::EarlyBinder::bind(Ty::new_error(tcx, e))
ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e))
} else {
ty::EarlyBinder::bind(output)
ty::EarlyBinder::bind(tcx, output)
}
}

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
name: tcx.item_ident(parent_def_id.to_def_id()),
what: "impl",
});
EarlyBinder::bind(Ty::new_error(tcx, guar))
EarlyBinder::bind(tcx, Ty::new_error(tcx, guar))
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(
name: tcx.item_ident(parent_def_id.to_def_id()),
what: "crate",
});
EarlyBinder::bind(Ty::new_error(tcx, guar))
EarlyBinder::bind(tcx, Ty::new_error(tcx, guar))
}
}

Expand Down Expand Up @@ -247,14 +247,14 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
let guar = tcx
.dcx()
.span_delayed_bug(opaque_type_span, "cannot infer type for stranded opaque type");
return EarlyBinder::bind(Ty::new_error(tcx, guar));
return EarlyBinder::bind(tcx, Ty::new_error(tcx, guar));
}

match opaque_types_from {
DefiningScopeKind::HirTypeck => {
let tables = tcx.typeck(owner_def_id);
if let Some(guar) = tables.tainted_by_errors {
EarlyBinder::bind(Ty::new_error(tcx, guar))
EarlyBinder::bind(tcx, Ty::new_error(tcx, guar))
} else if let Some(hidden_ty) = tables.hidden_types.get(&def_id) {
hidden_ty.ty
} else {
Expand All @@ -265,7 +265,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
// so we can just make the hidden type be `!`.
// For backwards compatibility reasons, we fall back to
// `()` until we the diverging default is changed.
EarlyBinder::bind(tcx.types.unit)
EarlyBinder::bind(tcx, tcx.types.unit)
}
}
DefiningScopeKind::MirBorrowck => match tcx.mir_borrowck(owner_def_id) {
Expand All @@ -275,14 +275,14 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
} else {
let hir_ty = tcx.type_of_opaque_hir_typeck(def_id);
if let Err(guar) = hir_ty.skip_binder().error_reported() {
EarlyBinder::bind(Ty::new_error(tcx, guar))
EarlyBinder::bind(tcx, Ty::new_error(tcx, guar))
} else {
assert!(!tcx.next_trait_solver_globally());
hir_ty
}
}
}
Err(guar) => EarlyBinder::bind(Ty::new_error(tcx, guar)),
Err(guar) => EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)),
},
}
}
Loading