Skip to content

Commit 94d6a9a

Browse files
committed
This can't happen anymore. An opaque type can't end up with itself as its hidden type
1 parent 3146c96 commit 94d6a9a

File tree

1 file changed

+4
-37
lines changed
  • compiler/rustc_borrowck/src/type_check

1 file changed

+4
-37
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ pub(crate) fn type_check<'mir, 'tcx>(
193193
let opaque_type_values =
194194
infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
195195

196-
let opaque_type_values = opaque_type_values
196+
opaque_type_values
197197
.into_iter()
198-
.filter_map(|(opaque_type_key, decl)| {
198+
.map(|(opaque_type_key, decl)| {
199199
cx.fully_perform_op(
200200
Locations::All(body.span),
201201
ConstraintCategory::OpaqueType,
@@ -226,43 +226,10 @@ pub(crate) fn type_check<'mir, 'tcx>(
226226
);
227227
hidden_type = infcx.tcx.ty_error();
228228
}
229-
let concrete_is_opaque = if let ty::Opaque(def_id, _) = hidden_type.kind() {
230-
*def_id == opaque_type_key.def_id
231-
} else {
232-
false
233-
};
234229

235-
if concrete_is_opaque {
236-
// We're using an opaque `impl Trait` type without
237-
// 'revealing' it. For example, code like this:
238-
//
239-
// type Foo = impl Debug;
240-
// fn foo1() -> Foo { ... }
241-
// fn foo2() -> Foo { foo1() }
242-
//
243-
// In `foo2`, we're not revealing the type of `Foo` - we're
244-
// just treating it as the opaque type.
245-
//
246-
// When this occurs, we do *not* want to try to equate
247-
// the concrete type with the underlying defining type
248-
// of the opaque type - this will always fail, since
249-
// the defining type of an opaque type is always
250-
// some other type (e.g. not itself)
251-
// Essentially, none of the normal obligations apply here -
252-
// we're just passing around some unknown opaque type,
253-
// without actually looking at the underlying type it
254-
// gets 'revealed' into
255-
debug!(
256-
"eq_opaque_type_and_type: non-defining use of {:?}",
257-
opaque_type_key.def_id,
258-
);
259-
None
260-
} else {
261-
Some((opaque_type_key, (hidden_type, decl.hidden_type.span, decl.origin)))
262-
}
230+
(opaque_type_key, (hidden_type, decl.hidden_type.span, decl.origin))
263231
})
264-
.collect();
265-
opaque_type_values
232+
.collect()
266233
},
267234
);
268235

0 commit comments

Comments
 (0)