Skip to content
Open
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
19 changes: 11 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,14 +1460,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let ty::Adt(def, args) = ty.peel_refs().kind()
&& tcx.is_lang_item(def.did(), LangItem::Pin)
&& let ty::Ref(_, _, hir::Mutability::Mut) = args.type_at(0).kind()
&& let self_ty = self.infcx.instantiate_binder_with_fresh_vars(
fn_call_span,
BoundRegionConversionTime::FnCall,
tcx.fn_sig(method_did)
.instantiate(tcx, method_args)
.skip_norm_wip()
.input(0),
)
&& let self_ty = self
.infcx
.instantiate_binder_with_fresh_vars(
fn_call_span,
BoundRegionConversionTime::FnCall,
tcx.fn_sig(method_did)
.instantiate(tcx, method_args)
.skip_norm_wip()
.input(0),
)
.skip_norm_wip()
&& self.infcx.can_eq(self.infcx.param_env, ty, self_ty)
{
err.subdiagnostic(CaptureReasonSuggest::FreshReborrow {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Then replace the bound items in the fn sig with fresh variables,
// so that they represent the view from "inside" the closure.
let user_provided_sig = self.instantiate_canonical(self.body.span, &user_provided_poly_sig);
let mut user_provided_sig = self.infcx.instantiate_binder_with_fresh_vars(
let user_provided_sig = self.infcx.instantiate_binder_with_fresh_vars(
self.body.span,
BoundRegionConversionTime::FnCall,
user_provided_sig,
);
let mut user_provided_sig = user_provided_sig.skip_norm_wip();

// FIXME(async_closures): It's kind of wacky that we must apply this
// transformation here, since we do the same thing in HIR typeck.
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
BoundRegionConversionTime::HigherRankedType,
src_sig,
);
let src_sig = src_sig.skip_norm_wip();
let src_ty = Ty::new_fn_ptr(self.tcx(), ty::Binder::dummy(src_sig));
self.prove_predicate(
ty::ClauseKind::WellFormed(src_ty.into()),
Expand Down Expand Up @@ -1642,6 +1643,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
BoundRegionConversionTime::HigherRankedType,
binder_ty.into(),
);
let expected_ty = expected_ty.skip_norm_wip();
self.sub_types(
operand_ty,
expected_ty,
Expand Down Expand Up @@ -1883,6 +1885,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
BoundRegionConversionTime::HigherRankedType,
binder_ty.into(),
);
let found_ty = found_ty.skip_norm_wip();
self.relate_types(
ty,
context.ambient_variance(),
Expand Down
23 changes: 15 additions & 8 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
fn enter_forall<T, U>(
&mut self,
binder: ty::Binder<'tcx, T>,
f: impl FnOnce(&mut Self, T) -> U,
f: impl FnOnce(&mut Self, ty::Unnormalized<'tcx, T>) -> U,
) -> U
where
T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
{
let value = if let Some(inner) = binder.no_bound_vars() {
inner
ty::Unnormalized::new(inner)
} else {
let infcx = self.type_checker.infcx;
let mut lazy_universe = None;
Expand Down Expand Up @@ -211,12 +211,15 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
}

#[instrument(skip(self), level = "debug")]
fn instantiate_binder_with_existentials<T>(&mut self, binder: ty::Binder<'tcx, T>) -> T
fn instantiate_binder_with_existentials<T>(
&mut self,
binder: ty::Binder<'tcx, T>,
) -> ty::Unnormalized<'tcx, T>
where
T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
{
if let Some(inner) = binder.no_bound_vars() {
return inner;
return ty::Unnormalized::new(inner);
}

let infcx = self.type_checker.infcx;
Expand Down Expand Up @@ -499,7 +502,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
// Note: the order here is important. Create the placeholders first, otherwise
// we assign the wrong universe to the existential!
self.enter_forall(b, |this, b| {
let a = this.instantiate_binder_with_existentials(a);
let b = b.skip_norm_wip();
let a = this.instantiate_binder_with_existentials(a).skip_norm_wip();
this.relate(a, b)
})?;
}
Expand All @@ -514,7 +518,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
// Note: the order here is important. Create the placeholders first, otherwise
// we assign the wrong universe to the existential!
self.enter_forall(a, |this, a| {
let b = this.instantiate_binder_with_existentials(b);
let a = a.skip_norm_wip();
let b = this.instantiate_binder_with_existentials(b).skip_norm_wip();
this.relate(a, b)
})?;
}
Expand All @@ -529,13 +534,15 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
// Note: the order here is important. Create the placeholders first, otherwise
// we assign the wrong universe to the existential!
self.enter_forall(b, |this, b| {
let a = this.instantiate_binder_with_existentials(a);
let b = b.skip_norm_wip();
let a = this.instantiate_binder_with_existentials(a).skip_norm_wip();
this.relate(a, b)
})?;
// Note: the order here is important. Create the placeholders first, otherwise
// we assign the wrong universe to the existential!
self.enter_forall(a, |this, a| {
let b = this.instantiate_binder_with_existentials(b);
let a = a.skip_norm_wip();
let b = this.instantiate_binder_with_existentials(b).skip_norm_wip();
this.relate(a, b)
})?;
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ pub fn validate_trivial_unsize<'tcx>(
let universe = infcx.universe();
let ocx = ObligationCtxt::new(&infcx);
infcx.enter_forall(hr_target_principal, |target_principal| {
let target_principal = target_principal.skip_norm_wip();
let source_principal = infcx.instantiate_binder_with_fresh_vars(
DUMMY_SP,
BoundRegionConversionTime::HigherRankedType,
hr_source_principal,
);
let source_principal = source_principal.skip_norm_wip();
let Ok(()) = ocx.eq(
&ObligationCause::dummy(),
param_env,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/check/compare_eii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub(crate) fn compare_eii_function_types<'tcx>(
)
.skip_norm_wip(),
);
let unnormalized_external_impl_sig = unnormalized_external_impl_sig.skip_norm_wip();
let external_impl_sig = ocx.normalize(
&norm_cause,
param_env,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ fn compare_method_predicate_entailment<'tcx>(
BoundRegionConversionTime::HigherRankedType,
tcx.fn_sig(impl_m.def_id).instantiate_identity().skip_norm_wip(),
);
let unnormalized_impl_sig = unnormalized_impl_sig.skip_norm_wip();

let norm_cause = ObligationCause::misc(impl_m_span, impl_m_def_id);
let impl_sig =
Expand Down Expand Up @@ -537,11 +538,11 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
let impl_sig = ocx.normalize(
&misc_cause,
param_env,
Unnormalized::new_wip(infcx.instantiate_binder_with_fresh_vars(
infcx.instantiate_binder_with_fresh_vars(
return_span,
BoundRegionConversionTime::HigherRankedType,
tcx.fn_sig(impl_m.def_id).instantiate_identity().skip_norm_wip(),
)),
),
);
impl_sig.error_reported()?;
let impl_return_ty = impl_sig.output();
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode};
use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
};
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, Unnormalized};
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::{bug, span_bug};
use rustc_span::def_id::LocalDefId;
use rustc_span::{Span, sym};
Expand Down Expand Up @@ -232,6 +232,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
closure_sig,
);
let closure_sig = closure_sig.skip_norm_wip();
let adjustments = self.adjust_steps(autoderef);
self.record_deferred_call_resolution(
def_id,
Expand Down Expand Up @@ -259,6 +260,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
closure_args.coroutine_closure_sig(),
);
let coroutine_closure_sig = coroutine_closure_sig.skip_norm_wip();
let tupled_upvars_ty = self.next_ty_var(callee_expr.span);
// We may actually receive a coroutine back whose kind is different
// from the closure that this dispatched from. This is because when
Expand Down Expand Up @@ -584,7 +586,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
fn_sig,
);
let fn_sig = self.normalize(call_expr.span, Unnormalized::new_wip(fn_sig));
let fn_sig = self.normalize(call_expr.span, fn_sig);

self.check_argument_types(
call_expr.span,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
supplied_sig,
);
let supplied_sig = supplied_sig.skip_norm_wip();

// The liberated version of this signature should be a subtype
// of the liberated form of the expectation.
Expand Down
26 changes: 16 additions & 10 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
infer::BoundRegionConversionTime::FnCall,
fn_sig.input(i),
);
let input = input.skip_norm_wip();
self.require_type_is_sized_deferred(
input,
span,
Expand All @@ -669,6 +670,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
infer::BoundRegionConversionTime::FnCall,
fn_sig.output(),
);
let output = output.skip_norm_wip();
self.require_type_is_sized_deferred(
output,
call_expr_and_args.map_or(expr.span, |(e, _)| e.span),
Expand Down Expand Up @@ -1571,11 +1573,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let binder_ty = self.structurally_resolve_type(inner_expr.span, binder_ty);
let hint_ty = match *binder_ty.kind() {
ty::UnsafeBinder(binder) => self.instantiate_binder_with_fresh_vars(
inner_expr.span,
infer::BoundRegionConversionTime::HigherRankedType,
binder.into(),
),
ty::UnsafeBinder(binder) => self
.instantiate_binder_with_fresh_vars(
inner_expr.span,
infer::BoundRegionConversionTime::HigherRankedType,
binder.into(),
)
.skip_norm_wip(),
ty::Error(e) => Ty::new_error(self.tcx, e),
_ => {
let guar = self
Expand Down Expand Up @@ -1608,11 +1612,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// if it's not an unsafe binder.
let binder_ty = self.structurally_resolve_type(inner_expr.span, binder_ty);
match *binder_ty.kind() {
ty::UnsafeBinder(binder) => self.instantiate_binder_with_fresh_vars(
inner_expr.span,
infer::BoundRegionConversionTime::HigherRankedType,
binder.into(),
),
ty::UnsafeBinder(binder) => self
.instantiate_binder_with_fresh_vars(
inner_expr.span,
infer::BoundRegionConversionTime::HigherRankedType,
binder.into(),
)
.skip_norm_wip(),
ty::Error(e) => Ty::new_error(self.tcx, e),
_ => {
let guar = self
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3034,11 +3034,14 @@ impl<'a, 'tcx> ArgsCtxt<'a, 'tcx> {
.instantiate(self.call_ctxt.fn_ctxt.tcx, args)
.skip_norm_wip();

self.call_ctxt.fn_ctxt.instantiate_binder_with_fresh_vars(
call_name.span,
BoundRegionConversionTime::FnCall,
fn_sig,
);
self.call_ctxt
.fn_ctxt
.instantiate_binder_with_fresh_vars(
call_name.span,
BoundRegionConversionTime::FnCall,
fn_sig,
)
.skip_norm_wip();
}
None
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
infer::BoundRegionConversionTime::AssocTypeProjection(item_def_id),
poly_trait_ref,
);
let trait_ref = trait_ref.skip_norm_wip();

let item_args = self.lowerer().lower_generic_args_of_assoc_item(
span,
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id);
let upcast_trait_ref =
this.instantiate_binder_with_fresh_vars(upcast_poly_trait_ref);
let upcast_trait_ref = upcast_trait_ref.skip_norm_wip();
debug!(
"original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}",
original_poly_trait_ref, upcast_trait_ref, trait_def_id
Expand All @@ -347,7 +348,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
probe::WhereClausePick(poly_trait_ref) => {
// Where clauses can have bound regions in them. We need to instantiate
// those to convert from a poly-trait-ref to a trait-ref.
self.instantiate_binder_with_fresh_vars(poly_trait_ref).args
self.instantiate_binder_with_fresh_vars(poly_trait_ref).skip_norm_wip().args
}
}
}
Expand Down Expand Up @@ -597,6 +598,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
debug!("type scheme instantiated, sig={:?}", sig);

let sig = self.instantiate_binder_with_fresh_vars(sig);
let sig = sig.skip_norm_wip();
debug!("late-bound lifetimes from method instantiated, sig={:?}", sig);

(sig, method_predicates)
Expand Down Expand Up @@ -788,7 +790,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
}
}

fn instantiate_binder_with_fresh_vars<T>(&self, value: ty::Binder<'tcx, T>) -> T
fn instantiate_binder_with_fresh_vars<T>(
&self,
value: ty::Binder<'tcx, T>,
) -> Unnormalized<'tcx, T>
where
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
{
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
fn_sig,
);
let fn_sig = fn_sig.skip_norm_wip();

let InferOk { value: fn_sig, obligations: o } =
self.at(&obligation.cause, self.param_env).normalize(Unnormalized::new_wip(fn_sig));
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
fty,
);
let fty = fty.skip_norm_wip();
self.can_eq(self.param_env, fty.output(), expected)
}),
_ => false,
Expand Down Expand Up @@ -1906,6 +1907,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
trait_ref,
);
let trait_ref = trait_ref.skip_norm_wip();
let (xform_self_ty, _) =
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
Expand Down Expand Up @@ -2040,6 +2042,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
poly_trait_ref,
);
let trait_ref = trait_ref.skip_norm_wip();
let trait_ref =
ocx.normalize(cause, self.param_env, Unnormalized::new_wip(trait_ref));
(xform_self_ty, xform_ret_ty) =
Expand Down Expand Up @@ -2105,6 +2108,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
poly_trait_ref,
);
let trait_ref = trait_ref.skip_norm_wip();
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
fn_sig,
);
let fn_sig = fn_sig.skip_norm_wip();
if similar_candidate.is_method() {
if let Some(args) = args
&& fn_sig.inputs()[1..].len() == args.len()
Expand Down Expand Up @@ -2379,6 +2380,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
BoundRegionConversionTime::FnCall,
fn_sig,
);
let fn_sig = fn_sig.skip_norm_wip();
let name = inherent_method.name();
let inputs = fn_sig.inputs();
let expected_inputs =
Expand Down
Loading
Loading