User facing .expect now follows “expect as precondition" style
Related issue: https://github.com/rust-lang/rust/issues/159751
Updated .expect error message in std/src/net/tcp.rs to follow “expect as precondition" style.
Add regression test for save temps ICE on incremental recompile
Closesrust-lang/rust#66367 adds an incremental regression test for adding -C save-tempsthat used to ICE
Add regression test for cycle error on guaranteed unsized self type
Closesrust-lang/rust#116914 the solver now detects the cycle and errors, which this pins
Refactor tidy detection of stability attribute
And fix support for multi-line attributes. And add some tests.
Necessary for https://github.com/rust-lang/rust/pull/160108 which confused tidy.
stabilize `c_variadic_naked_functions`
tracking issue: https://github.com/rust-lang/rust/issues/148767
reference PR: https://github.com/rust-lang/reference/pull/2321
# Stabilization report
## Summary
Stabilize the ability to use `#[unsafe(naked)]` functions to define c-variadic functions. These c-variadic naked functions accept the same set of ABIs as c-variadic foreign functions, this set is larger than what we currently accept for c-variadic definitions.
```rust
#[unsafe(naked)]
unsafe extern "aapcs" fn variadic_aapcs(_: f64, _: ...) -> f64 {
core::arch::naked_asm!(
r#"
sub sp, sp, #12
stmib sp, {{r2, r3}}
vmov d0, r0, r1
add r0, sp, #4
vldr d1, [sp, #4]
add r0, r0, #15
bic r0, r0, #7
vadd.f64 d0, d0, d1
add r1, r0, #8
str r1, [sp]
vldr d1, [r0]
vadd.f64 d0, d0, d1
vmov r0, r1, d0
add sp, sp, #12
bx lr
"#,
)
}
```
## Accepted ABIs
The set of accepted ABIs is the same as for c-variadic foreign functions, defined as rule [`items.extern.variadic.conventions`](https://doc.rust-lang.org/nightly/reference/items/external-blocks.html?highlight=externblo#r-items.extern.variadic.conventions):
- `"aapcs"`
- `"C"`
- `"cdecl"`
- `"efiapi"`
- `"system"`
- `"sysv64"`
- `"win64"`
And their corresponding `-unwind` variants. Given that naked functions desugar to a block of module assembly and a foreign definition, it makes sense to support the same set as source-level foreign definitions.
For c-variadic definitions we only accept `"C"` and `"C-unwind"`.
## Multiple c-variadic ABIs in the same program
LLVM supports c-variadic calls of different ABIs in the same program. We test both an arm and x86 configuration
- 771916f902/tests/ui/c-variadic/same-program-multiple-abis-arm.rs
- 771916f902/tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs
Note that GCC, Clang and LLVM do not support c-variadic definitions of multiple ABIs: the `va_start`, `va_arg` etc. macros are always expanded using the default C calling convention. Clang and GCC reject a variable argument list on definitions that use a non-default calling convention.
## History
- [#t-lang > C-variadic naked functions](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/C-variadic.20naked.20functions/with/554593886)
- https://github.com/rust-lang/rust/pull/148770
The stabilization report of `feature(c_variadic)` mentions this feature:
- https://github.com/rust-lang/rust/pull/155697
## Unresolved questions
None.
rustc_attr_ir: fix up `lang_items` imports
Cleanup after splitting attributes from rustc_hir.
It's a big one and maybe annoying to merge without conflicts but I figured it's best to just get it done and over with. If it turns out to be too big to merge at once it should be possible to split it up tho :>
r? @JonathanBrouwer
Rollup of 5 pull requests
Successful merges:
- rust-lang/rust#158517 (Initial implementation of named `Fn` trait parameters)
- rust-lang/rust#158587 (check if len of array const arg matches the expected len of the type when lowering to valtree)
- rust-lang/rust#160748 (Add regression test for cross-crate assoc const private field leak in rustdoc)
- rust-lang/rust#160708 (remove old update mechanism)
- rust-lang/rust#160768 (Fix autodiff_illegal.rs test)
Add regression test for cross-crate assoc const private field leak in rustdoc
Closesrust-lang/rust#99630 adds a rustdoc test, reexporting a type must not leak the private field
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
Initial implementation of named `Fn` trait parameters
This is an initial implementation of the feature `named_fn_trait_parameters`.
This implementation is incomplete (and also marked as such) , and needs significant further changes to be implemented correctly. To keep the size of this PR managable, I propose we do this in follow-up PRs.
I've added a test that shows the current behaviour, with `FIXME` comments where the test output is currently incorrect.
Tracking issue: https://github.com/rust-lang/rust/issues/158499
Accepted RFC: https://github.com/rust-lang/rfcs/pull/3955
Merge `rustc_attr_parsing/session_diagnostics.rs` into `diagnostics.rs`
Renaming diagnostics files to all be diagnostics.rs, per the decision in https://github.com/rust-lang/compiler-team/issues/1003
r? @GuillaumeGomez
Rename more diagnostic files to `diagnostics.rs`
Renaming diagnostics files to all be `diagnostics.rs`, per the decision in https://github.com/rust-lang/compiler-team/issues/1003
PR was created by doing a file rename using the editor actions of my IDE, and then running `./x fmt`
r? @GuillaumeGomez @nnethercote
Whoever of you gets to it first :)
rustc_passes: lint unused `#[path]` attributes on inline modules
Closesrust-lang/rust#157260.
This PR emits the `unused_attributes` lint for `#[path]` attributes on inline modules when the attribute is unused.
It also adds UI tests covering both linted and non-linted cases.
r? @theemathas
Make `char::is_default_ignorable` unstably public
Similar to https://github.com/rust-lang/rust/pull/154849; this function is used in the implementation of `char::escape_debug()`, and there's no reason to force crates to duplicate a data table that std has to ship anyway.
I'll add a tracking issue if this is approved.
(I'll do the other data tables from https://github.com/rust-lang/rust/pull/155527 in separate PRs.)
@rustbot label A-Unicode T-libs-api
Tracking issue: rust-lang/rust#160583
r? @Mark-Simulacrum
Apply str debugger visualizer to `*const str`, `*mut str` and `Box<str>`
Fairly straightforward. Note that the MSVC changes very likely aren't exercised by CI. My GSoC project is actively working on fixing that, but in the meantime i can personally verify that it works (note that the `ref$<str$> *` type name confirms this is MSVC):
<img width="318" height="138" alt="image" src="https://github.com/user-attachments/assets/fd868f16-d9a5-438a-a155-a429771bf525" />
Introduce a `PinSafePointer` trait that generalizes `PinCoerceUnsized`
This PR renames `PinCoerceUnsized` to `PinSafePointer` and adds several new safety requirements about the implementations of various safe traits.
Closes: rust-lang/rust#152667Closes: rust-lang/rust#147794
~~With this merged, the only remaining soundness issues with `Pin` are:~~
* rust-lang/rust#134407
* The fact that `CoercePointee` may be implemented on `Pin<LocalType>` in downstream crates. (unstable only)
For your convenience here are the docs for the new trait:
# `PinSafePointer`
Trait that indicates that this is a pointer that does not misbehave when combined with `Pin`.
Note that for backwards compatibility reasons, it is possible to create a `Pin<P>` for pointer types `P` that do not implement this trait. However, this can only be done safely if `<P as Deref>::Target` implements `Unpin`, which means that pinning has no effect.
# Safety
Types that implement this trait must not provide "malicious" implementations of any safe traits used by `Pin`.
## The pointer must always reference the same object
Calls to [`deref`]/[`deref_mut`] on the same `Pin<P>` instance must always refer to the same object. That is, the address returned by these methods must not change. This applies even if the pointer type is moved.
Furthermore, if the pointer type can participate in unsizing coercions or dynamic dispatch, then these coercions must also not change the underlying concrete type. Here, the concrete type of a trait object is the type that the vtable corresponds to. The concrete type of a slice is an array of the same element type and the length specified in the metadata. The concrete type of a sized type is the type itself.
As an example, after unsizing coercing a pinned pointer, `deref_mut` must not return a `#[repr(transparent)]` wrapper around the value it referenced before being unsized, even if the address is unchanged.
## The pointer must not move its pointee
The [`deref_mut`] method and the pointer type's destructor are called with a `&mut self` receiver, but they must behave as-if it was a `self: Pin<&mut Self>` receiver. That is, they must not move out of the underlying value.
As an example, `deref_mut` must not invoke `swap` on the inner value.
## Shared access to the pointer
If this pointer type uses `&P` references as evidence that this value is not pinned, then it must not treat the `&self` argument passed to [`Clone`] or the formatting traits (`fmt::Debug`, `fmt::Display`, `fmt::Pointer`) as such evidence.
As an example, given a `Pin<Arc<T>>` there is no way to obtain an `&Arc<T>` (note that `Deref` just gives a `&T`). Because of this, the [`Arc`] type can assume that an `&Arc<T>` value can only exist if the `T` is not pinned, which justifies the soundness of the [`Arc::get_mut`] method.
## Cloning pinned pointers
When a `Pin<P>` is cloned, the `P` pointer value returned by `clone` is passed to [`Pin::new_unchecked`]. The implementation of [`Clone`] must return a value such that this is sound.
For example, when a `Pin<&T>` is cloned, the resulting `&T` points at the same value. The value is known to be pinned since a `Pin<&T>` to it exists, so it is safe to wrap the `&T` returned by `clone` in `Pin`.
[`deref`]: https://doc.rust-lang.org/stable/core/ops/trait.Deref.html#tymethod.deref
[`deref_mut`]: https://doc.rust-lang.org/stable/core/ops/trait.DerefMut.html#tymethod.deref_mut
[`clone`]: https://doc.rust-lang.org/stable/core/clone/trait.Clone.html#tymethod.clone
[`Clone`]: https://doc.rust-lang.org/stable/core/clone/trait.Clone.html
[`Arc`]: https://doc.rust-lang.org/stable/std/sync/struct.Arc.html
[`Arc::get_mut`]: https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#method.get_mut
[`Pin::new_unchecked`]: https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#method.new_unchecked
r? lcnr
Add regression test for higher ranked fn pointer impl not general enough
Closesrust-lang/rust#57936 adds a regression test for higher ranked fn-pointer impl is now correctly rejected
sort lint names in lint pass declarations
When adding a new lint, you'd naturally add the new lint at the bottom, and would have to deal with merge conflicts with all other PRs that also add a lint. Sorting the list should at least mitigate that, and is probably more readable overall.
miri: implement more restrictive trivial-ABI checks
This implements the rules from rust-lang/rust#157973 in Miri. We unfortunately have to reject some code that we thought was okay. Let's land this in Miri ahead of anything official also to see if there's any major breakage from that.
r? @oli-obk