Skip to content

Commit

Permalink
Structurally resolve before checking never
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 27, 2024
1 parent f2abf82 commit 72cd7ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ check-pass
//@ compile-flags: -Znext-solver

#![feature(never_type)]

trait Mirror {
type Assoc;
}
impl<T> Mirror for T {
type Assoc = T;
}

fn diverge() -> <! as Mirror>::Assoc { todo!() }

fn main() {
let close = || {
diverge();
};
let x: u32 = close();
}

0 comments on commit 72cd7ac

Please sign in to comment.