Commit Graph

19780 Commits

Author SHA1 Message Date
Matthias Krüger
f61645325e Rollup merge of #141886 - ferrocene:lw/2015-edition-directives, r=compiler-errors
Add missing 2015 edition directives

These tests specifically test 2015 edition behavior, so ensure that they can only be run with this edition
2025-06-03 07:03:45 +02:00
Matthias Krüger
69ebe39cea Rollup merge of #141876 - compiler-errors:missing-let-ty, r=SparrowLii
Don't declare variables in `ExprKind::Let` in invalid positions

Handle `let` expressions in invalid positions specially during resolve in order to avoid making destructuring-assignment expressions that reference (invalid) variables that have not yet been delcared yet.

See further explanation in test and comment in the source.

Fixes rust-lang/rust#141844
2025-06-03 07:03:44 +02:00
Matthias Krüger
aed1171c66 Rollup merge of #141677 - azhogin:azhogin/async-drop-unexpected-type-instead-of-drop-fn-fix, r=oli-obk
Async drop - type instead of async drop fn, fixes #140484

Fixes: rust-lang/rust#140484
Fixes: rust-lang/rust#140500

Fixes ICE, when type is provided in AsyncDrop trait instead of `async fn drop()`.
Fixes ICE, when async drop fn has wrong signature.
2025-06-03 07:03:43 +02:00
Nicholas Nethercote
02a86dbd1d Remove pre-expansion AST stats.
They're very little value, because they only measure the top-level
`main.rs` or `lib.rs` file. (Other `.rs` files don't get read and parsed
until expansion occurs.)

I saw an example recently where the pre-expansion AST was 3KB in size
and the post-expansion AST was 66MB.

I kept the "POST EXPANSION" in the output header, I think that's useful
information to avoid possible confusion about when the measurement
happens.
2025-06-03 14:50:22 +10:00
Kivooeo
e7e884b0a4 cleaned up some tests 2025-06-03 07:38:06 +05:00
Michael Goulet
3418d5db3a Fast path for stalled obligations on self ty 2025-06-02 19:23:20 +00:00
b-naber
8604e58942 add doc comment and a test with a generic closure 2025-06-02 17:36:17 +00:00
b-naber
1d66e66f2f add body to ClosureDef 2025-06-02 16:25:20 +00:00
Oli Scherer
020216c31c Clarify why we are talking about a failed const eval at a random place 2025-06-02 15:37:15 +00:00
Oli Scherer
b331b8b96d Use the informative error as the main const eval error message 2025-06-02 15:37:15 +00:00
Yukang
1931272796 Rollup merge of #141892 - chenyukang:yukang-fix-141785-extern-crate, r=petrochenkov
Fix false positive lint error from no_implicit_prelude attr

Fixes rust-lang/rust#141785

r? `@petrochenkov`
2025-06-02 20:57:42 +08:00
Ell
a6a1c1b247 Separately check equality of the scalar types and compound types in the order of declaration. 2025-06-02 15:29:34 +03:00
Jana Dönszelmann
8b5b6d053a add fixme to improve error matching 2025-06-02 14:22:14 +02:00
yukang
7167e7ce06 Fix false positive lint error from no_implicit_prelude attr 2025-06-02 17:49:01 +08:00
Jana Dönszelmann
2e527f03d1 fix bug where borrowck tries to describe a name from a macro in another crate 2025-06-02 11:29:27 +02:00
Jana Dönszelmann
a5f7d44405 add test for 141764 2025-06-02 11:29:27 +02:00
Lukas Wirth
aba70e8f9d Add missing dyn keywords to tests that do not test for them
This ensures that these tests can be run on editions other than 2015
2025-06-02 11:02:50 +02:00
Lukas Wirth
87054fc811 Add missing 2015 edition directives
These tests specifically test 2015 edition behavior, so ensure that they can only be run with this edition
2025-06-02 11:00:46 +02:00
bohan
9b94caef4f allow macro_use as first segment 2025-06-02 16:30:21 +08:00
Michael Goulet
4a803d26ea Suppress redundant error 2025-06-02 02:19:35 +00:00
Michael Goulet
d2d0f62f78 Don't declare variables in ExprKind::Let in invalid positions 2025-06-02 02:19:34 +00:00
Guillaume Gomez
335232d958 Rollup merge of #141224 - RalfJung:no-objects, r=traviscross
terminology: allocated object → allocation

Rust does not have "objects" in memory so "allocated object" is a somewhat odd name. I am not sure where the term comes from. "object" has been used to refer to allocations already [in 1.0 docs](https://doc.rust-lang.org/1.0.0/std/primitive.pointer.html#method.offset); this was apparently later changed to "allocated object".

"Allocation" is already the terminology used in Miri and in the [UCG](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#allocation). We should properly move to that terminology, and avoid any confusion about whether Rust has an object memory model. (It does not. Memory contains untyped bytes.)

Cc ``@rust-lang/opsem`` ``@rust-lang/lang``
2025-06-01 19:35:42 +02:00
Guillaume Gomez
cd0adc9d7b Rollup merge of #140370 - WaffleLapkin:unqualified, r=jdonszelmann
Improve diagnostics for usage of qualified paths within tuple struct exprs/pats

For patterns the old diagnostic was just incorrect, but I also added machine applicable suggestions.

For context, this special cases errors for `<T as Trait>::Assoc(..)` patterns and expressions (latter is just a call). Tuple struct patterns and expressions both live in the value namespace, so they are not forwarded through associated *types*.

r? ``@jdonszelmann``

cc ``@petrochenkov`` in https://github.com/rust-lang/rust/pull/80080#issuecomment-800630582 you were wondering why it doesn't work for types, that's why — tuple patterns are resolved in the value namespace.
2025-06-01 19:35:41 +02:00
Andrew Zhogin
f023a69f32 Async drop - type instead of async drop fn and incorrect drop signature don't ICE now 2025-06-01 15:22:29 +07:00
bors
13a4540908 Auto merge of #141725 - nnethercote:avoid-UsePath-overcounting, r=BoxyUwU
Avoid over-counting of `UsePath` in the HIR stats.

Currently we over-count. Details in the individual commits.

r? `@BoxyUwU`
2025-06-01 04:21:50 +00:00
bors
337c11e593 Auto merge of #141842 - jhpratt:rollup-r7ldrl2, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#141072 (Stabilize feature `result_flattening`)
 - rust-lang/rust#141215 (std: clarify Clone trait documentation about duplication semantics)
 - rust-lang/rust#141277 (Miri CI: test aarch64-apple-darwin in PRs instead of the x86_64 target)
 - rust-lang/rust#141521 (Add `const` support for float rounding methods)
 - rust-lang/rust#141812 (Fix "consider borrowing" for else-if)
 - rust-lang/rust#141832 (library: explain TOCTOU races in `fs::remove_dir_all`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-01 01:02:51 +00:00
Jacob Pratt
542dcbf6a2 Rollup merge of #141812 - JonathanBrouwer:fix-else-if-help, r=jdonszelmann
Fix "consider borrowing" for else-if

Fixes rust-lang/rust#141810

When trying to suggest a borrow on a `if` or `block` expression, instead we now recurse into the `if` or `block`.
The comments in the code should explain the goal of the new code.

r? ``@jdonszelmann``
2025-06-01 00:35:53 +02:00
bors
f0999ffdc4 Auto merge of #139118 - scottmcm:slice-get-unchecked-intrinsic, r=workingjubilee
`slice.get(i)` should use a slice projection in MIR, like `slice[i]` does

`slice[i]` is built-in magic, so ends up being quite different from `slice.get(i)` in MIR, even though they're both doing nearly identical operations -- checking the length of the slice then getting a ref/ptr to the element if it's in-bounds.

This PR adds a `slice_get_unchecked` intrinsic for `impl SliceIndex for usize` to use to fix that, so it no longer needs to do a bunch of lines of pointer math and instead just gets the obvious single statement.  (This is *not* used for the range versions, since `slice[i..]` and `slice[..k]` can't use the mir Slice projection as they're using fenceposts, not indices.)

I originally tried to do this with some kind of GVN pattern, but realized that I'm pretty sure it's not legal to optimize `BinOp::Offset` to `PlaceElem::Index` without an extremely complicated condition.  Basically, the problem is that the `Index` projection on a dereferenced slice pointer *cares about the metadata*, since it's UB to `PlaceElem::Index` outside the range described by the metadata.  But then you cast the fat pointer to a thin pointer then offset it, that *ignores* the slice length metadata, so it's possible to write things that are legal with `Offset` but would be UB if translated in the obvious way to `Index`.  Checking (or even determining) the necessary conditions for that would be complicated and error-prone, whereas this intrinsic-based approach is quite straight-forward.

Zero backend changes, because it just lowers to MIR, so it's already supported naturally by CTFE/Miri/cg_llvm/cg_clif.
2025-05-31 21:38:21 +00:00
Ralf Jung
f388c987cf terminology: allocated object → allocation 2025-05-31 22:49:14 +02:00
bors
4d08223c05 Auto merge of #141824 - matthiaskrgr:rollup-7nffwd0, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#140787 (Note expr being cast when encounter NonScalar cast error)
 - rust-lang/rust#141112 (std: note that `std::str::from_utf8*` functions are aliases to `<str>::from_utf8*` methods)
 - rust-lang/rust#141646 (Document what `distcheck` is intended to exercise)
 - rust-lang/rust#141740 (Hir item kind field order)
 - rust-lang/rust#141793 (`tests/ui`: A New Order [1/N])
 - rust-lang/rust#141805 (Update `compiler-builtins` to 0.1.160)
 - rust-lang/rust#141815 (Enable non-leaf Frame Pointers for mingw-w64 Arm64 Windows)
 - rust-lang/rust#141819 (Fixes for building windows-gnullvm hosts)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-31 18:16:35 +00:00
Matthias Krüger
282c6654a0 Rollup merge of #141793 - Kivooeo:test-reform, r=jieyouxu
`tests/ui`: A New Order [1/N]

not sure if i should say something about changes here, just part of rust-lang/rust#133895

but this is my very first time doing something like this, id love to keep contributing in this area later on, so any feedback is appreciated

also should say that im going to squash it after agreement on changes

r? `@jieyouxu`

mind if i name this PR series like "`tests/ui`: A New Order [N/N]", im not sure if it fits the project tone, so id like your approval first — but i think it sounds really neat (Star Wars reference)

this could be a first part :)
2025-05-31 18:51:49 +02:00
Matthias Krüger
05debb0d0d Rollup merge of #140787 - xizheyin:issue-140491, r=nnethercote
Note expr being cast when encounter NonScalar cast error

Fixes #140491

I added note for `expr` so that it doesn't treat `&x as T` as `&(x as T)` but `(&x) as T`. But I'm not sure if I want to add note for all NonScalar, maybe for specific `expr_ty`?

r? compiler
2025-05-31 18:51:47 +02:00
Jonathan Brouwer
b1a1df2efe Fix consider borrowing for else-if 2025-05-31 18:34:35 +02:00
Jonathan Brouwer
a261d167ac Failing tests for "consider borrowing" 2025-05-31 18:32:50 +02:00
bors
852f15c0f1 Auto merge of #141685 - orlp:inplace-tls-drop, r=joboet
Do not move thread-locals before dropping

Fixes rust-lang/rust#140816. I also (potentially) improved the speed of `get_or_init` a bit by having an explicit hot/cold path.

We still move the value before dropping in the event of a recursive initialization (leading to double-initialization with one value being silently dropped). This is the old behavior, but changing this to panic instead would involve changing tests and also the other OS-specific `thread_local/os.rs` implementation, which is more than I'd like in this PR.
2025-05-31 14:56:33 +00:00
Kivooeo
afc64242b6 cleaned up some tests 2025-05-31 19:49:19 +05:00
bors
ec28ae9454 Auto merge of #141667 - lqd:lazy-maybe-init, r=matthewjasper
Add fast path for maybe-initializedness in liveness

r? `@matthewjasper`

Correct me if I'm wrong Matthew, but my understanding is that
1. `MaybeInitializedPlaces` is currently eagerly computed, in `do_mir_borrowck`
2. but this data is only used in liveness
3. and `liveness::trace` actually only uses it for drop-liveness

This PR moves the computation to `liveness::trace` which looks to be its only use-site. We also add a fast path there, so that it's only computed by drop-liveness.

This is interesting because 1) liveness is only computed for relevant live locals, 2) drop-liveness is only computed for relevant live locals with >0 drop points; 0 is the common case from our benchmarks, as far as I can tell, so even just computing the entire data lazily helps.

It seems possible to also reduce the domain here, and speed up the analysis for the cases where it has to be computed -- so I've left a fixme for that, and may look into it soon.

(I've come upon this while doing implementation work for polonius, so don't be too enamored with possible wins: the goal is to reduce the eventual polonius overhead and make it more palatable 😓)
2025-05-31 04:52:37 +00:00
xizheyin
17352e6937 Note ref expr being cast when encounter NonScalar cast error
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-31 12:19:55 +08:00
Jubilee
955ebfc7d3 Rollup merge of #141781 - matthewjasper:unused-unsafe-lifetimes, r=compiler-errors
Fix spans for unsafe binders

closes rust-lang/rust#141758

r? ``@compiler-errors``
2025-05-30 13:52:28 -07:00
Jubilee
3846f2f08f Rollup merge of #141494 - dianqk:match-br-non-int, r=wesleywiser
mir-opt: Do not transform non-int type in match_branches

Fixes #141378.

r? mir-opt
2025-05-30 13:52:26 -07:00
Jubilee
5e139db47b Rollup merge of #141077 - chenyukang:yukang-fix-140991-comma, r=wesleywiser
Fix the issue of typo of comma in arm parsing

Fixes #140991

I also checked is it a '/', since it's near from ',' from keyboard.
2025-05-30 13:52:25 -07:00
Jubilee
a7e56bff08 Rollup merge of #140825 - rs-sac:ext, r=workingjubilee
Add Range parameter to `BTreeMap::extract_if` and `BTreeSet::extract_if`

This new parameter was requested in the btree_extract_if tracking issue:  https://github.com/rust-lang/rust/issues/70530#issuecomment-2486566328

I attempted to follow the style used by `Vec::extract_if`.

Before:

```rust
impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
    #[unstable(feature = "btree_extract_if", issue = "70530")]
    pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F, A>
    where
        K: Ord,
        F: FnMut(&K, &mut V) -> bool;
}
```

After:

```rust
impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
    #[unstable(feature = "btree_extract_if", issue = "70530")]
    pub fn extract_if<F, R>(&mut self, range: R, pred: F) -> ExtractIf<'_, K, V, R, F, A>
    where
        K: Ord,
        R: RangeBounds<K>,
        F: FnMut(&K, &mut V) -> bool;
}
```

Related: #70530

—

While I believe I have adjusted all of the necessary bits, as this is my first attempt to contribute to Rust, I may have overlooked something out of ignorance, but if you can point out any oversight, I shall attempt to remedy it.
2025-05-30 13:52:24 -07:00
Scott McMurray
4668124cc7 slice.get(i) should use a slice projection in MIR, like slice[i] does 2025-05-30 12:04:41 -07:00
Matthew Jasper
4a1843924e Fix spans for unsafe binders 2025-05-30 16:58:48 +00:00
bors
15825b7161 Auto merge of #139385 - joboet:threadlocal_address, r=nikic
rustc_codegen_llvm: use `threadlocal.address` intrinsic to access TLS

Fixes #136044
r? `@nikic`
2025-05-30 15:39:56 +00:00
Matthias Krüger
4aac899406 Rollup merge of #141746 - Urgau:rework-doc_cfg-checks, r=GuillaumeGomez
Rework `#[doc(cfg(..))]` checks as distinct pass in rustdoc

This PR reworks how rustdoc calls `rustc_attr_parsing::cfg_matches` to be in a separate pass, instead of being wired-up in a ad-hoc way, which is causing problems in https://github.com/rust-lang/rust/pull/138907#issuecomment-2920026627.

This un-does most part of https://github.com/rust-lang/rust/pull/140894, but the result is IMO much cleaner, easier to reason about, and most importantly no longer interfears with rust-lang/rust#138907.

r? `@GuillaumeGomez`
2025-05-30 13:39:54 +02:00
Matthias Krüger
bace7f986c Rollup merge of #141703 - compiler-errors:deref-place, r=lcnr
Structurally normalize types as needed in `projection_ty_core`

Introduce a `structurally_normalize` callback to `projection_ty_core`, and then use it before we match on the ty kind in `projection_ty_core`.

Previously we were only structurally normalizing the return type of the `handle_field` struct, but if we were to (e.g.) apply a deref projection to that type, then the resulting type is not guaranteed to be structurally normalized and any subsequent projections applied would ICE.

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/221

I'll leave a few comments inline to explain the changes.

r? lcnr

---

Also fixes rust-lang/rust#141708
2025-05-30 13:39:52 +02:00
Orson Peters
b374adc9db Address review comments. 2025-05-30 12:14:27 +02:00
Matthias Krüger
71529f59b1 Rollup merge of #141747 - lolbinarycat:rustdoc-cfg-138112, r=GuillaumeGomez
rustdoc: display doc(cfg(false)) properly

before we had an extra 'on' that was
ungramatical.

fixes https://github.com/rust-lang/rust/issues/138112

this is what it looks like now:
![screenshot: Available nowhere](https://github.com/user-attachments/assets/e27b4990-09a7-4f13-8bcf-26d44c8c1bea)
2025-05-30 07:01:31 +02:00
Matthias Krüger
5023691213 Rollup merge of #141538 - folkertdev:systemv-x86_64-va_arg, r=workingjubilee
implement `va_arg` for x86_64 systemv

tracking issue: https://github.com/rust-lang/rust/issues/44930

Turns out LLVM's `va_arg` is also unreliable for this target.

https://github.com/llvm/llvm-project/issues/141361

So, like clang, we implement our own. I used

- the spec at https://gitlab.com/x86-psABIs/x86-64-ABI
- the clang implementation at 9a440f8477/clang/lib/CodeGen/Targets/X86.cpp (L3041)

We can take a bunch of shortcuts because the return type of `va_list` must implement `VaArgSafe`. I also extended some of the tests, because up to 11 floats can be stored in the `reg_safe_area` for this calling convention.

r? `@workingjubilee`
`@rustbot` label +F-c_variadic

try-job: x86_64-apple-1
2025-05-30 07:01:30 +02:00