Structurally resolve before checking never

This commit is contained in:
Michael Goulet 2024-11-26 23:18:02 +00:00
parent f2abf827c1
commit 72cd7ac4f1
2 changed files with 26 additions and 2 deletions

View File

@ -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,
@ -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));
}

View File

@ -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();
}