Skip to content

Commit 4019c8a

Browse files
Rollup merge of #104921 - compiler-errors:no-binder-on-fut-ty, r=cjgillot
Remove unnecessary binder from `get_impl_future_output_ty` We never construct an `async fn` with a higher-ranked `impl Future` bound anyways, and basically all the call-sites already skip the binder.
2 parents 75352dd + 1472b38 commit 4019c8a

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2333,12 +2333,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23332333
base: &'tcx hir::Expr<'tcx>,
23342334
ty: Ty<'tcx>,
23352335
) {
2336-
let output_ty = match self.get_impl_future_output_ty(ty) {
2337-
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
2338-
_ => return,
2339-
};
2336+
let Some(output_ty) = self.get_impl_future_output_ty(ty) else { return; };
23402337
let mut add_label = true;
2341-
if let ty::Adt(def, _) = output_ty.skip_binder().kind() {
2338+
if let ty::Adt(def, _) = output_ty.kind() {
23422339
// no field access on enum type
23432340
if !def.is_enum() {
23442341
if def

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -924,15 +924,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
924924
let ty = match self.tcx.asyncness(fn_id.owner) {
925925
hir::IsAsync::Async => {
926926
let infcx = self.tcx.infer_ctxt().build();
927-
infcx
928-
.get_impl_future_output_ty(ty)
929-
.unwrap_or_else(|| {
930-
span_bug!(
931-
fn_decl.output.span(),
932-
"failed to get output type of async function"
933-
)
934-
})
935-
.skip_binder()
927+
infcx.get_impl_future_output_ty(ty).unwrap_or_else(|| {
928+
span_bug!(
929+
fn_decl.output.span(),
930+
"failed to get output type of async function"
931+
)
932+
})
936933
}
937934
hir::IsAsync::NotAsync => ty,
938935
};

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19521952
span: Span,
19531953
) {
19541954
let output_ty = match self.get_impl_future_output_ty(ty) {
1955-
Some(output_ty) => self.resolve_vars_if_possible(output_ty).skip_binder(),
1955+
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
19561956
_ => return,
19571957
};
19581958
let method_exists = self.method_exists(item_name, output_ty, call.hir_id, true);

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

+14-19
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use rustc_middle::dep_graph::DepContext;
7474
use rustc_middle::ty::print::with_no_trimmed_paths;
7575
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
7676
use rustc_middle::ty::{
77-
self, error::TypeError, Binder, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
77+
self, error::TypeError, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
7878
TypeVisitable,
7979
};
8080
use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span};
@@ -339,16 +339,15 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
339339
}
340340

341341
impl<'tcx> InferCtxt<'tcx> {
342-
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Binder<'tcx, Ty<'tcx>>> {
343-
if let ty::Opaque(def_id, substs) = ty.kind() {
344-
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
345-
// Future::Output
346-
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
342+
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
343+
let ty::Opaque(def_id, substs) = *ty.kind() else { return None; };
347344

348-
let bounds = self.tcx.bound_explicit_item_bounds(*def_id);
345+
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
346+
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
349347

350-
for (predicate, _) in bounds.subst_iter_copied(self.tcx, substs) {
351-
let output = predicate
348+
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs).find_map(
349+
|(predicate, _)| {
350+
predicate
352351
.kind()
353352
.map_bound(|kind| match kind {
354353
ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate))
@@ -358,14 +357,10 @@ impl<'tcx> InferCtxt<'tcx> {
358357
}
359358
_ => None,
360359
})
361-
.transpose();
362-
if output.is_some() {
363-
// We don't account for multiple `Future::Output = Ty` constraints.
364-
return output;
365-
}
366-
}
367-
}
368-
None
360+
.no_bound_vars()
361+
.flatten()
362+
},
363+
)
369364
}
370365
}
371366

@@ -2055,8 +2050,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20552050
}
20562051

20572052
match (
2058-
self.get_impl_future_output_ty(exp_found.expected).map(Binder::skip_binder),
2059-
self.get_impl_future_output_ty(exp_found.found).map(Binder::skip_binder),
2053+
self.get_impl_future_output_ty(exp_found.expected),
2054+
self.get_impl_future_output_ty(exp_found.found),
20602055
) {
20612056
(Some(exp), Some(found)) if self.same_type_modulo_infer(exp, found) => match cause
20622057
.code()

0 commit comments

Comments
 (0)