summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_typeck/src/closure.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_hir_typeck/src/closure.rs')
-rw-r--r--compiler/rustc_hir_typeck/src/closure.rs51
1 files changed, 26 insertions, 25 deletions
diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs
index d84fabb78..8c2495e1d 100644
--- a/compiler/rustc_hir_typeck/src/closure.rs
+++ b/compiler/rustc_hir_typeck/src/closure.rs
@@ -2,13 +2,12 @@
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
-use hir::def::DefKind;
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_hir_analysis::astconv::AstConv;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
-use rustc_infer::infer::LateBoundRegionConversionTime;
+use rustc_infer::infer::{DefineOpaqueTypes, LateBoundRegionConversionTime};
use rustc_infer::infer::{InferOk, InferResult};
use rustc_macros::{TypeFoldable, TypeVisitable};
use rustc_middle::ty::subst::InternalSubsts;
@@ -205,15 +204,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut expected_sig = None;
let mut expected_kind = None;
- for obligation in traits::elaborate_predicates_with_span(
+ for (pred, span) in traits::elaborate(
self.tcx,
// Reverse the obligations here, since `elaborate_*` uses a stack,
// and we want to keep inference generally in the same order of
// the registered obligations.
predicates.rev(),
- ) {
- debug!(?obligation.predicate);
- let bound_predicate = obligation.predicate.kind();
+ )
+ // We only care about self bounds
+ .filter_only_self()
+ {
+ debug!(?pred);
+ let bound_predicate = pred.kind();
// Given a Projection predicate, we can potentially infer
// the complete signature.
@@ -221,9 +223,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let ty::PredicateKind::Clause(ty::Clause::Projection(proj_predicate)) = bound_predicate.skip_binder()
{
let inferred_sig = self.normalize(
- obligation.cause.span,
+ span,
self.deduce_sig_from_projection(
- Some(obligation.cause.span),
+ Some(span),
bound_predicate.rebind(proj_predicate),
),
);
@@ -398,7 +400,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
///
/// Here:
/// - E would be `fn(&u32) -> &u32`.
- /// - S would be `fn(&u32) ->
+ /// - S would be `fn(&u32) -> ?T`
/// - E' is `&'!0 u32 -> &'!0 u32`
/// - S' is `&'?0 u32 -> ?T`
///
@@ -563,10 +565,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
// Check that E' = S'.
let cause = self.misc(hir_ty.span);
- let InferOk { value: (), obligations } = self
- .at(&cause, self.param_env)
- .define_opaque_types(true)
- .eq(*expected_ty, supplied_ty)?;
+ let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq(
+ DefineOpaqueTypes::Yes,
+ *expected_ty,
+ supplied_ty,
+ )?;
all_obligations.extend(obligations);
}
@@ -576,10 +579,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
supplied_sig.output(),
);
let cause = &self.misc(decl.output.span());
- let InferOk { value: (), obligations } = self
- .at(cause, self.param_env)
- .define_opaque_types(true)
- .eq(expected_sigs.liberated_sig.output(), supplied_output_ty)?;
+ let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq(
+ DefineOpaqueTypes::Yes,
+ expected_sigs.liberated_sig.output(),
+ supplied_output_ty,
+ )?;
all_obligations.extend(obligations);
let inputs = inputs.into_iter().map(|ty| self.resolve_vars_if_possible(ty));
@@ -713,14 +717,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.subst_iter_copied(self.tcx, substs)
.find_map(|(p, s)| get_future_output(p, s))?,
ty::Error(_) => return None,
- ty::Alias(ty::Projection, proj)
- if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
- {
- self.tcx
- .bound_explicit_item_bounds(proj.def_id)
- .subst_iter_copied(self.tcx, proj.substs)
- .find_map(|(p, s)| get_future_output(p, s))?
- }
+ ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
+ .tcx
+ .bound_explicit_item_bounds(proj.def_id)
+ .subst_iter_copied(self.tcx, proj.substs)
+ .find_map(|(p, s)| get_future_output(p, s))?,
_ => span_bug!(
self.tcx.def_span(expr_def_id),
"async fn generator return type not an inference variable: {ret_ty}"