Skip to content

Commit d2ec957

Browse files
Stop using PolyTraitRef for closure/coroutine predicates already instantiated w placeholders
1 parent 3a0db6c commit d2ec957

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
367367
}),
368368
) = error.code
369369
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
370-
expected_trait_ref.skip_binder().self_ty().kind()
370+
expected_trait_ref.self_ty().kind()
371371
&& span.overlaps(self.tcx.def_span(*def_id))
372372
{
373373
true

compiler/rustc_middle/src/traits/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,10 @@ pub enum SelectionError<'tcx> {
620620
OpaqueTypeAutoTraitLeakageUnknown(DefId),
621621
}
622622

623-
// FIXME(@lcnr): The `Binder` here should be unnecessary. Just use `TraitRef` instead.
624623
#[derive(Clone, Debug, TypeVisitable)]
625624
pub struct SignatureMismatchData<'tcx> {
626-
pub found_trait_ref: ty::PolyTraitRef<'tcx>,
627-
pub expected_trait_ref: ty::PolyTraitRef<'tcx>,
625+
pub found_trait_ref: ty::TraitRef<'tcx>,
626+
pub expected_trait_ref: ty::TraitRef<'tcx>,
628627
pub terr: ty::error::TypeError<'tcx>,
629628
}
630629

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1879,19 +1879,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18791879
&self,
18801880
span: Span,
18811881
found_span: Option<Span>,
1882-
found: ty::PolyTraitRef<'tcx>,
1883-
expected: ty::PolyTraitRef<'tcx>,
1882+
found: ty::TraitRef<'tcx>,
1883+
expected: ty::TraitRef<'tcx>,
18841884
cause: &ObligationCauseCode<'tcx>,
18851885
found_node: Option<Node<'_>>,
18861886
param_env: ty::ParamEnv<'tcx>,
18871887
) -> Diag<'tcx> {
18881888
pub(crate) fn build_fn_sig_ty<'tcx>(
18891889
infcx: &InferCtxt<'tcx>,
1890-
trait_ref: ty::PolyTraitRef<'tcx>,
1890+
trait_ref: ty::TraitRef<'tcx>,
18911891
) -> Ty<'tcx> {
1892-
let inputs = trait_ref.skip_binder().args.type_at(1);
1892+
let inputs = trait_ref.args.type_at(1);
18931893
let sig = match inputs.kind() {
1894-
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id()) => {
1894+
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id) => {
18951895
infcx.tcx.mk_fn_sig(
18961896
*inputs,
18971897
infcx.next_ty_var(TypeVariableOrigin {
@@ -1915,10 +1915,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19151915
),
19161916
};
19171917

1918-
Ty::new_fn_ptr(infcx.tcx, trait_ref.rebind(sig))
1918+
Ty::new_fn_ptr(infcx.tcx, ty::Binder::dummy(sig))
19191919
}
19201920

1921-
let argument_kind = match expected.skip_binder().self_ty().kind() {
1921+
let argument_kind = match expected.self_ty().kind() {
19221922
ty::Closure(..) => "closure",
19231923
ty::Coroutine(..) => "coroutine",
19241924
_ => "function",

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -3380,11 +3380,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33803380
fn report_cyclic_signature_error(
33813381
&self,
33823382
obligation: &PredicateObligation<'tcx>,
3383-
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
3384-
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
3383+
found_trait_ref: ty::TraitRef<'tcx>,
3384+
expected_trait_ref: ty::TraitRef<'tcx>,
33853385
terr: TypeError<'tcx>,
33863386
) -> Diag<'tcx> {
3387-
let self_ty = found_trait_ref.self_ty().skip_binder();
3387+
let self_ty = found_trait_ref.self_ty();
33883388
let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() {
33893389
(
33903390
ObligationCause::dummy_with_span(self.tcx.def_span(def_id)),
@@ -3394,7 +3394,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33943394
(obligation.cause.clone(), terr)
33953395
};
33963396
self.report_and_explain_type_error(
3397-
TypeTrace::poly_trait_refs(&cause, true, expected_trait_ref, found_trait_ref),
3397+
TypeTrace::poly_trait_refs(
3398+
&cause,
3399+
true,
3400+
ty::Binder::dummy(expected_trait_ref),
3401+
ty::Binder::dummy(found_trait_ref),
3402+
),
33983403
terr,
33993404
)
34003405
}
@@ -3434,17 +3439,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
34343439
&self,
34353440
obligation: &PredicateObligation<'tcx>,
34363441
span: Span,
3437-
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
3438-
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
3442+
found_trait_ref: ty::TraitRef<'tcx>,
3443+
expected_trait_ref: ty::TraitRef<'tcx>,
34393444
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
34403445
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
34413446
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
34423447

34433448
expected_trait_ref.self_ty().error_reported()?;
3444-
3445-
let Some(found_trait_ty) = found_trait_ref.self_ty().no_bound_vars() else {
3446-
self.dcx().bug("bound vars outside binder");
3447-
};
3449+
let found_trait_ty = found_trait_ref.self_ty();
34483450

34493451
let found_did = match *found_trait_ty.kind() {
34503452
ty::Closure(did, _) | ty::FnDef(did, _) | ty::Coroutine(did, ..) => Some(did),
@@ -3462,15 +3464,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
34623464

34633465
let mut not_tupled = false;
34643466

3465-
let found = match found_trait_ref.skip_binder().args.type_at(1).kind() {
3467+
let found = match found_trait_ref.args.type_at(1).kind() {
34663468
ty::Tuple(tys) => vec![ArgKind::empty(); tys.len()],
34673469
_ => {
34683470
not_tupled = true;
34693471
vec![ArgKind::empty()]
34703472
}
34713473
};
34723474

3473-
let expected_ty = expected_trait_ref.skip_binder().args.type_at(1);
3475+
let expected_ty = expected_trait_ref.args.type_at(1);
34743476
let expected = match expected_ty.kind() {
34753477
ty::Tuple(tys) => {
34763478
tys.iter().map(|t| ArgKind::from_expected_ty(t, Some(span))).collect()
@@ -3487,15 +3489,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
34873489
// traits manually, but don't make it more confusing when it does
34883490
// happen.
34893491
Ok(
3490-
if Some(expected_trait_ref.def_id()) != self.tcx.lang_items().coroutine_trait()
3492+
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait()
34913493
&& not_tupled
34923494
{
34933495
self.report_and_explain_type_error(
34943496
TypeTrace::poly_trait_refs(
34953497
&obligation.cause,
34963498
true,
3497-
expected_trait_ref,
3498-
found_trait_ref,
3499+
ty::Binder::dummy(expected_trait_ref),
3500+
ty::Binder::dummy(found_trait_ref),
34993501
),
35003502
ty::error::TypeError::Mismatch,
35013503
)

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10791079
})
10801080
.map_err(|terr| {
10811081
SignatureMismatch(Box::new(SignatureMismatchData {
1082-
expected_trait_ref: ty::Binder::dummy(obligation_trait_ref),
1083-
found_trait_ref: ty::Binder::dummy(found_trait_ref),
1082+
expected_trait_ref: obligation_trait_ref,
1083+
found_trait_ref,
10841084
terr,
10851085
}))
10861086
})

0 commit comments

Comments
 (0)