Commit Graph

285652 Commits

Author SHA1 Message Date
Samuel Moelius
1a2c5a35b9 Fix adjacent code 2025-04-03 22:03:20 -04:00
Samuel Moelius
ddf7f18190 Extend QueryStability to handle IntoIterator implementations 2025-04-03 22:03:20 -04:00
bors
00095b3da4 Auto merge of #132527 - DianQK:gvn-stmt-iter, r=oli-obk
gvn: Invalid dereferences for all non-local mutations

Fixes #132353.

This PR removes the computation value by traversing SSA locals through `for_each_assignment_mut`.

Because the `for_each_assignment_mut` traversal skips statements which have side effects, such as dereference assignments, the computation may be unsound. Instead of `for_each_assignment_mut`, we compute values by traversing in reverse postorder.

Because we compute and use the symbolic representation of values on the fly, I invalidate all old values when encountering a dereference assignment. The current approach does not prevent the optimization of a clone to a copy.

In the future, we may add an alias model, or dominance information for dereference assignments, or SSA form to help GVN.

r? cjgillot

cc `@jieyouxu` #132356
cc `@RalfJung` #133474
2025-04-03 19:17:33 +00:00
bors
82eb03ec62 Auto merge of #139301 - matthiaskrgr:rollup-sa6ali8, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #139080 (Experimental feature gate for `super let`)
 - #139145 (slice: Remove some uses of unsafe in first/last chunk methods)
 - #139149 (unstable book: document import_trait_associated_functions)
 - #139273 (Apply requested API changes to `cell_update`)
 - #139282 (rustdoc: make settings checkboxes always square)
 - #139283 (Rustc dev guide subtree update)
 - #139294 (Fix the `f16`/`f128` feature gates on integer literals)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-03 15:31:20 +00:00
dianqk
7d44887374
Invalid dereferences for all non-local mutations 2025-04-03 21:59:49 +08:00
dianqk
4e05d858ad
Only preserving derefs for trivial terminators like SwitchInt and Goto 2025-04-03 21:59:49 +08:00
dianqk
ac7dd7a1b3
Remove unsound-mir-opts for simplify_aggregate_to_copy 2025-04-03 21:59:43 +08:00
bors
946aea0b3d Auto merge of #139137 - petrochenkov:errwhere2, r=jieyouxu
compiletest: Require `//~` annotations even if `error-pattern` is specified

This is continuation of #138865 with some help from #139100.

`error-pattern` annotations that duplicate the newly added `//~` annotations are removed, other `error-pattern`s are not touched yet.

In exceptional cases `//@ compile-flags: --error-format=human` can be used to opt out of these checks.
In this PR I only had to use the opt out 3 times:
- `tests/ui/parser/utf16-{be,le}-without-bom.rs` - there are too many errors that are nearly identical (modulo location), because an error is reported on every second symbol
- `tests/ui-fulldeps/missing-rustc-driver-error.rs` - the errors list various rustc crate dependencies and may unexpectedly invalidate on random rustc changes
2025-04-03 12:05:32 +00:00
bors
e0883a2a6c Auto merge of #137738 - Daniel-Aaron-Bloom:const_slice_make_iter, r=dtolnay
Make slice iterator constructors unstably const

See [tracking issue](https://github.com/rust-lang/rust/issues/137737) for justification.

try-job: aarch64-apple
try-job: x86_64-gnu
2025-04-03 08:57:46 +00:00
Vadim Petrochenkov
4916d44b59 Fix up tests on wasm and msvc, and rebase conflicts
Can be fixed properly later by adding a new flag for non-exhaustive line annotation checking
2025-04-03 11:08:55 +03:00
Vadim Petrochenkov
4d64990690 compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
Matthias Krüger
29c0fe747a
Rollup merge of #139294 - beetrees:fix-f16-f128-literal-feature-gate, r=fmease
Fix the `f16`/`f128` feature gates on integer literals

The feature gating logic for `f16`/`f128` currently only checks float literals, meaning this code currently compiles with no feature gates on stable ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b0c0e285ccb822fc7e2abc595557886b)):
```rust
fn main() {
    let a = 1f16;
    let b = 1f128;
    dbg!(a, b);
}
```
This PR fixes that.

Tracking issue: #116909
2025-04-03 07:39:08 +02:00
Matthias Krüger
85c557e76e
Rollup merge of #139283 - BoxyUwU:rdg-push, r=jieyouxu
Rustc dev guide subtree update

r? ``@jieyouxu`` ``@Kobzol``
2025-04-03 07:39:08 +02:00
Matthias Krüger
b5d5b6cd41
Rollup merge of #139282 - lolbinarycat:rustdoc-settings-checkbox-noshrink, r=notriddle
rustdoc: make settings checkboxes always square

Previously, checkboxes would flex horizontally on small screens:
![Screenshot 2025-04-02 at 15-45-13 std - Rust](https://github.com/user-attachments/assets/405dc764-3c04-4ba4-b86c-19e9d4fc0bff)

this simple css tweak fixes this.
2025-04-03 07:39:07 +02:00
Matthias Krüger
184e4baf1b
Rollup merge of #139273 - tgross35:cell-update-changes, r=jhpratt
Apply requested API changes to `cell_update`

Do the following:

* Switch to `impl FnOnce` rather than a generic `F`.
* Change `update` to return nothing.

This was discussed at a libs-api meeting [1].

Tracking issue: https://github.com/rust-lang/rust/issues/50186

[1]: https://github.com/rust-lang/rust/pull/134446#issuecomment-2770842949
2025-04-03 07:39:07 +02:00
Matthias Krüger
ee56188457
Rollup merge of #139149 - mejrs:itaf, r=ehuss
unstable book: document import_trait_associated_functions

Documents https://github.com/rust-lang/rust/issues/134691 which was implemented in https://github.com/rust-lang/rust/pull/134754
2025-04-03 07:39:06 +02:00
Matthias Krüger
e332aa89a7
Rollup merge of #139145 - okaneco:safe_splits, r=Amanieu
slice: Remove some uses of unsafe in first/last chunk methods

Remove unsafe `split_at_unchecked` and `split_at_mut_unchecked` in some slice `split_first_chunk`/`split_last_chunk` methods.
Replace those calls with the safe `split_at` and `split_at_checked` where applicable.

Add codegen tests to check for no panics when calculating the last chunk index using `checked_sub` and `split_at`.

Better viewed with whitespace disabled in diff view

---

The unchecked calls are mostly manual implementations of the safe methods, but with the safety condition negated from `mid <= len` to `len < mid`.
```rust
if self.len() < N {
    None
} else {
    // SAFETY: We manually verified the bounds of the split.
    let (first, tail) = unsafe { self.split_at_unchecked(N) };
    // Or for the last_chunk methods
    let (init, last) = unsafe { self.split_at_unchecked(self.len() - N) };
```

Unsafe is still needed for the pointer array casts. Their safety comments are unmodified.
2025-04-03 07:39:05 +02:00
Matthias Krüger
dbd7f52c83
Rollup merge of #139080 - m-ou-se:super-let-gate, r=traviscross
Experimental feature gate for `super let`

This adds an experimental feature gate, `#![feature(super_let)]`, for the `super let` experiment.

Tracking issue: https://github.com/rust-lang/rust/issues/139076

Liaison: ``@nikomatsakis``

## Description

There's a rough (inaccurate) description here: https://blog.m-ou.se/super-let/

In short, `super let` allows you to define something that lives long enough to be borrowed by the tail expression of the block. For example:

```rust
let a = {
    super let b = temp();
    &b
};
```

Here, `b` is extended to live as long as `a`, similar to how in `let a = &temp();`, the temporary will be extended to live as long as `a`.

## Properties

During the temporary lifetimes work we did last year, we explored the properties of "super let" and concluded that the fundamental property should be that these two are always equivalent in any context:

1. `& $expr`
2. `{ super let a = & $expr; a }`

And, additionally, that these are equivalent in any context when `$expr` is a temporary (aka rvalue):

1. `& $expr`
2. `{ super let a = $expr; & a }`

This makes it possible to give a name to a temporary without affecting how temporary lifetimes work, such that a macro can transparently use a block in its expansion, without that having any effect on the outside.

## Implementing pin!() correctly

With `super let`, we can properly implement the `pin!()` macro without hacks: 

```rust
pub macro pin($value:expr $(,)?) {
    {
        super let mut pinned = $value;
        unsafe { $crate::pin::Pin::new_unchecked(&mut pinned) }
    }
}
```

This is important, as there is currently no way to express it without hacks in Rust 2021 and before (see [hacky definition](2a06022951/library/core/src/pin.rs (L1947))), and no way to express it at all in Rust 2024 (see [issue](https://github.com/rust-lang/rust/issues/138718)).

## Fixing format_args!()

This will also allow us to express `format_args!()` in a way where one can assign the result to a variable, fixing a [long standing issue](https://github.com/rust-lang/rust/issues/92698):

```rust
let f = format_args!("Hello {name}!"); // error today, but accepted in the future! (after separate FCP)
```

## Experiment

The precise definition of `super let`, what happens for `super let x;` (without initializer), and whether to accept `super let _ = _ else { .. }` are still open questions, to be answered by the experiment.

Furthermore, once we have a more complete understanding of the feature, we might be able to come up with a better syntax. (Which could be just a different keywords, or an entirely different way of naming temporaries that doesn't involve a block and a (super) let statement.)
2025-04-03 07:39:05 +02:00
bors
b6d74b5e15 Auto merge of #139250 - dianqk:llvm-20.1.2, r=cuviper
Update to LLVM 20.1.2

`@rustbot` label A-LLVM T-compiler
2025-04-03 03:27:29 +00:00
bors
3658060890 Auto merge of #139234 - compiler-errors:query-tweak, r=oli-obk
Misc query tweaks

Remove some redundant work around `cache_on_disk` and `ensure_ok`, since `Result<(), ErrorGuaranteed>` queries don't need to cache or recompute their "value" if they are only used for their result.
2025-04-03 00:13:54 +00:00
beetrees
62fcb9d585
Fix the f16/f128 feature gate on integer literals 2025-04-03 01:08:41 +01:00
Mara Bos
14e6a964f2
Mark super_let feature as incomplete.
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-04-02 23:43:41 +02:00
binarycat
33c1ff0579 rustdoc: make settings checkboxes always square 2025-04-02 16:25:29 -05:00
bors
d5b4c2e4f1 Auto merge of #139269 - matthiaskrgr:rollup-pk78gig, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #138992 (literal pattern lowering: use the pattern's type instead of the literal's in `const_to_pat`)
 - #139211 (interpret: add a version of run_for_validation for &self)
 - #139235 (`AstValidator` tweaks)
 - #139237 (Add a dep kind for use of the anon node with zero dependencies)
 - #139260 (Add dianqk to codegen reviewers)
 - #139264 (Fix two incorrect turbofish suggestions)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-02 18:39:21 +00:00
Trevor Gross
072aa9e66f Apply requested API changes to cell_update
Do the following:

* Switch to `impl FnOnce` rather than a generic `F`.
* Change `update` to return nothing.

This was discussed at a libs-api meeting [1].

Tracking issue: https://github.com/rust-lang/rust/issues/50186

[1]: https://github.com/rust-lang/rust/pull/134446#issuecomment-2770842949
2025-04-02 18:18:50 +00:00
Matthias Krüger
278bc67fdc
Rollup merge of #139264 - freyacodes:fix/bad-turbofish-hints, r=petrochenkov
Fix two incorrect turbofish suggestions

This fixes #121901

This is my contribution to Rust, and my first contribution to a language parser that I didn't write myself.
I am a bit outside my depth here, so any constructive criticism is appreciated.
2025-04-02 19:44:15 +02:00
Matthias Krüger
43f17288e1
Rollup merge of #139260 - dianqk:dianqk-codegen-reviewers, r=Urgau
Add dianqk to codegen reviewers

Not an expert yet, but I may be able to review some LLVM-related PRs.

r? codegen
2025-04-02 19:44:14 +02:00
Matthias Krüger
3c5ee8d5f9
Rollup merge of #139237 - Zoxc:anon-0-deps-kind, r=compiler-errors
Add a dep kind for use of the anon node with zero dependencies

This adds a dep kind for use of the anon node with zero dependencies instead of making use of the null node. I don't think this matters, but it is nicer than random null nodes in the dep graph.
2025-04-02 19:44:14 +02:00
Matthias Krüger
ad8db11b94
Rollup merge of #139235 - nnethercote:AstValidator-tweaks, r=compiler-errors
`AstValidator` tweaks

When I read through `AstValidator` there were several things that tripped me up, and made the code harder to understand than I would have liked. This PR addresses them. Best reviewed one commit at a time.

r? ``@davidtwco``
2025-04-02 19:44:13 +02:00
Matthias Krüger
f5276bb0cf
Rollup merge of #139211 - RalfJung:interpret-run-for-validation, r=oli-obk
interpret: add a version of run_for_validation for &self

Turns out we'll need this for some ongoing work in Miri.

r? ``@oli-obk``
2025-04-02 19:44:13 +02:00
Matthias Krüger
3fb1230adc
Rollup merge of #138992 - dianne:simplify-byte-string-to-pat, r=oli-obk
literal pattern lowering: use the pattern's type instead of the literal's in `const_to_pat`

This has two purposes:
- First, it enables removing the `treat_byte_string_as_slice` fields from `TypeckResults` and `ConstToPat`. A byte string pattern's type will be `&[u8]` when matching on a slice reference, so `const_to_pat` will lower it to a slice ref pattern. I believe this is tested by `tests/ui/match/pattern-deref-miscompile.rs`.
- Second, it will simplify the implementation of byte string literals in deref patterns. If byte string patterns can be given the type `[u8; N]` or `[u8]` during HIR typeck, then nothing needs to be changed in `const_to_pat` in order to lower the patterns `deref!(b"..."): Vec<u8>` and `deref!(b"..."): Box<[u8; 3]>`.

Implementation-wise, this uses `lit_to_const` to make a const with the pattern's type and the literal's valtree; that feels to me like the best way to make sure that the valtree representations of the pattern type and literal are the same. Though it may necessitate later changes to `lit_to_const` to accommodate giving byte string literal patterns non-reference types—would that be reasonable?

This unfortunately doesn't work for the `string_deref_patterns` feature (since that gives string literal patterns the `String` type), so I added a workaround for that. However, once `deref_patterns` supports string literals, it may be able to replace `string_deref_patterns`; the special case for `String` can removed at that point.

r? ``@oli-obk``
2025-04-02 19:44:12 +02:00
Daniel Bloom
20417a9522 Make slice iterator constructors unstably const 2025-04-02 10:39:14 -07:00
Freya Arbjerg
d8d27ca822 Fix two incorrect turbofish suggestions
Fixes #121901
2025-04-02 18:10:34 +02:00
许杰友 Jieyou Xu (Joe)
ead4d4c951
Merge pull request #2313 from jieyouxu/rustc-pull
Rustc pull
2025-04-02 23:35:57 +08:00
Jieyou Xu
cae5d8a81c
Merge from rustc 2025-04-02 23:26:35 +08:00
Jieyou Xu
05d5fdadbb
Preparing for merge from rustc 2025-04-02 23:26:26 +08:00
dianqk
d5f7e9c200
Add dianqk to codegen reviewers 2025-04-02 22:23:19 +08:00
bors
4f0de4c81d Auto merge of #139257 - TaKO8Ki:rollup-vjzdas7, r=TaKO8Ki
Rollup of 5 pull requests

Successful merges:

 - #139178 (Remove cjgillot from automated review assignment)
 - #139184 (Add unstable `--print=crate-root-lint-levels`)
 - #139215 (Add `opt-level = "s"` for more std symbolication crates)
 - #139232 (Move methods from `Map` to `TyCtxt`, part 5.)
 - #139239 (Remove `aux_build` run-make rustc helpers)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-02 14:17:11 +00:00
Takayuki Maeda
abcfc3e390
Rollup merge of #139239 - jieyouxu:run-make-aux-build, r=Kobzol
Remove `aux_build` run-make rustc helpers

They provide very little value and makes it more confusing than is
helpful.

Helps with #138066.

r? `@Kobzol`
2025-04-02 22:52:47 +09:00
Takayuki Maeda
bda2ea4d01
Rollup merge of #139232 - nnethercote:remove-Map-5, r=Zalathar
Move methods from `Map` to `TyCtxt`, part 5.

This eliminates all methods on `Map`. Actually removing `Map` will occur in a follow-up PR.

A follow-up to #137504.

r? `@Zalathar`
2025-04-02 22:52:46 +09:00
Takayuki Maeda
5df0c684f4
Rollup merge of #139215 - clubby789:std-size-tweaks, r=joboet
Add `opt-level = "s"` for more std symbolication crates

This reduces the size of a hello world binary built by stage 1 in release by a few kilobytes
2025-04-02 22:52:46 +09:00
Takayuki Maeda
eb23a597c8
Rollup merge of #139184 - Urgau:crate-root-lint-levels, r=jieyouxu
Add unstable `--print=crate-root-lint-levels`

This PR implements `--print=crate-root-lint-levels` from MCP 833 https://github.com/rust-lang/compiler-team/issues/833.

Tracking issue: https://github.com/rust-lang/rust/issues/139180

Best reviewed commit by commit.
2025-04-02 22:52:45 +09:00
Takayuki Maeda
13c2d5e71e
Rollup merge of #139178 - apiraino:remove-cjgillot-automated-assighment, r=cjgillot
Remove cjgillot from automated review assignment

As discussed [on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Review.20for.20.23137465/with/508540539).

To be clear, this is not a value judgement, it's just a way to improve our fairness when assigning reviews, trying to find a balance between leaving time to Rust contributors review on their terms and availability and avoid having PRs waiting for too long.

> [!IMPORTANT]
> This is not a final decision! Rust contributors are free to re-add themselves back to the active review rotation (if they feel like it) once they have more availability.

cc: `@cjgillot`
2025-04-02 22:52:45 +09:00
dianqk
6e6d4a8cc5
Update to LLVM 20.1.2 2025-04-02 20:19:43 +08:00
dianqk
1787789fe5
Bless tests 2025-04-02 19:59:26 +08:00
dianqk
fefb0dba82
Partially revert "Do not unify dereferences in GVN."
This reverts commit 917dd82628.
2025-04-02 19:59:26 +08:00
dianqk
7e0463fe93
Revert "comment out the old tests instead of adjusting them"
This reverts commit 906f66fb4c.
2025-04-02 19:59:26 +08:00
dianqk
7830406df1
Invalidate all dereferences for non-local assignments 2025-04-02 19:58:35 +08:00
dianqk
84af556791
next_opaque is no longer an Option 2025-04-02 19:27:17 +08:00
dianqk
9d999bb035
Do not use for_each_assignment_mut to iterate over assignment statements
`for_each_assignment_mut` can skip assignment statements with side effects,
which can result in some assignment statements retrieving outdated value.
For example, it may skip a dereference assignment statement.
2025-04-02 19:27:17 +08:00