Remove unnecessary binder from get_impl_future_output_ty
This commit is contained in:
parent
aff003becd
commit
1472b38039
4 changed files with 23 additions and 34 deletions
|
@ -2333,12 +2333,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
base: &'tcx hir::Expr<'tcx>,
|
base: &'tcx hir::Expr<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) {
|
) {
|
||||||
let output_ty = match self.get_impl_future_output_ty(ty) {
|
let Some(output_ty) = self.get_impl_future_output_ty(ty) else { return; };
|
||||||
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
|
|
||||||
_ => return,
|
|
||||||
};
|
|
||||||
let mut add_label = true;
|
let mut add_label = true;
|
||||||
if let ty::Adt(def, _) = output_ty.skip_binder().kind() {
|
if let ty::Adt(def, _) = output_ty.kind() {
|
||||||
// no field access on enum type
|
// no field access on enum type
|
||||||
if !def.is_enum() {
|
if !def.is_enum() {
|
||||||
if def
|
if def
|
||||||
|
|
|
@ -925,15 +925,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let ty = match self.tcx.asyncness(fn_id.owner) {
|
let ty = match self.tcx.asyncness(fn_id.owner) {
|
||||||
hir::IsAsync::Async => {
|
hir::IsAsync::Async => {
|
||||||
let infcx = self.tcx.infer_ctxt().build();
|
let infcx = self.tcx.infer_ctxt().build();
|
||||||
infcx
|
infcx.get_impl_future_output_ty(ty).unwrap_or_else(|| {
|
||||||
.get_impl_future_output_ty(ty)
|
span_bug!(
|
||||||
.unwrap_or_else(|| {
|
fn_decl.output.span(),
|
||||||
span_bug!(
|
"failed to get output type of async function"
|
||||||
fn_decl.output.span(),
|
)
|
||||||
"failed to get output type of async function"
|
})
|
||||||
)
|
|
||||||
})
|
|
||||||
.skip_binder()
|
|
||||||
}
|
}
|
||||||
hir::IsAsync::NotAsync => ty,
|
hir::IsAsync::NotAsync => ty,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1960,7 +1960,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
) {
|
) {
|
||||||
let output_ty = match self.get_impl_future_output_ty(ty) {
|
let output_ty = match self.get_impl_future_output_ty(ty) {
|
||||||
Some(output_ty) => self.resolve_vars_if_possible(output_ty).skip_binder(),
|
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
let method_exists = self.method_exists(item_name, output_ty, call.hir_id, true);
|
let method_exists = self.method_exists(item_name, output_ty, call.hir_id, true);
|
||||||
|
|
|
@ -74,7 +74,7 @@ use rustc_middle::dep_graph::DepContext;
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
|
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, error::TypeError, Binder, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
|
self, error::TypeError, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
|
||||||
TypeVisitable,
|
TypeVisitable,
|
||||||
};
|
};
|
||||||
use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span};
|
use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span};
|
||||||
|
@ -339,16 +339,15 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> InferCtxt<'tcx> {
|
impl<'tcx> InferCtxt<'tcx> {
|
||||||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Binder<'tcx, Ty<'tcx>>> {
|
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||||
if let ty::Opaque(def_id, substs) = ty.kind() {
|
let ty::Opaque(def_id, substs) = *ty.kind() else { return None; };
|
||||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
|
||||||
// Future::Output
|
|
||||||
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
|
|
||||||
|
|
||||||
let bounds = self.tcx.bound_explicit_item_bounds(*def_id);
|
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
||||||
|
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
|
||||||
|
|
||||||
for (predicate, _) in bounds.subst_iter_copied(self.tcx, substs) {
|
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs).find_map(
|
||||||
let output = predicate
|
|(predicate, _)| {
|
||||||
|
predicate
|
||||||
.kind()
|
.kind()
|
||||||
.map_bound(|kind| match kind {
|
.map_bound(|kind| match kind {
|
||||||
ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate))
|
ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate))
|
||||||
|
@ -358,14 +357,10 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.transpose();
|
.no_bound_vars()
|
||||||
if output.is_some() {
|
.flatten()
|
||||||
// We don't account for multiple `Future::Output = Ty` constraints.
|
},
|
||||||
return output;
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2055,8 +2050,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match (
|
match (
|
||||||
self.get_impl_future_output_ty(exp_found.expected).map(Binder::skip_binder),
|
self.get_impl_future_output_ty(exp_found.expected),
|
||||||
self.get_impl_future_output_ty(exp_found.found).map(Binder::skip_binder),
|
self.get_impl_future_output_ty(exp_found.found),
|
||||||
) {
|
) {
|
||||||
(Some(exp), Some(found)) if self.same_type_modulo_infer(exp, found) => match cause
|
(Some(exp), Some(found)) if self.same_type_modulo_infer(exp, found) => match cause
|
||||||
.code()
|
.code()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue