Commit Graph

284272 Commits

Author SHA1 Message Date
Oli Scherer
14cd467001 Fix next solver handling of shallow trait impl check 2025-03-19 14:40:14 +00:00
Oli Scherer
055d31c7a5 Demonstrate next-solver missing diagnostic 2025-03-19 14:38:23 +00:00
bors
9c67cecd12 Auto merge of #138595 - jhpratt:rollup-09pvfzu, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #136355 (Add `*_value` methods to proc_macro lib)
 - #137621 (Add std support to cygwin target)
 - #137793 (Stablize anonymous pipe)
 - #138341 (std: Mention clone-on-write mutation in Arc<T>)
 - #138517 (Improve upvar analysis for deref of child capture)
 - #138584 (Update Rust Foundation links in Readme)
 - #138586 (Document `#![register_tool]`)
 - #138590 (Flatten and simplify some control flow 🫓)
 - #138592 (update change entry for #137147)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-17 10:43:38 +00:00
Jacob Pratt
87b87b1966
Rollup merge of #138592 - onur-ozkan:follow-up-137147, r=Kobzol
update change entry for #137147

r? `@RalfJung`
2025-03-17 05:47:54 -04:00
Jacob Pratt
25a95e537c
Rollup merge of #138590 - yotamofek:pr/flatten-ifs, r=fmease
Flatten and simplify some control flow 🫓
2025-03-17 05:47:53 -04:00
Jacob Pratt
47d0c6b14e
Rollup merge of #138586 - jyn514:doc-register-tool, r=jieyouxu
Document `#![register_tool]`

cc https://github.com/rust-lang/rust/issues/66079
2025-03-17 05:47:52 -04:00
Jacob Pratt
72f95eba1d
Rollup merge of #138584 - atouchet:found, r=jieyouxu
Update Rust Foundation links in Readme

The Rust Foundation links in the Readme are outdated. I'm not sure if this is the best wording to use in place of the media guide, that can be changed if need be.
2025-03-17 05:47:52 -04:00
Jacob Pratt
e9f6e01b3a
Rollup merge of #138517 - compiler-errors:better-child-capture, r=oli-obk
Improve upvar analysis for deref of child capture

Two fixes to the heuristic I implemented in #123660. As I noted in the code:

> Luckily, if this function is not correct, then the program is not unsound, since we still borrowck and validate the choices made from this function -- the only side-effect is that the user may receive unnecessary borrowck errors.

This indeed fixes unnecessary borrowck errors.

r? oli-obk

---

The heuristic is only valid if we deref a `&T`, not a `&mut T` or `Box<T>`, so make sure to check the type. This fixes:

```rust
struct Foo { precise: i32 }

fn mut_ref_inside_mut(f: &mut Foo) {
    let x: impl AsyncFn() = async move || {
        let y = &f.precise;
    };
}
```

Since the capture from `f` to `&f.precise` needs to be treated as a lending borrow from the parent coroutine-closure to the child coroutine.

---

The heuristic is also valid if *any* deref projection in the child capture's projections is a `&T`, but we were only looking at the last one. This ensures that this function is considered not to be lending:

```rust
struct Foo { precise: i32 }

fn ref_inside_mut(f: &mut &Foo) {
    let x: impl Fn() -> _ = async move || {
        let y = &f.precise;
    };
}
```

(Specifically, checking that `impl Fn() -> _` is satisfied is exercising that the coroutine is not considered to be lending.)
2025-03-17 05:47:51 -04:00
Jacob Pratt
625278bb0e
Rollup merge of #138341 - xizheyin:issue-138322, r=joboet
std: Mention clone-on-write mutation in Arc<T>

Fixes #138322

r? libs
2025-03-17 05:47:50 -04:00
Jacob Pratt
62c2a7b93b
Rollup merge of #137793 - NobodyXu:stablise-annoymous-pipe, r=joshtriplett
Stablize anonymous pipe

Since #135822 is staled, I create this PR to stablise anonymous pipe

Closes #127154

try-job: test-various
2025-03-17 05:47:50 -04:00
Jacob Pratt
b3b7a3b8d2
Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboet
Add std support to cygwin target
2025-03-17 05:47:49 -04:00
Jacob Pratt
08dfbf49e3
Rollup merge of #136355 - GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu
Add `*_value` methods to proc_macro lib

This is the implementation of https://github.com/rust-lang/libs-team/issues/459.

It allows to get the actual value (unescaped) of the different string literals.

Part of https://github.com/rust-lang/rust/issues/136652.

r? libs-api
2025-03-17 05:47:48 -04:00
Guillaume Gomez
4394f94023 Only add rustc_randomized_layouts if the crate has it 2025-03-17 10:43:28 +01:00
Yotam Ofek
51e8309f50 Flatten and simplify some control flow 2025-03-17 09:15:49 +00:00
onur-ozkan
0d100d34d5 update change entry for #137147
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2025-03-17 11:13:05 +03:00
bors
9bad8ac498 Auto merge of #138566 - yotamofek:pr/strip-prefix, r=nnethercote
Use `strip_{prefix|suffix}` instead of `{starts|ends}_with`+indexing

Randomly scratching an itch 😁
2025-03-17 07:34:25 +00:00
Yotam Ofek
a3e4dff183 Use strip_{prefix|suffix} instead of {starts|ends}_with+indexing 2025-03-17 07:06:10 +00:00
jyn
10bc5acf0d Document #![register_tool] 2025-03-17 01:16:47 -04:00
bors
10bcdad7df Auto merge of #138583 - jhpratt:rollup-h699hty, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - #136293 (document capacity for ZST as example)
 - #136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove)
 - #136816 (refactor `notable_traits_button` to use iterator combinators  instead of for loop)
 - #138552 (Misc print request handling cleanups + a centralized test for print request stability gating)
 - #138573 (Make `_Unwind_Action` a type alias, not enum)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-17 03:45:06 +00:00
Alex Touchet
04c9956c9a
Update Rust Foundation links in Readme 2025-03-16 19:03:40 -07:00
Jacob Pratt
5144055055
Rollup merge of #138573 - Noratrieb:no-unsound-bad-bonk-bonk, r=workingjubilee
Make `_Unwind_Action` a type alias, not enum

It's bitflags in practice, so an enum is unsound, as an enum must only have the described values. The x86_64 psABI declares it as a `typedef int _Unwind_Action`, which seems reasonable. I made a newtype first but that was more annoying than just a typedef. We don't really use this value for much other than a short check.

I ran `x check library --target aarch64-unknown-linux-gnu,x86_64-pc-windows-gnu,x86_64-fortanix-unknown-sgx,x86_64-unknown-haiku,x86_64-unknown-fuchsi
a,x86_64-unknown-freebsd,x86_64-unknown-dragonfly,x86_64-unknown-netbsd,x86_64-unknown-openbsd,x86_64-unknown-redox,riscv64-linux-android,armv7-unknown-freebsd` (and some more but they failed to build for other reasons :D)

fixes #138558

r? workingjubilee have fun
2025-03-16 21:47:45 -04:00
Jacob Pratt
6da26f7cfe
Rollup merge of #138552 - jieyouxu:print-request-cleanups, r=Urgau
Misc print request handling cleanups + a centralized test for print request stability gating

I was working on implementing `--print=supported-crate-types`, then I noticed some things that were mildly annoying me, so I pulled out these changes. In this PR:

- First commit adds a centralized test `tests/ui/print/stability.rs` that is responsible for exercising stability gating of the print requests.
    - AFAICT we didn't have any test that systematically checks this.
    - I coalesced `tests/ui/feature-gates/feature-gate-print-check-cfg.rs` (for `--print=check-cfg`) into this test too, since `--print=check-cfg` is only `-Z unstable-options`-gated like other unstable print requests, and is not additionally feature-gated. cc ``@Urgau`` in case you have any concerns.
- Second commit alphabetically sorts the `PrintKind` enum for consistency because the `PRINT_KINDS` list (using the enum) is *already* alphabetically sorted.
- Third commit pulls out two helpers:
    1. A helper `check_print_request_stability` for checking stability of print requests and the diagnostics for using unstable print requests without `-Z unstable-options`, to avoid repeating the same logic over and over.
    2. A helper `emit_unknown_print_request_help` for the unknown print request diagnostics to make print request collection control flow more obvious.
- Fourth commit renames `PrintKind::{TargetSpec,AllTargetSpecs}` to `PrintKind::{TargetSpecJson,AllTargetSpecsJson}` to better reflect their actual print names, `--print={target-spec-json,all-target-specs-json}`.

r? ``@nnethercote`` (or compiler/reroll)
2025-03-16 21:47:44 -04:00
Jacob Pratt
04032ab233
Rollup merge of #136816 - yotamofek:pr/notable-traits-button-cleanup, r=aDotInTheVoid
refactor `notable_traits_button` to use iterator combinators  instead of for loop

~Small cleanup.
Use `Iterator::any` instead of `for` loop with `predicate = true;`.
I think this makes the code more readable... and also has the additional benefit of short-circuiting the iterator when a notable trait is found (a `break` statement was missing in the `for` loop version, I think). Probably won't be significant enough to show on perf results, though.~

Three commits, each attempting to optimize `notable_trait_buttons` by a little bit.
2025-03-16 21:47:43 -04:00
Jacob Pratt
feb6cb4132
Rollup merge of #136359 - hkBst:ptr_copy_docs, r=Amanieu
doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove

Fixes #79430
2025-03-16 21:47:42 -04:00
Jacob Pratt
c7700406f4
Rollup merge of #136293 - hkBst:patch-32, r=Amanieu
document capacity for ZST as example

The main text already covers this, although it provides weaker guarantees, but I think an example in the right spot does not hurt. Fixes #80747
2025-03-16 21:47:42 -04:00
bors
c3dd4eefd6 Auto merge of #138363 - beetrees:f16-f128-integer-convert, r=Amanieu
Add `From<{integer}>` for `f16`/`f128` impls

This PR adds `impl From<{bool,i8,u8}> for f16` and `impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128`.

The `From<{i64,u64}> for f128` impls are left commented out as adding them would allow using `f128` on stable before it is stabilised like in the following example:
```rust
fn f<T: From<u64>>(x: T) -> T { x }

fn main() {
    let x = f(1.0); // the type of the literal is inferred to be `f128`
}
```
None of the impls added in this PR have this issue as they are all, at minimum, also implemented by `f64`.

This PR will need a crater run for the `From<{i32,u32}>` impls, as `f64` is no longer the only float type to implement them (similar to the cause of #125198).

cc `@bjoernager`
r? `@tgross35`

Tracking issue: #116909
2025-03-17 00:33:36 +00:00
Guillaume Gomez
417bfe2125 Exclude literal-escaper from library workspace 2025-03-16 21:46:39 +01:00
Noratrieb
f20a6c70fb make _Unwind_Action a type alias, not enum
It's bitflags in practice, so an enum is unsound, as an enum must only
have the described values. The x86_64 psABI declares it as a `typedef
int _Unwind_Action`, which seems reasonable. I made a newtype first but
that was more annoying than just a typedef. We don't really use this
value for much other than a short check.
2025-03-16 21:32:41 +01:00
bors
227690a258 Auto merge of #137011 - LuuuXXX:promote-ohos-with-host-tools, r=Amanieu
Promote ohos targets to tier2 with host tools.

### What does this PR try to resolve?

Try to promote the following [[Tier 2 without Host Tools](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-without-host-tools)](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-without-host-tools) targets to [[Tier 2 with Host Tools](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-with-host-tools)](https://doc.rust-lang.org/rustc/platform-support.html#tier-2-with-host-tools):

- `aarch64-unknown-linux-ohos`
- `armv7-unknown-linux-ohos`
- `x86_64-unknown-linux-ohos`

### More Information?

see MCP: https://github.com/rust-lang/compiler-team/issues/811

### Blockage to be solved?

- [x] Submit an MCP
- [x] Submit code of promote ohos targets
- [x] Resolve related dependencies (`measureme`)

The modified code of the measureme has been merged (see https://github.com/rust-lang/measureme/pull/238). [done]
The new version will was released (https://github.com/rust-lang/measureme/pull/240). [done]
2025-03-16 18:42:18 +00:00
bors
8b87fefd76 Auto merge of #138537 - yotamofek:pr/lib/multi-char-pattern, r=jhpratt
Optimize multi-char string patterns

Uses specialization for `[T]::contains` from #130991 to optimize multi-char patterns in string searches.
Requesting a perf run to see if this actually has an effect 🙏
(I think that adding `char` to the list of types for which the `SliceContains` is specialized is a good idea, even if it doesn't show up on perf - might be helpful for downstream users)
2025-03-16 14:23:18 +00:00
Jieyou Xu
24edbfbc24
Rename PrintKind::{AllTargetSpecs,TargetSpec} to {AllTargetSpecsJson,TargetSpecJson}
To correspond to their actual print request names, `target-spec-json`
and `all-target-specs-json`, and for consistency with other print name
<-> print kind mappings.
2025-03-16 21:56:02 +08:00
Jieyou Xu
f9eabc28d9
Extract print request stability gating and unknown print request help into helpers
To avoid duplicating stability check logic and make the print request
collection logic more straightforward.
2025-03-16 21:56:02 +08:00
Jieyou Xu
5f8e0920f9
Alphabetically sort PrintKind and enforce with tidy 2025-03-16 21:56:02 +08:00
Jieyou Xu
ab7fb0d483
Add a centralized test for print request stability gating
I can't find any dedicated tests that actually exercises the stability
gating (via `-Z unstable-options`) of print requests, so here's a
dedicated one.

I coalesced `tests/ui/feature-gates/feature-gate-print-check-cfg.rs`
into this test, because AFAICT that print request is not feature gated,
but only `-Z unstable-options`-gated just like other unstable print
requests.
2025-03-16 21:56:01 +08:00
Guillaume Gomez
ec4b3c2779 Add test for new proc_macro literal methods 2025-03-16 14:28:45 +01:00
bors
d497e43a16 Auto merge of #138551 - jieyouxu:rollup-ttktelm, r=jieyouxu
Rollup of 4 pull requests

Successful merges:

 - #135080 (core: Make `Debug` impl of raw pointers print metadata if present)
 - #137492 (libstd: rustdoc: correct note on fds 0/1/2 pre-main)
 - #137538 (fix doc path in std::fmt macro)
 - #138549 (Fix the OperandRef type for NullOp::{UbChecks,ContractChecks})

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-16 11:15:56 +00:00
许杰友 Jieyou Xu (Joe)
e714c3be9f
Rollup merge of #138549 - scottmcm:option-ssa, r=saethlin
Fix the OperandRef type for NullOp::{UbChecks,ContractChecks}

Stumbled on this while looking at something totally unrelated 🙃

r? saethlin
2025-03-16 13:19:53 +08:00
许杰友 Jieyou Xu (Joe)
c29a29e717
Rollup merge of #137538 - tapanprakasht:fix-doc-path, r=thomcc
fix doc path in std::fmt macro

fixes https://github.com/rust-lang/rust/issues/137519
2025-03-16 13:19:52 +08:00
许杰友 Jieyou Xu (Joe)
26dea1d944
Rollup merge of #137492 - nabijaczleweli:master, r=thomcc
libstd: rustdoc: correct note on fds 0/1/2 pre-main

Closes: #137490
2025-03-16 13:19:52 +08:00
许杰友 Jieyou Xu (Joe)
a23a93cb4e
Rollup merge of #135080 - Enselic:debug-ptr-metadata, r=thomcc
core: Make `Debug` impl of raw pointers print metadata if present

Make Rust pointers appear less magic by including metadata information in their `Debug` output.

This does not break Rust stability guarantees because `Debug` impl are explicitly exempted from stability:
https://doc.rust-lang.org/std/fmt/trait.Debug.html#stability

> ## Stability
>
> Derived `Debug` formats are not stable, and so may change with future Rust versions. Additionally, `Debug` implementations of types provided by the standard library (`std`, `core`, `alloc`, etc.) are not stable, and may also change with future Rust versions.

Note that a regression test is added as a separate commit to make it clear what impact the last commit has on the output.

Closes #128684 because the output of that code now becomes:

```
thread 'main' panicked at src/main.rs:5:5:
assertion `left == right` failed
  left: Pointer { addr: 0x7ffd45c6fc6b, metadata: 5 }
 right: Pointer { addr: 0x7ffd45c6fc6b, metadata: 3 }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
2025-03-16 13:19:51 +08:00
bors
5f3b84a421 Auto merge of #137278 - heiseish:101210-extra-codegen-tests, r=scottmcm
added some new test to check for result and options opt

Apologies for the delay. Finally have some time to get back into contributing.

## Context
- Added some tests to show optimization on result and options for 64 and 128 bits
- Relevant issue https://github.com/rust-lang/rust/issues/101210

## Some newb questions from me
- [x] My local llvm IR has `nuw` in `result_nop_match_128` etc whereas [godbolt version](https://rust.godbolt.org/z/Td9zoT5zn) doesn't have. So I put optional there, but not sure if it's desirable (maybe I'm not using the compiled llvm in the repo). I ran the test with
```bash
./x test tests/codegen/try_question_mark_nop.rs
```
- [x] Unless I'm reading it wrongly, but `option_nop_match_128` and `option_nop_traits_128` look to be **not** optimized away?

Update:
Here's the test for future reference
```rust
// CHECK-LABEL: `@option_nop_match_128`
#[no_mangle]
pub fn option_nop_match_128(x: Option<i128>) -> Option<i128> {
    // CHECK: start:
    // CHECK-NEXT: %trunc = trunc nuw i128 %0 to i1
    // CHECK-NEXT: br i1 %trunc, label %bb3, label %bb4
    // CHECK: bb3:
    // CHECK-NEXT: %2 = getelementptr inbounds {{(nuw )?}}i8, ptr %_0, i64 16
    // CHECK-NEXT: store i128 %1, ptr %2, align 16
    // CHECK: bb4:
    // CHECK-NEXT: %storemerge = phi i128 [ 1, %bb3 ], [ 0, %start ]
    // CHECK-NEXT: store i128 %storemerge, ptr %_0, align 16
    // CHECK-NEXT: ret void
    match x {
        Some(x) => Some(x),
        None => None,
    }
}
```

r? `@scottmcm`
2025-03-16 05:17:07 +00:00
Scott McMurray
3d42541313 Fix the OperandRef type for NullOp::{UbChecks,ContractChecks} 2025-03-15 19:39:15 -07:00
bors
66678e6822 Auto merge of #138548 - jieyouxu:rollup-xpslct5, r=jieyouxu
Rollup of 16 pull requests

Successful merges:

 - #133055 (Expand `CloneToUninit` documentation.)
 - #137147 (Add exclude to config.toml)
 - #137864 (Don't drop `Rvalue::WrapUnsafeBinder` during GVN)
 - #137890 (doc: clarify that consume can be called after BufReader::peek)
 - #137956 (Add RTN support to rustdoc)
 - #137968 (Properly escape regexes in Python scripts)
 - #138082 (Remove `#[cfg(not(test))]` gates in `core`)
 - #138275 (expose `is_s390x_feature_detected!` from `std::arch`)
 - #138303 (Fix Ptr inconsistency in {Rc,Arc})
 - #138309 (Add missing doc for intrinsic (Fix PR135334))
 - #138323 (Expand and organize `offset_of!` documentation.)
 - #138329 (debug-assert that the size_hint is well-formed in `collect`)
 - #138465 (linkchecker: bump html5ever)
 - #138471 (Clean up some tests in tests/ui)
 - #138472 (Add codegen test for #129795)
 - #138484 (Use lit span when suggesting suffix lit cast)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-16 02:02:45 +00:00
许杰友 Jieyou Xu (Joe)
f4372f5d12
Rollup merge of #138484 - xizheyin:issue-138392, r=compiler-errors
Use lit span when suggesting suffix lit cast

Fixes #138392
2025-03-16 09:40:10 +08:00
许杰友 Jieyou Xu (Joe)
c05a643ca8
Rollup merge of #138472 - KonaeAkira:master, r=Mark-Simulacrum
Add codegen test for #129795

Adds test for #129795.

Min LLVM version is 20 because the optimization only happens since LLVM 20.
2025-03-16 09:40:09 +08:00
许杰友 Jieyou Xu (Joe)
7c1555cb9b
Rollup merge of #138471 - spencer3035:move-ui-test-1ofn, r=jieyouxu
Clean up some tests in tests/ui

I cleaned up 3 top level tests, keeping the changes minor because it is my first PR and wanted to get feedback before doing more changes/PRs.

Tracking issues:
https://github.com/rust-lang/rust/issues/73494
https://github.com/rust-lang/rust/issues/133895

r? jieyouxu
2025-03-16 09:40:08 +08:00
许杰友 Jieyou Xu (Joe)
e42f33970c
Rollup merge of #138465 - klensy:linkchecker-b, r=Mark-Simulacrum
linkchecker: bump html5ever

Bumping html5ever to 0.28 required small refactoring, see https://github.com/servo/html5ever/pull/548
2025-03-16 09:40:08 +08:00
许杰友 Jieyou Xu (Joe)
01bc95417c
Rollup merge of #138329 - scottmcm:assert-hint, r=Mark-Simulacrum
debug-assert that the size_hint is well-formed in `collect`

Closes #137919

In the hopes of helping to catch any future accidentally-incorrect rustc or stdlib iterators (like the ones #137908 accidentally found), this has `Iterator::collect` call `size_hint` and check its `low` doesn't exceed its `Some(high)`.

There's of course a bazillion more places this *could* be checked, but the hope is that this one is a good tradeoff of being likely to catch lots of things while having minimal maintenance cost (especially compared to putting it in *every* container's `from_iter`).
2025-03-16 09:40:07 +08:00
许杰友 Jieyou Xu (Joe)
5b9225070c
Rollup merge of #138323 - kpreid:offset-of-doc, r=Mark-Simulacrum
Expand and organize `offset_of!` documentation.

* Give example of how to get the offset of an unsized tail field (prompted by discussion <https://github.com/rust-lang/rust/pull/133055#discussion_r1986422206>).
* Specify the return type.
* Add section headings.
* Reduce “Visibility is respected…”, to a single sentence.
* Move `offset_of_enum` documentation to unstable book (with link to it).
* Add `offset_of_slice` documentation in unstable book.

r? Mark-Simulacrum
2025-03-16 09:40:07 +08:00
许杰友 Jieyou Xu (Joe)
413600c2de
Rollup merge of #138309 - DiuDiu777:intrinsic-doc-fix, r=thomcc
Add missing doc for intrinsic (Fix PR135334)

The previous [PR135334](https://github.com/rust-lang/rust/pull/135334) mentioned that some of the intrinsic APIs were missing safety descriptions.

Among intrinsic APIs that miss safety specifications, most are related to numerical operations. They might need to be discussed and then seen how to organize.

Apart from them, only a few intrinsics lack safety. So this PR deals with the APIs with non-numerical operations in priority.
2025-03-16 09:40:06 +08:00