const checking: properly compute the set of transient locals
For const-checking the MIR of a const/static initializer, we have to know the set of "transient" locals. The reason for this is that creating a mutable (or interior mutable) reference to a transient local is "safe" in the sense that this reference cannot possibly end up in the final value of the const -- even if it is turned into a raw pointer and stored in a union, we will see that pointer during interning and reliably reject it as dangling.
So far, we determined the set of transient locals as "locals that have a `StorageDead` somewhere". But that's not quite right -- if we had MIR like
```rust
StorageLive(_5);
StorageDead(_5);
StorageLive(_5);
// no further storage annotations for _5
```
Then we'd consider `_5` to be "transient", but it is not actually transient.
We do not currently generate such MIR, but I feel uneasy relying on subtle invariants like this. So this PR implements a proper analysis for computing the set of "transient" locals: a local is "transient" if it is guaranteed dead at all `Return` terminators.
Cc `@cjgillot`
Rollup of 9 pull requests
Successful merges:
- #129288 (Use subtyping for `UnsafeFnPointer` coercion, too)
- #129405 (Fixing span manipulation and indentation of the suggestion introduced by #126187)
- #129518 (gitignore: ignore ICE reports regardless of directory)
- #129519 (Remove redundant flags from `lower_ty_common` that can be inferred from the HIR)
- #129525 (rustdoc: clean up tuple <-> primitive conversion docs)
- #129526 (Use `FxHasher` on new solver unconditionally)
- #129544 (Removes dead code from the compiler)
- #129553 (add back test for stable-const-can-only-call-stable-const)
- #129590 (Avoid taking reference of &TyKind)
r? `@ghost`
`@rustbot` modify labels: rollup
add back test for stable-const-can-only-call-stable-const
This got accidentally removed in https://github.com/rust-lang/rust/pull/128596 (file `tests/ui/internal/internal-unstable-const.rs`). The test has little to do with "allow internal unstable" though, so add it in a file that already tests various const stability things.
Also tweak the help that suggests to add `rustc_allow_const_fn_unstable` to make it clear that this needs team approval, since it is a fairly big gun.
Use `FxHasher` on new solver unconditionally
r? lqd
This should actually fix the inference problem in ad855fe6db, since `HashSet::default` was not inferring the hasher when `HashSet` was coming from the stdlib due to the way that defaulted types/inference vars work. You could cherry-pick this on top of your PR alternatively.
rustdoc: clean up tuple <-> primitive conversion docs
This adds a minor missing feature to `fake_variadic`, so that it can render `impl From<(T,)> for [T; 1]` correctly.
Remove redundant flags from `lower_ty_common` that can be inferred from the HIR
...and then get rid of `lower_ty_common`.
r? ``@fmease`` or re-roll if you're busy!
gitignore: ignore ICE reports regardless of directory
Quite often when working on compiler I end up running into ICEs during the standard library compilation.
These ICEs generate reports in `/library/` and not at the root of the repo, so they aren't `gitignore`d.
I finally ended up committing one today, by accident: https://github.com/rust-lang/rust/pull/129487#event-14002067843
Use subtyping for `UnsafeFnPointer` coercion, too
I overlooked this in #129059, which changed MIR typechecking to use subtyping for other fn pointer coercions.
Fixes#129285
Make `rustc_type_ir` build on stable
This PR fixes a handful of issues that appear in `rustc_type_ir` when trying to build the new solver on stable.
r? ```@compiler-errors```
```@bors``` rollup
handle stage0 `cargo` and `rustc` separately
This change allows setting either `build.cargo` or `build.rustc` without requiring both to be set simultaneously, which was not possible previously.
To try it, set `build.rustc` without setting `build.cargo`, and try to bootstrap on clean build.
Blocker for https://github.com/rust-lang/rust/pull/129152
library: Move unstable API of new_uninit to new features
- `new_zeroed` variants move to `new_zeroed_alloc`
- the `write` fn moves to `box_uninit_write`
The remainder will be stabilized in upcoming patches, as it was decided to only stabilize `uninit*` and `assume_init`.
Build `library/profiler_builtins` from `ci-llvm` if appropriate
Running all of `tests/coverage` requires the LLVM profiler runtime, which requires setting `build.profiler = true`.
Historically, doing that has required checking out the entire `src/llvm-project` submodule. For compiler contributors who otherwise don't need that submodule (thanks to `download-ci-vm`), that's quite inconvenient.
However, thanks to #129116, the downloaded CI LLVM tarball now contains a copy of LLVM's `compiler-rt` directory, which includes all the files needed to build the profiler runtime. So with a little bit of extra logic in bootstrap, we can have `library/profiler_builtins` look for the `compiler-rt` files in `ci-llvm` instead of the `src/llvm-project` submodule.
Rollup of 10 pull requests
Successful merges:
- #128467 (Detect `*` operator on `!Sized` expression)
- #128524 (Don't suggest turning crate-level attributes into outer style)
- #128735 (Add a special case for `CStr`/`CString` in the `improper_ctypes` lint)
- #129429 (Print the generic parameter along with the variance in dumps.)
- #129430 (rustdoc: show exact case-sensitive matches first)
- #129449 (Put Pin::as_deref_mut in impl Pin<Ptr> / rearrange Pin methods)
- #129481 (Update `compiler_builtins` to `0.1.121`)
- #129482 (Add myself to the review rotation for libs)
- #129492 (Make wasm32 platform support docs easier to read)
- #129512 (update the doc comment on lintchecker b/c it parses html now)
r? `@ghost`
`@rustbot` modify labels: rollup
Put Pin::as_deref_mut in impl Pin<Ptr> / rearrange Pin methods
Tracking issue: #86918
Based on the suggestion in https://github.com/rust-lang/rust/issues/86918#issuecomment-2189367582
> Some advantages:
>
> * Synergy with the existing `as_ref` and `as_mut` signatures (stable since Rust 1.33)
>
> * Lifetime elision reduces noise in the signature
>
> * Turbofish less verbose: `Pin::<&mut T>::as_deref_mut` vs `Pin::<&mut Pin<&mut T>>::as_deref_mut`
The comment seemed to imply that `Pin::as_ref` and `Pin::as_mut` already share an impl block, which they don't. So, I rearranged it so that they do, and we can see which looks better in the docs.
<details><summary><b>Docs screenshots</b></summary>
Current nightly:
![image](https://github.com/user-attachments/assets/b432cb82-8f4b-48ae-bafc-2fe49d0ad48c)
`Pin::as_deref_mut` moved into the same block as `as_mut`:
![image](https://github.com/user-attachments/assets/f9b35722-6a88-4465-ad1c-28d8e91902ac)
`Pin::as_ref`, `as_mut`, and `as_deref_mut` all in the same block:
![image](https://github.com/user-attachments/assets/9a1b2bf0-70a6-4751-b13f-390f1d575244)
</details>
I think I like the last one the most; obviously I'm biased since I'm the one who rearranged it, but it doesn't make sense to me to have `as_ref` methods split up by an `into_inner` method.
r? dtolnay
Print the generic parameter along with the variance in dumps.
This allows to make sure we are testing what we think we are testing.
While the tests are correct, I discovered that opaque duplicated args are in the reverse declaration order.
Add a special case for `CStr`/`CString` in the `improper_ctypes` lint
Revives #120176. Just needed to bless a test and fix an argument, but seemed reasonable to me otherwise.
Instead of saying to "consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct", we now tell users to "Use `*const ffi::c_char` instead, and pass the value from `CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.
The suggestion is not made for `&mut CString` or `*mut CString`.
r? ``````@cjgillot`````` (since you were the reviewer of the original PR #120176, but feel free to reroll)
Detect `*` operator on `!Sized` expression
The suggestion is new:
```
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/unsized-str-in-return-expr-arg-and-local.rs:15:9
|
LL | let x = *"";
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature
help: references to `!Sized` types like `&str` are `Sized`; consider not dereferencing the expression
|
LL - let x = *"";
LL + let x = "";
|
```
Fix#128199.