Skip to content

Commit 314dee5

Browse files
Rollup merge of #123900 - compiler-errors:nobound, r=lcnr
Stop using `PolyTraitRef` for closure/coroutine predicates already instantiated w placeholders r? lcnr
2 parents 99d0186 + 9e630d3 commit 314dee5

File tree

10 files changed

+39
-61
lines changed

10 files changed

+39
-61
lines changed

Diff for: 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

Diff for: compiler/rustc_infer/src/infer/at.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -424,25 +424,7 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
424424
) -> TypeTrace<'tcx> {
425425
TypeTrace {
426426
cause: cause.clone(),
427-
values: PolyTraitRefs(ExpectedFound::new(
428-
a_is_expected,
429-
ty::Binder::dummy(a),
430-
ty::Binder::dummy(b),
431-
)),
432-
}
433-
}
434-
}
435-
436-
impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
437-
fn to_trace(
438-
cause: &ObligationCause<'tcx>,
439-
a_is_expected: bool,
440-
a: Self,
441-
b: Self,
442-
) -> TypeTrace<'tcx> {
443-
TypeTrace {
444-
cause: cause.clone(),
445-
values: PolyTraitRefs(ExpectedFound::new(a_is_expected, a, b)),
427+
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
446428
}
447429
}
448430
}

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
16531653
.report(diag);
16541654
(false, Mismatch::Fixed("signature"))
16551655
}
1656-
ValuePairs::PolyTraitRefs(_) => (false, Mismatch::Fixed("trait")),
1656+
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
16571657
ValuePairs::Aliases(infer::ExpectedFound { expected, .. }) => {
16581658
(false, Mismatch::Fixed(self.tcx.def_descr(expected.def_id)))
16591659
}
@@ -1969,8 +1969,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19691969
self.note_and_explain_type_err(diag, exp_found, cause, span, cause.body_id.to_def_id());
19701970
}
19711971

1972-
if let Some(ValuePairs::PolyTraitRefs(exp_found)) = values
1973-
&& let ty::Closure(def_id, _) = exp_found.expected.skip_binder().self_ty().kind()
1972+
if let Some(ValuePairs::TraitRefs(exp_found)) = values
1973+
&& let ty::Closure(def_id, _) = exp_found.expected.self_ty().kind()
19741974
&& let Some(def_id) = def_id.as_local()
19751975
&& terr.involves_regions()
19761976
{
@@ -2188,7 +2188,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
21882188
infer::Aliases(exp_found) => self.expected_found_str(exp_found),
21892189
infer::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
21902190
infer::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
2191-
infer::PolyTraitRefs(exp_found) => {
2191+
infer::TraitRefs(exp_found) => {
21922192
let pretty_exp_found = ty::error::ExpectedFound {
21932193
expected: exp_found.expected.print_trait_sugared(),
21942194
found: exp_found.found.print_trait_sugared(),

Diff for: compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
195195
value_pairs: &ValuePairs<'tcx>,
196196
) -> Option<Diag<'tcx>> {
197197
let (expected_args, found_args, trait_def_id) = match value_pairs {
198-
ValuePairs::PolyTraitRefs(ExpectedFound { expected, found })
199-
if expected.def_id() == found.def_id() =>
198+
ValuePairs::TraitRefs(ExpectedFound { expected, found })
199+
if expected.def_id == found.def_id =>
200200
{
201201
// It's possible that the placeholders come from a binder
202202
// outside of this value pair. Use `no_bound_vars` as a
203203
// simple heuristic for that.
204-
(expected.no_bound_vars()?.args, found.no_bound_vars()?.args, expected.def_id())
204+
(expected.args, found.args, expected.def_id)
205205
}
206206
_ => return None,
207207
};

Diff for: compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
599599
&self,
600600
span: Span,
601601
hir: hir::Node<'_>,
602-
exp_found: &ty::error::ExpectedFound<ty::PolyTraitRef<'tcx>>,
602+
exp_found: &ty::error::ExpectedFound<ty::TraitRef<'tcx>>,
603603
diag: &mut Diag<'_>,
604604
) {
605605
// 0. Extract fn_decl from hir
@@ -614,10 +614,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
614614

615615
// 1. Get the args of the closure.
616616
// 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1].
617-
let Some(expected) = exp_found.expected.skip_binder().args.get(1) else {
617+
let Some(expected) = exp_found.expected.args.get(1) else {
618618
return;
619619
};
620-
let Some(found) = exp_found.found.skip_binder().args.get(1) else {
620+
let Some(found) = exp_found.found.args.get(1) else {
621621
return;
622622
};
623623
let expected = expected.unpack();

Diff for: compiler/rustc_infer/src/infer/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ pub enum ValuePairs<'tcx> {
403403
Regions(ExpectedFound<ty::Region<'tcx>>),
404404
Terms(ExpectedFound<ty::Term<'tcx>>),
405405
Aliases(ExpectedFound<ty::AliasTy<'tcx>>),
406-
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
406+
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
407407
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
408408
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
409409
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
@@ -1882,15 +1882,15 @@ impl<'tcx> TypeTrace<'tcx> {
18821882
}
18831883
}
18841884

1885-
pub fn poly_trait_refs(
1885+
pub fn trait_refs(
18861886
cause: &ObligationCause<'tcx>,
18871887
a_is_expected: bool,
1888-
a: ty::PolyTraitRef<'tcx>,
1889-
b: ty::PolyTraitRef<'tcx>,
1888+
a: ty::TraitRef<'tcx>,
1889+
b: ty::TraitRef<'tcx>,
18901890
) -> TypeTrace<'tcx> {
18911891
TypeTrace {
18921892
cause: cause.clone(),
1893-
values: PolyTraitRefs(ExpectedFound::new(a_is_expected, a, b)),
1893+
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
18941894
}
18951895
}
18961896

Diff for: 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

Diff for: 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",

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+11-14
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,7 @@ 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::trait_refs(&cause, true, expected_trait_ref, found_trait_ref),
33983398
terr,
33993399
)
34003400
}
@@ -3434,17 +3434,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
34343434
&self,
34353435
obligation: &PredicateObligation<'tcx>,
34363436
span: Span,
3437-
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
3438-
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
3437+
found_trait_ref: ty::TraitRef<'tcx>,
3438+
expected_trait_ref: ty::TraitRef<'tcx>,
34393439
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
34403440
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
34413441
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
34423442

34433443
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-
};
3444+
let found_trait_ty = found_trait_ref.self_ty();
34483445

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

34633460
let mut not_tupled = false;
34643461

3465-
let found = match found_trait_ref.skip_binder().args.type_at(1).kind() {
3462+
let found = match found_trait_ref.args.type_at(1).kind() {
34663463
ty::Tuple(tys) => vec![ArgKind::empty(); tys.len()],
34673464
_ => {
34683465
not_tupled = true;
34693466
vec![ArgKind::empty()]
34703467
}
34713468
};
34723469

3473-
let expected_ty = expected_trait_ref.skip_binder().args.type_at(1);
3470+
let expected_ty = expected_trait_ref.args.type_at(1);
34743471
let expected = match expected_ty.kind() {
34753472
ty::Tuple(tys) => {
34763473
tys.iter().map(|t| ArgKind::from_expected_ty(t, Some(span))).collect()
@@ -3487,11 +3484,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
34873484
// traits manually, but don't make it more confusing when it does
34883485
// happen.
34893486
Ok(
3490-
if Some(expected_trait_ref.def_id()) != self.tcx.lang_items().coroutine_trait()
3487+
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait()
34913488
&& not_tupled
34923489
{
34933490
self.report_and_explain_type_error(
3494-
TypeTrace::poly_trait_refs(
3491+
TypeTrace::trait_refs(
34953492
&obligation.cause,
34963493
true,
34973494
expected_trait_ref,

Diff for: 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)