Skip to content

Commit 72cd7ac

Browse files
Structurally resolve before checking never
1 parent f2abf82 commit 72cd7ac

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6868

6969
// While we don't allow *arbitrary* coercions here, we *do* allow
7070
// coercions from ! to `expected`.
71-
if ty.is_never() && self.expr_guaranteed_to_constitute_read_for_never(expr) {
71+
if self.try_structurally_resolve_type(expr.span, ty).is_never()
72+
&& self.expr_guaranteed_to_constitute_read_for_never(expr)
73+
{
7274
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
7375
let reported = self.dcx().span_delayed_bug(
7476
expr.span,
@@ -274,7 +276,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
274276
// unless it's a place expression that isn't being read from, in which case
275277
// diverging would be unsound since we may never actually read the `!`.
276278
// e.g. `let _ = *never_ptr;` with `never_ptr: *const !`.
277-
if ty.is_never() && self.expr_guaranteed_to_constitute_read_for_never(expr) {
279+
if self.try_structurally_resolve_type(expr.span, ty).is_never()
280+
&& self.expr_guaranteed_to_constitute_read_for_never(expr)
281+
{
278282
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
279283
}
280284

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ check-pass
2+
//@ compile-flags: -Znext-solver
3+
4+
#![feature(never_type)]
5+
6+
trait Mirror {
7+
type Assoc;
8+
}
9+
impl<T> Mirror for T {
10+
type Assoc = T;
11+
}
12+
13+
fn diverge() -> <! as Mirror>::Assoc { todo!() }
14+
15+
fn main() {
16+
let close = || {
17+
diverge();
18+
};
19+
let x: u32 = close();
20+
}

0 commit comments

Comments
 (0)