Revert "Fix regression from lazy opaque types"
This reverts commit 239f1e716d
.
This commit is contained in:
parent
e646f3d2a9
commit
7a71b7a99e
7 changed files with 10 additions and 126 deletions
|
@ -259,7 +259,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
/// The `cause_span` should be the span that caused us to
|
||||
/// have this expected signature, or `None` if we can't readily
|
||||
/// know that.
|
||||
#[instrument(level = "debug", skip(self, cause_span))]
|
||||
fn deduce_sig_from_projection(
|
||||
&self,
|
||||
cause_span: Option<Span>,
|
||||
|
@ -267,13 +266,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
) -> Option<ExpectedSig<'tcx>> {
|
||||
let tcx = self.tcx;
|
||||
|
||||
debug!("deduce_sig_from_projection({:?})", projection);
|
||||
|
||||
let trait_def_id = projection.trait_def_id(tcx);
|
||||
|
||||
let is_fn = tcx.fn_trait_kind_from_lang_item(trait_def_id).is_some();
|
||||
let gen_trait = tcx.require_lang_item(LangItem::Generator, cause_span);
|
||||
let is_gen = gen_trait == trait_def_id;
|
||||
if !is_fn && !is_gen {
|
||||
debug!("not fn or generator");
|
||||
debug!("deduce_sig_from_projection: not fn or generator");
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -282,7 +283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// associated item and not yield.
|
||||
let return_assoc_item = self.tcx.associated_item_def_ids(gen_trait)[1];
|
||||
if return_assoc_item != projection.projection_def_id() {
|
||||
debug!("not return assoc item of generator");
|
||||
debug!("deduce_sig_from_projection: not return assoc item of generator");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +291,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let input_tys = if is_fn {
|
||||
let arg_param_ty = projection.skip_binder().projection_ty.substs.type_at(1);
|
||||
let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty);
|
||||
debug!(?arg_param_ty);
|
||||
debug!("deduce_sig_from_projection: arg_param_ty={:?}", arg_param_ty);
|
||||
|
||||
match arg_param_ty.kind() {
|
||||
ty::Tuple(tys) => tys.into_iter().map(|k| k.expect_ty()).collect::<Vec<_>>(),
|
||||
|
@ -305,7 +306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// Since this is a return parameter type it is safe to unwrap.
|
||||
let ret_param_ty = projection.skip_binder().term.ty().unwrap();
|
||||
let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty);
|
||||
debug!(?ret_param_ty);
|
||||
debug!("deduce_sig_from_projection: ret_param_ty={:?}", ret_param_ty);
|
||||
|
||||
let sig = projection.rebind(self.tcx.mk_fn_sig(
|
||||
input_tys.iter(),
|
||||
|
@ -314,7 +315,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
hir::Unsafety::Normal,
|
||||
Abi::Rust,
|
||||
));
|
||||
debug!(?sig);
|
||||
debug!("deduce_sig_from_projection: sig={:?}", sig);
|
||||
|
||||
Some(ExpectedSig { cause_span, sig })
|
||||
}
|
||||
|
|
|
@ -730,32 +730,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
) -> Vec<Ty<'tcx>> {
|
||||
let formal_ret = self.resolve_vars_with_obligations(formal_ret);
|
||||
let ret_ty = match expected_ret.only_has_type(self) {
|
||||
Some(ret) => {
|
||||
// HACK(oli-obk): This is a backwards compatibility hack. Without it, the inference
|
||||
// variable will get instantiated with the opaque type. The inference variable often
|
||||
// has various helpful obligations registered for it that help closures figure out their
|
||||
// signature. If we infer the inference var to the opaque type, the closure won't be able
|
||||
// to find those obligations anymore, and it can't necessarily find them from the opaque
|
||||
// type itself. We could be more powerful with inference if we *combined* the obligations
|
||||
// so that we got both the obligations from the opaque type and the ones from the inference
|
||||
// variable. That will accept more code than we do right now, so we need to carefully consider
|
||||
// the implications.
|
||||
// Note: this check is pessimistic, as the inference type could be matched with something other
|
||||
// than the opaque type, but then we need a new `TypeRelation` just for this specific case and
|
||||
// can't re-use `sup` below.
|
||||
if formal_ret.has_infer_types() {
|
||||
for ty in ret.walk() {
|
||||
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack() {
|
||||
if let ty::Opaque(def_id, _) = *ty.kind() {
|
||||
if self.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() {
|
||||
return Vec::new();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
Some(ret) => ret,
|
||||
None => return Vec::new(),
|
||||
};
|
||||
let expect_args = self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue