This PR solves #21559 by making sure that unreachable if-expressions are not further translated.
Could someone who knows their way around `trans` take a look at the changes in `controlflow.rs`? I'm not sure if any other code relies on any side-effects of translating unreachable things.
cc @nikomatsakis @nrc @eddyb
for `Box<FnBox()>`. I found the alias was still handy because it is
shorter than the fully written type.
This is a [breaking-change]: convert code using `Invoke` to use `FnBox`,
which is usually pretty straight-forward. Code using thunk mostly works
if you change `Thunk::new => Box::new` and `foo.invoke(arg)` to
`foo(arg)`.
local only if matches `FUNDAMENTAL(LocalType)`, where `FUNDAMENTAL`
includes `&T` and types marked as fundamental (which includes `Box`).
Also apply these tests to negative reasoning.
case where `None` was returned should never happen in practice; it
amounts to comparing regions from two unrelated hierarchies. (I was also
not able to make it happen.)
const_eval : add overflow-checking for {`+`, `-`, `*`, `/`, `<<`, `>>`}.
One tricky detail here: There is some duplication of labor between `rustc::middle::const_eval` and `rustc_trans::trans::consts`. It might be good to explore ways to try to factor out the common structure to the two passes (by abstracting over the particular value-representation used in the compile-time interpreter).
----
Update: Rebased atop #23841Fix#22531Fix#23030Fix#23221Fix#23235
The overflow-checking attempts to accommodate early evaluation where
we do not have type information yet.
Also, add fixme note about something that has been bothering me.
Add option-returning variants to `const_to_int`/`const_to_uint` that
never assert fail. (These will be used for overflow checking from
rustc_trans::trans::consts.)
Moved such overflow checking into one place (in `rustc::middle::ty`,
since it needs to be run on-demand during `const_eval` in some
scenarios), and revised `rustc_typeck` accordingly.
(Note that we only check for overflow if program did not provide a
discriminant value explicitly.)
Fix#23030Fix#23221Fix#23235