Skip to content

Commit cca0aa9

Browse files
committed
Properly account for binders in get_impl_future_output_ty
1 parent e100ec5 commit cca0aa9

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use rustc_middle::ty::error::TypeError;
6969
use rustc_middle::ty::{
7070
self,
7171
subst::{GenericArgKind, Subst, SubstsRef},
72-
Region, Ty, TyCtxt, TypeFoldable,
72+
Binder, Region, Ty, TyCtxt, TypeFoldable,
7373
};
7474
use rustc_span::{sym, BytePos, DesugaringKind, MultiSpan, Pos, Span};
7575
use rustc_target::spec::abi;
@@ -1774,7 +1774,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17741774
self.note_error_origin(diag, cause, exp_found, terr);
17751775
}
17761776

1777-
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1777+
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Binder<'tcx, Ty<'tcx>>> {
17781778
if let ty::Opaque(def_id, substs) = ty.kind() {
17791779
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
17801780
// Future::Output
@@ -1784,13 +1784,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17841784

17851785
for (predicate, _) in bounds {
17861786
let predicate = predicate.subst(self.tcx, substs);
1787-
if let ty::PredicateKind::Projection(projection_predicate) =
1788-
predicate.kind().skip_binder()
1789-
{
1790-
if projection_predicate.projection_ty.item_def_id == item_def_id {
1791-
// We don't account for multiple `Future::Output = Ty` contraints.
1792-
return Some(projection_predicate.ty);
1793-
}
1787+
let output = predicate
1788+
.kind()
1789+
.map_bound(|kind| match kind {
1790+
ty::PredicateKind::Projection(projection_predicate)
1791+
if projection_predicate.projection_ty.item_def_id == item_def_id =>
1792+
{
1793+
Some(projection_predicate.ty)
1794+
}
1795+
_ => None,
1796+
})
1797+
.transpose();
1798+
if output.is_some() {
1799+
// We don't account for multiple `Future::Output = Ty` contraints.
1800+
return output;
17941801
}
17951802
}
17961803
}
@@ -1832,8 +1839,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
18321839
}
18331840

18341841
match (
1835-
self.get_impl_future_output_ty(exp_found.expected),
1836-
self.get_impl_future_output_ty(exp_found.found),
1842+
self.get_impl_future_output_ty(exp_found.expected).map(Binder::skip_binder),
1843+
self.get_impl_future_output_ty(exp_found.found).map(Binder::skip_binder),
18371844
) {
18381845
(Some(exp), Some(found)) if same_type_modulo_infer(exp, found) => match cause.code() {
18391846
ObligationCauseCode::IfExpression(box IfExpressionCause { then, .. }) => {

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19131913
_ => return,
19141914
};
19151915
let mut add_label = true;
1916-
if let ty::Adt(def, _) = output_ty.kind() {
1916+
if let ty::Adt(def, _) = output_ty.skip_binder().kind() {
19171917
// no field access on enum type
19181918
if !def.is_enum() {
19191919
if def.non_enum_variant().fields.iter().any(|field| field.ident == field_ident) {

compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12891289
span: Span,
12901290
) {
12911291
let output_ty = match self.infcx.get_impl_future_output_ty(ty) {
1292-
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
1292+
Some(output_ty) => self.resolve_vars_if_possible(output_ty).skip_binder(),
12931293
_ => return,
12941294
};
12951295
let method_exists = self.method_exists(item_name, output_ty, call.hir_id, true);

0 commit comments

Comments
 (0)