Skip to content

Commit 7a71b7a

Browse files
committed
Revert "Fix regression from lazy opaque types"
This reverts commit 239f1e7.
1 parent e646f3d commit 7a71b7a

File tree

7 files changed

+10
-126
lines changed

7 files changed

+10
-126
lines changed

compiler/rustc_typeck/src/check/closure.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
259259
/// The `cause_span` should be the span that caused us to
260260
/// have this expected signature, or `None` if we can't readily
261261
/// know that.
262-
#[instrument(level = "debug", skip(self, cause_span))]
263262
fn deduce_sig_from_projection(
264263
&self,
265264
cause_span: Option<Span>,
266265
projection: ty::PolyProjectionPredicate<'tcx>,
267266
) -> Option<ExpectedSig<'tcx>> {
268267
let tcx = self.tcx;
269268

269+
debug!("deduce_sig_from_projection({:?})", projection);
270+
270271
let trait_def_id = projection.trait_def_id(tcx);
271272

272273
let is_fn = tcx.fn_trait_kind_from_lang_item(trait_def_id).is_some();
273274
let gen_trait = tcx.require_lang_item(LangItem::Generator, cause_span);
274275
let is_gen = gen_trait == trait_def_id;
275276
if !is_fn && !is_gen {
276-
debug!("not fn or generator");
277+
debug!("deduce_sig_from_projection: not fn or generator");
277278
return None;
278279
}
279280

@@ -282,15 +283,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
282283
// associated item and not yield.
283284
let return_assoc_item = self.tcx.associated_item_def_ids(gen_trait)[1];
284285
if return_assoc_item != projection.projection_def_id() {
285-
debug!("not return assoc item of generator");
286+
debug!("deduce_sig_from_projection: not return assoc item of generator");
286287
return None;
287288
}
288289
}
289290

290291
let input_tys = if is_fn {
291292
let arg_param_ty = projection.skip_binder().projection_ty.substs.type_at(1);
292293
let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty);
293-
debug!(?arg_param_ty);
294+
debug!("deduce_sig_from_projection: arg_param_ty={:?}", arg_param_ty);
294295

295296
match arg_param_ty.kind() {
296297
ty::Tuple(tys) => tys.into_iter().map(|k| k.expect_ty()).collect::<Vec<_>>(),
@@ -305,7 +306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
305306
// Since this is a return parameter type it is safe to unwrap.
306307
let ret_param_ty = projection.skip_binder().term.ty().unwrap();
307308
let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty);
308-
debug!(?ret_param_ty);
309+
debug!("deduce_sig_from_projection: ret_param_ty={:?}", ret_param_ty);
309310

310311
let sig = projection.rebind(self.tcx.mk_fn_sig(
311312
input_tys.iter(),
@@ -314,7 +315,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
314315
hir::Unsafety::Normal,
315316
Abi::Rust,
316317
));
317-
debug!(?sig);
318+
debug!("deduce_sig_from_projection: sig={:?}", sig);
318319

319320
Some(ExpectedSig { cause_span, sig })
320321
}

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -730,32 +730,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
730730
) -> Vec<Ty<'tcx>> {
731731
let formal_ret = self.resolve_vars_with_obligations(formal_ret);
732732
let ret_ty = match expected_ret.only_has_type(self) {
733-
Some(ret) => {
734-
// HACK(oli-obk): This is a backwards compatibility hack. Without it, the inference
735-
// variable will get instantiated with the opaque type. The inference variable often
736-
// has various helpful obligations registered for it that help closures figure out their
737-
// signature. If we infer the inference var to the opaque type, the closure won't be able
738-
// to find those obligations anymore, and it can't necessarily find them from the opaque
739-
// type itself. We could be more powerful with inference if we *combined* the obligations
740-
// so that we got both the obligations from the opaque type and the ones from the inference
741-
// variable. That will accept more code than we do right now, so we need to carefully consider
742-
// the implications.
743-
// Note: this check is pessimistic, as the inference type could be matched with something other
744-
// than the opaque type, but then we need a new `TypeRelation` just for this specific case and
745-
// can't re-use `sup` below.
746-
if formal_ret.has_infer_types() {
747-
for ty in ret.walk() {
748-
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack() {
749-
if let ty::Opaque(def_id, _) = *ty.kind() {
750-
if self.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() {
751-
return Vec::new();
752-
}
753-
}
754-
}
755-
}
756-
}
757-
ret
758-
}
733+
Some(ret) => ret,
759734
None => return Vec::new(),
760735
};
761736
let expect_args = self

src/test/ui/impl-trait/hidden-type-is-opaque-2.rs

-34
This file was deleted.

src/test/ui/impl-trait/hidden-type-is-opaque-2.stderr

-11
This file was deleted.

src/test/ui/impl-trait/hidden-type-is-opaque.rs

-32
This file was deleted.

src/test/ui/impl-trait/issues/issue-70877.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Iterator for Bar {
1313
type Item = FooItem;
1414

1515
fn next(&mut self) -> Option<Self::Item> {
16-
Some(Box::new(quux)) //~ ERROR mismatched types
16+
Some(Box::new(quux))
1717
}
1818
}
1919

Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/issue-70877.rs:16:9
3-
|
4-
LL | type FooRet = impl std::fmt::Debug;
5-
| -------------------- the expected opaque type
6-
...
7-
LL | fn next(&mut self) -> Option<Self::Item> {
8-
| ------------------ expected `Option<Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> FooRet + 'static)>>` because of return type
9-
LL | Some(Box::new(quux))
10-
| ^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn Fn`, found fn item
11-
|
12-
= note: expected enum `Option<Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> FooRet + 'static)>>`
13-
found enum `Option<Box<for<'r> fn(&'r (dyn ToString + 'r)) -> FooRet {quux}>>`
14-
151
error: opaque type's hidden type cannot be another opaque type from the same scope
162
--> $DIR/issue-70877.rs:31:12
173
|
@@ -29,6 +15,5 @@ note: opaque type being used as hidden type
2915
LL | type FooRet = impl std::fmt::Debug;
3016
| ^^^^^^^^^^^^^^^^^^^^
3117

32-
error: aborting due to 2 previous errors
18+
error: aborting due to previous error
3319

34-
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)