Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#158168 (Added implementation on `set_permissions_nofollow` for all primary platforms)
- rust-lang/rust#160055 (Simplify `MaybeRequiresStorage`)
- rust-lang/rust#157226 (Partially stabilize `box_vec_non_null`)
- rust-lang/rust#158879 (simplify `slice::Iter[Mut]::next_chunk` implementation)
- rust-lang/rust#159413 (Enable `#[diagnostic::on_unknown]` during late res)
- rust-lang/rust#160091 (Fix rustdoc toolbar height when title is taller than one line)
- rust-lang/rust#158615 (fix: don't fire `explicit_outlives_requirements` on `?Sized` type params)
- rust-lang/rust#159666 (fix(ld64.lld): route version mismatch warnings to linker_info on macOS)
- rust-lang/rust#160032 (rustdoc-json: Make `Stability` compatible with non-self-describing serde formats)
- rust-lang/rust#160039 (Add regression test for enum unconstrained parameter )
- rust-lang/rust#160049 (Use assert_eq! in splat codegen tests)
rustdoc-json: Make `Stability` compatible with non-self-describing serde formats
Using `#[serde(flatten)]` and `#[serde(tag = "` break using rustdoc-json-types with serde serializers like postcard. rustdoc-json-types should work with these, even if rustdoc itself doesn't use this yet.
This is a breaking change to the `FORMAT_VERSION` even though rust reader/writer code is uneffected.
cc @obi1kenobi
r? @GuillaumeGomez
fix(ld64.lld): route version mismatch warnings to linker_info on macOS
r? jyn514
Fixesrust-lang/rust#159227
**Issue:** .o objects (e.g. precompiled stdlib .rlib files, C libraries compiled via cc-rs) receive MacOS version of the machine they were compiled on and that version is much higher than Rust's default deployment target for aarch64-apple-darwin which is macOS 11.0.0.
[`(Os::MacOs, crate::spec::Arch::AArch64, _) => (11, 0, 0)`](f65b272fc9/compiler/rustc_target/src/spec/base/apple/mod.rs (L332))
That’s why hundreds of warning logs appear such as warning: `linker stderr: rust-lld: /path/file.rlib(file.o) has version 26.4.1, which is newer than target minimum of 11.0.0`. These warnings were already filtered for ld64 and ld_prime but not for lld (see rust-lang/rust#136113).
**Root cause:** I believe that the current function `is_macos_ld()` in [compiler/rustc_codegen_ssa/src/back/link.rs](730a6b5dce/compiler/rustc_codegen_ssa/src/back/link.rs (L874)) handles the case when we use native macOS linker so the entire filtering chain in linker output is skipped when using ld64.lld. Relevant code:
```
fn is_macos_ld(sess: &Session) -> bool {
let (_, flavor) = linker_and_flavor(sess);
sess.target.is_like_darwin && matches!(flavor, LinkerFlavor::Darwin(_, Lld::No))
}
```
So, `Lld::No` means using native macOS linker, so when lld is used via `Lld::Yes`, the match fails and the function returns `false` hence all warnings come from stderr to linker_messages which are visible.
**My proposed solution:** modify filtering such that it runs for lld too and add a new specific ld64.lld warning pattern routing warnings to linker_info to make them invisible by default.
fix: don't fire `explicit_outlives_requirements` on `?Sized` type params
`explicit_outlives_requirements` uses `tcx.inferred_outlives_of()` to check whether an explicit `T: 'a` bound is structurally implied by struct fields. for a field `r: &'a T`, it is — so the lint fired and suggested removing it.
but RFC 599 object lifetime defaults are computed from *explicit* HIR bounds not inferred ones. removing an explicit `T: 'a` from a `?Sized` type param silently changes every `Struct<dyn Trait>` use from `dyn Trait + 'a` to `dyn Trait + 'static`, breaking callers without any error.
added a guard: before emitting the lint for a type param outlives bound, check whether the param carries any `?Sized` bound (`BoundPolarity::Maybe` in HIR). if so, skip — the bound may be the sole anchor for the object lifetime default.
also suppresses the pre-existing false positive in `edition-lint-infer-outlives.rs` (noted in issue https://github.com/rust-lang/rust/issues/105150) which was an instance of the same bug.
closes https://github.com/rust-lang/rust/issues/134902
Enable `#[diagnostic::on_unknown]` during late res
The pr prior to this is rust-lang/rust#157926. That PR enabled it for early res, this PR does so for late res.
r? @estebank
simplify `slice::Iter[Mut]::next_chunk` implementation
I verified that this doesn't pessimize codegen using the example from the PR that inroduced the optimization of `next_chunk` (rust-lang/rust#149131):
```rust
#![feature(iter_next_chunk)]
#[no_mangle]
pub fn simd_sum_slow(arr: &[u32]) -> u32 {
const STEP_SIZE: usize = 16;
let mut result = [0; STEP_SIZE];
let mut iter = arr.iter();
while let Ok(c) = iter.next_chunk::<STEP_SIZE>() {
for (&n, r) in c.iter().zip(result.iter_mut()) {
*r += n;
}
}
result.iter().sum()
}
```
I compiled this example with
```shell
./build/host/stage1/bin/rustc t.rs --emit=asm -O --crate-type=lib
```
Before and after this change; the only difference is the choice of the jump instruction, which I think shouldn't make any difference:
```diff
28,29c28,29
< cmpq $64, %rsi
< jae .LBB0_2
---
> cmpq $60, %rsi
> ja .LBB0_2
```
r? libs
cc @bend-n
Partially stabilize `box_vec_non_null`
Closesrust-lang/rust#130364
r? libs-api
### What's being stabilized
The following is being stabilized in this PR:
```rust
impl<T: ?Sized> Box<T> {
pub unsafe fn from_non_null(ptr: NonNull<T>) -> Self { .... }
pub fn into_non_null(b: Self) -> NonNull<T> { .... }
}
impl<T> Vec<T> {
pub const unsafe fn from_parts(ptr: NonNull<T>, length: usize, capacity: usize) -> Self { .... }
pub const fn into_parts(self) -> (NonNull<T>, usize, usize) { .... }
}
```
Note that `Vec::from_parts` and `Vec::into_parts` remain const-unstable behind the `const_heap` feature (like `Vec::from_raw_parts` and `Vec::into_raw_parts`).
The following APIs remain gated behind `allocator_api`
```rust
impl<T: ?Sized, A: Allocator> Box<T, A> {
pub unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self { .... }
pub fn into_non_null_with_allocator(b: Self) -> (NonNull<T>, A) { .... }
}
impl<T, A: Allocator> Vec<T, A> {
pub const unsafe fn from_parts_in(ptr: NonNull<T>, length: usize, capacity: usize, alloc: A) -> Self { .... }
pub const fn into_parts_with_alloc(self) -> (NonNull<T>, usize, usize, A) { .... }
}
```
The following API is split into a new unstable feature in rust-lang/rust#157843, and remains unstable:
```rust
impl<T, A: Allocator> Vec<T, A> {
pub const fn as_non_null(&mut self) -> NonNull<T> { .... }
}
```
### Implementation History
Most of this feature was ACP'ed in https://github.com/rust-lang/libs-team/issues/418, and implemented in https://github.com/rust-lang/rust/pull/130061. `Vec::as_non_null` was ACP'ed separately in https://github.com/rust-lang/libs-team/issues/440, and implemented in https://github.com/rust-lang/rust/pull/130624.
### Potential issues
* Should `Vec::from_parts` and `Vec::into_parts` be the name used for this? Or should those names be used for functions that take/return `Box<[MaybeUninit<T>]>`? (Raised at https://github.com/rust-lang/rust/issues/130364#issuecomment-2357276951)
* Should these function names be named `non_null` or `nonnull`? (Raised at https://github.com/rust-lang/rust/issues/130364#issuecomment-4525680948. See https://github.com/rust-lang/rust/issues/154237#issuecomment-4120073976.)
* Will the methods on `Vec` collide with anything via autoderef?
Simplify `MaybeRequiresStorage`
It currently contains a `MaybeBorrowedLocals` cursor. The cursor is within a `RefCell` because cursor traversal requires mutation. The cursor is used in the `MaybeRequiresStorage::check_for_move` operation.
Instead of using this cursor within `MaybeRequiresStorage` it's possible to do a pre-traversal of `MaybeBorrowedLocals` to extract the necessary information and then give that (immutably) to `MaybeRequiresStorage`.
This commit makes that change. The extracted information is in the new `KillableLocals` type, which is computed by the `KillableLocalsVisitor` type within `MaybeRequiresStorage::new`. `MaybeRequiresStorage` no longer needs lifetimes. `MoveVisitor` is no longer needed. And the complicated `locals_live_across_suspend_points` gets a little simpler.
r? @cjgillot
Added implementation on `set_permissions_nofollow` for all primary platforms
For context, this PR is related to the tracking issue for [`std::fs::set_permissions_nofollow`](https://github.com/rust-lang/rust/issues/141607). This PR does a few different things:
* Windows support is provided for `std::fs::set_permissions_nofollow`. On Windows, it uses `OpenOptions::open` with the custom flag `FILE_FLAG_OPEN_REPARSE_POINT` enabled and then sets the permissions on the reparse point directly. All other platforms (hermit, motor, solid, uefi, etc.) defer to what `fs::set_permissions` does since symlinks aren't supported on those platforms, so they effectively do the same thing.
* The implementation for Unix was modified to use [`fchmodat`](https://linux.die.net/man/2/fchmodat) instead of doing two separate calls (`open` and then `fchmod` via `OpenOptions`).
* Because the previous implementations actually used `fchmod` instead of `chmod` underneath the hood (as that's what `File::set_permissions`, which is not to be confused with `fs::set_permissions` as that does use `chmod`, does underneath the hood), it actually had some incorrect documentation about the error returned by `fchmod` on symlinks. Instead of `io::ErrorKind::FilesystemLoop`, it returns `io::ErrorKind::InvalidInput`. You can read the documentation for [`fchmod`](https://pubs.opengroup.org/onlinepubs/009696699/functions/fchmod.html). `fchmodat` does effectively the same thing as the `open` + `fchmod` combo, but it does return a different error, `io::ErrorKind::Unsupported`, that makes more sense. Regardless, I corrected the documentation for `std::fs::set_permissions_nofollow` and added a lot more clarifying information.
* A test case has been added to verify if `set_permissions_nofollow` is operating correctly.
cc @ChrisDenton and @lolbinarycat
rustdoc: Only analyze head of self type when deciding impl inlining
We only care about whether the self type is a generic or an item (inlined) in
the current crate, so we don't actually need to compute the param_env, which is
expensive when done to every external impl. This PR avoids computing the
param_env until we actually decide to inline the impl. Moreover, it adds
specialized cleaning logic for types that stops after the "head" (the top-level
structure) is constructed, which is enough for the self type-based impl
inlining analysis.
It currently contains a `MaybeBorrowedLocals` cursor. The cursor is
within a `RefCell` because cursor traversal requires mutation. The
cursor is used in the `MaybeRequiresStorage::check_for_move` operation.
Instead of using this cursor within `MaybeRequiresStorage` it's possible
to do a pre-traversal of `MaybeBorrowedLocals` to extract the necessary
information and then give that (immutably) to `MaybeRequiresStorage`.
This commit makes that change. The extracted information is in the new
`KillableLocals` type, which is computed by the `KillableLocalsVisitor`
type within `MaybeRequiresStorage::new`. `MaybeRequiresStorage` no
longer needs lifetimes. `MoveVisitor` is no longer needed. And the
complicated `locals_live_across_suspend_points` gets a little simpler.
miri ui tests: don't run native tests on stage 0
This seems to always fail. There's probably a way to make it work, but IMO it's enough if the native tests run in rustc CI (and in the Miri repo of course).
r? @oli-obk
Update `browser-ui-test` version to `0.25.0`
With this new version we should be able to finally add a regression test for [the "code copy" ](https://github.com/rust-lang/rust/pull/158137).
r? ghost
Add regression test for #132767Closesrust-lang/rust#132767. Coercing a fn item to a fn pointer with an associated type projection used to ICE during normalization. now errors with E0277.
Avoid stale closure recovery state across statements
Fixesrust-lang/rust#159989
`current_closure` was cleared when starting a new expression through `parse_expr`, but statement expressions call `parse_expr_res` directly. This allowed closure recovery state from one statement to remain active while parsing the next statement.
This pr clears `current_closure` when entering `parse_stmt_without_recovery`, matching the behavior of `parse_expr`.
da2697d1d8/compiler/rustc_parse/src/parser/expr.rs (L55-L56)da2697d1d8/compiler/rustc_parse/src/parser/expr.rs (L63-L64)
run intrinsic-test by default on x86_64-gnu
This PR runs intrinsic-test by default on x86_64-gnu and set sde bootstrap config in `RUST_CONFIGURE_ARGS` .
r? @Kobzol
Split register_tool into register_attribute_tool and register_lint_tool
Tracking issue: rust-lang/rust#66079
This implements the attribute parsing part of RFC 3808. The resolution part is yet to be implemented.
cc @jyn514
Distinguish the dep-graph index space from the live node count
`SerializedDepGraph::node_count()` returns `nodes.len()`, the size of the index space, which includes indices that batch allocation left unused. In the same file, the local `node_count` in `decode` is the number of nodes actually encoded. The two differ and are easy to confuse.
Fix ICE when dumping the dep graph with the parallel frontend
`-Zquery-dep-graph -Zdump-dep-graph` ICEs whenever `-Zthreads` is greater than 1:
```console
$ echo 'fn main() {}' > foo.rs
$ rustc -C incremental=incr -Zquery-dep-graph -Zdump-dep-graph -Zthreads=2 foo.rs
thread 'rustc' panicked at compiler/rustc_middle/src/dep_graph/retained.rs:40:63:
called `Option::unwrap()` on a `None` value
```
Reproduces on nightly on 15 of 15 runs at `-Zthreads` 2, 4 and 8. `-Zthreads=1` passes.
Dep-graph indices are handed to threads in batches of 256 and `EncoderState::finish` abandons each worker's unused tail, so `LinkedGraph::add_node_with_idx` back-fills the skipped slots with `data: None`. `RetainedDepGraph::nodes` unwrapped every slot, instead we skip the empty ones.
codegen: skip stores for entirely-uninit constant aggregate fields, attempt #2
This reverts both rust-lang/rust#159825 and rust-lang/rust#157797, and goes back to the original fix from rust-lang/rust#157797, albeit with a small refactor to share code between the now three branches that do the same check. This preserves the original issue (rust-lang/rust#157743) in a fixed state, but avoids the whack-a-mole the initially landed attempt created.
Fixes: rust-lang/rust#159867
r? @oli-obk
refactor(mir-transform): Calculate optimization status inside `run_passes_inner`
The `Optimizations` enum represents whether `#[optimize(none)]` has been applied to a function. Currently, `run_passes` takes an `Optimizations` which is confusing (https://github.com/rust-lang/rust/pull/160015#discussion_r3663238318).
Calculate this in `run_passes_inner` instead (which also means `#[optimize(none)]` is applied more consistently.
r? @RalfJung
rustdoc: Set tracing max_level_info when debug-logging is false
This matches rustc and should improve performance for the published versions of rustdoc. We shouldn't be including all our `debug!` calls in builds for users.
Replace most `Ty::new_fn_def` calls with `type_of` queries directly
This is so we can reduce the amount of code and changes in rust-lang/rust#159403. It should stand on its own, but really it's meant as an extended part of 159403.
This allows getting the right `ty::FnDef` even cross-crate, as the `type_of` query results are stored in metadata, in contrast to the queries for computing the binder for various declarations. These binders are already cached via `fn_sig`, but using that is somewhat overkill and can cause cycle errors in some cases.
Many "predicate"-to-"clause" renamings
Lots of names weren't changed to account for the introduction of the `Clause` type as a specialized form of `Predicate`, presumably because it was tedious. This commit converts as many of them as I could find. It's mostly very tedious renamings of types, functions, variables, and queries. The more interesting ones are a couple of files (`predicates_of.rs`, `impossible_predicates.rs`) and a MIR pass (`ImpossiblePredicates`).
r? @oli-obk
The last commit removed the expensive param_env computation since we
only need to look at the "head" of the self type (i.e. the top-level
structure) when making impl inlining decisions. This commit makes that
change more sound and improves on it further by creating specialized
cleaning logic for types that stops after the head is constructed.
Broaden `is_macos_ld` to `is_macos_linker` by matching `Darwin(..)`
instead of `Darwin(_, Lld::No)`, so the linker output filtering also
runs when lld is used. Add lld-specific version mismatch pattern to
`deployment_mismatch` closure, routing these warnings to `linker_info`
(default Allow) instead of `linker_messages` (default Warn).
Add a real-lld sub-test to `macos-deployment-target-warning` that
exercises the `ld64.lld` path via `-fuse-ld=`, verifying lld warnings
are normalized and routed to `linker_info`.
Signed-off-by: Ian Miller <milleryan2003@gmail.com>