Replace infers and non-rigid aliases with `Ty/Const::Error` if param env normalization fails
Fixesrust-lang/rust#160196Fixesrust-lang/rust#148630
Previously we use unnormalized param env if we fail to normalize it. This causes problem for places which expect normalized param env, like in lexical region solving.
I also sneak in a one-line change that we resolve regions with normalized param env in param env normalization now.
This fixes ICEs in `polkadot` and `zerocopy` which had non-rigid const aliases in type outlive env before. I can split it into another PR if that's preferred.
r? lcnr
check if len of array const arg matches the expected len of the type when lowering to valtree
When creating valtrees for arrays passed as const args in `lower_const_arg_array`, we assume the array has the correct length without actually checking the length of the arg, leading to UB at runtime (rust-lang/rust#155168) or an ICE during CTFE (rust-lang/rust#151079). This PR adds a check comparing the expected length of the type with the actual number of elements, similar to `lower_const_arg_tup`.
fixesrust-lang/rust#155168
The test was removed on the assumption that it no longer crashed the compiler,
but it still does, both on the nightly the issue was reported against and on
current master. The assertion has since moved out of the debug info code and
into `normalize_erasing_regions`, but it is the same one.
Fix avoid cycle for self referential return type notation
Fixesrust-lang/rust#159892 and rust-lang/rust#133613
we had to preserve and restore shadowed parameters in the impl trait overcapture lint and convert the resolved crash regression into a normal UI test which is applied to this patch
interpret: properly check for inhabitedness of nested references
This implements the opsem from the ongoing FCP in https://github.com/rust-lang/unsafe-code-guidelines/issues/413. The bit we were previously missing is that transmuting a `&&!` into existence was not caught as being immediate UB -- only the `&!` case behaved as expected.
I did not adjust the layout computation because when we compute the layout of `&T`, we cannot know the layout of `T` (as that might be recursive).
r? @oli-obk
the old solver doesn't register `TypeOutlives` and `RegionOutlives` goals if `ignoring_regions` is set. The new solver always registers these requirements, so we instead ignore errors caused by these constraints.
Moreover, in `probe_single_bound_for_assoc_item` unconditionally return
an `Err(_)` if there's more than a single bound (aka ambiguity) instead
of returning the first bound in some cases. This avoids triggering a
debug assertion later on ("not enough bound vars"). See the added test
for details.
Fix ICE in borrowck mutability suggestion with multi-byte ref sigil
Fixesrust-lang/rust#139089
Similarly to rust-lang/rust#155068, this is another instance where span arithmetic did not account for multi-byte characters. (Note that the ampersand in the test is full-width)
This change also results in correcting some inappropriate suggestions.
Emit fatal on invalid const args with nested defs
Fixed https://github.com/rust-lang/rust/issues/123629
Fixes https://github.com/rust-lang/rust/issues/154539
Invalid const args are rejected, so their surrounding HIR is not preserved. But nested defs inside them can still get created, leaving children lowered without a valid HIR parent and causing an ICE when later error handling walks HIR parents.
r? @BoxyUwU
Avoid ICE when param-env normalization leaves unresolved inference variables
Fixesrust-lang/rust#153354
Because the impl is already ill-formed, those variables are not fully constrained, so zfully_resolve` fails. We previously treated that as an immediate compiler bug with `span_bug!`, which caused an ICE on invalid input.
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by https://github.com/rust-lang/rust/pull/148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
The ICE fix appears to be unsound, causing a miscompilation involving
`dyn Trait` and `async {}` which induces segfaults in safe Rust code.
As the patch only hid an ICE, it does not seem worth the risk.
This reverts commit 8afd63610b, reversing
changes made to 19122c03c7.