Create promoted MIR fragments for `const` and `static`s
Resolves#65732.
The previous strategy of removing `Drop` and `StorageDead` for promoted locals only worked for rvalue lifetime extension and only if no `loop`s were present. This PR applies the approach currently used for `fn` and `const fn`s to `const` and `statics`.
This may have some performance impacts.
r? @eddyb
Simplify memory categorization
With AST borrowck gone, mem_categorization can be simplified, a lot.
* `cmt_` is now called `Place`. Most local variable names have been updated to reflect this, but the `cat_*` methods retain their names.
* `MemCategorizationContext` no longer needs a `ScopeTree` and always needs an `InferCtxt`.
* `Place` now uses a similar representation to `mir::Place` with a `Vec` of projections.
* `Upvar` places don't include the implicit environment and capture derefs. These are now handled by `regionck` when needed.
* Various types, methods and variants only used by AST borrowck have been removed.
* `ExprUseVisitor` now lives in `rustc_typeck::expr_use_visitor`.
* `MemCategorizationContext` and `Place` live in `rustc_typeck::mem_categorization`.
* `Place` is re-exported in `rustc_typeck::expr_use_visitor` so that Clippy can access it.
The loss of an error in `issue-4335.rs` is due to a change in capture inference in ill-formed programs. If any projection from a variable is moved from then we capture that variable by move, whether or not the place being moved from allows this.
Closes#66270
Add memoization for const function evaluations
When a const function is being evaluated, as long as all its arguments are zero-sized-types (or it has no arguments) then we can trivially memoize the evaluation result using the existing query mechanism.
With thanks to @oli-obk for mentoring me through this at RustFest Barcelona.
r? @oli-obk
Implement Debug for MaybeUninit
Precedent: `UnsafeCell` implements `Debug` even though it can't actually display the value. I noticed this omission while writing the following:
```
#[derive(Debug)]
pub struct SliceInitializer<'a, T> {
marker: PhantomData<&'a mut T>,
uninit: &'a mut [MaybeUninit<T>],
written: usize,
}
```
...which currently unergonomically fails to compile.
`UnsafeCell` does require `T: Debug`. Because of things like the above I think it'd be better to leave that requirement off. In fact, I'd also suggest removing that requirement for `UnsafeCell` too, which again I noticed in some low-level real world code.
Rollup of 17 pull requests
Successful merges:
- #64325 (Stabilize nested self receivers in 1.41.0)
- #66222 (Use `eq_opaque_type_and_type` when type-checking closure signatures)
- #66305 (Add by-value arrays to `improper_ctypes` lint)
- #66399 (rustc_metadata: simplify the interactions between Lazy and Table.)
- #66534 (Allow global references via ForeignItem and Item for the same symbol name during LLVM codegen)
- #66700 (Fix pointing at arg for fulfillment errors in function calls)
- #66704 (Intra doc enum variant field)
- #66718 (Refactor `parse_enum_item` to use `parse_delim_comma_seq`)
- #66722 (Handle non_exhaustive in borrow checking)
- #66744 (Fix shrink_to panic documentation)
- #66761 (Use LLVMDisposePassManager instead of raw delete in rustllvm)
- #66769 (Add core::{f32,f64}::consts::TAU.)
- #66774 (Clean up error codes)
- #66777 (Put back tidy check on error codes)
- #66797 (Fixes small typo in array docs r? @steveklabnik)
- #66798 (Fix spelling typos)
- #66800 (Combine similar tests for const match)
Failed merges:
r? @ghost
Fixes small typo in array docs r? @steveklabnik
Fixes a small typo in the array documentation.
Also, wasn't sure which [message](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#pull-requests) to put this in, and will definitely update the commit message if it is supposed to be the PR description but for "safety" - r? @steveklabnik
Put back tidy check on error codes
I just realized that the tidy checks were not run anymore on the error code long explanations. This add it back.
cc @Dylan-DPC
r? @Mark-Simulacrum
Use LLVMDisposePassManager instead of raw delete in rustllvm
LLVM has a dedicated API call which wraps the destructor invocation for the PassManager.
Rust invokes it [otherwhere](d63b24ffcc/src/librustc_codegen_llvm/back/write.rs (L446-L447)), but not in the `LLVMRustWriteOutputFile`.
Since `LLVMDisposePassManager` might be extended to perform additional cleanup actions in the future, this change replaces raw destructor invocation with that API call.