Allow coercions from never-type when ref binding is involved by Aaron1011 · Pull Request #118270 · rust-lang/rust (original) (raw)
@RalfJung to make sure I understand you correctly:
First a question: is there currently a consensus whether a place expression of type ! is unreachable? Afaict the consensus is that it is not. A place of type ! is totally acceptable and only causes UB when converted to a value. let _ = *(&1 as *const u32 as *const !); is not UB.
It's not at all clear to me that
let ref x = exprshould be constructing a value -- AFAIK it is equivalent tolet x = &expr, which evaluatesexpras a place only.For
let Foo { ref my_field } = expr;, that seems equivalent tolet my_field = &expr.my_field.expris in place position here so again, I don't think this constructs a value.
You believe that let ref var = place_expr does not convert place_expr to a value and neither does let Foo { ref my_field } = *raw_ptr;.
You therefore believe that the PR as is is not desirable. We should only apply coercions from ! to any other type if the source is an expression, not a place?
Assuming that 1) we have not yet decided that a place of type ! is UB (or even decided the opposite) and 2) this PR would result in coercions from places to pattern to be unique for ! by adding a place_to_value conversion not present for other types:
@rfcbot concern coerce place vs value
I am not confident that I fully understand what is going on here and how this fits into the greater picture, but I would like to definitely involve @rust-lang/opsem to make sure the behavior here is consistent