Commit Graph

48471 Commits

Author SHA1 Message Date
Matthias Krüger
f3622ead6e Rollup merge of #141891 - jdonszelmann:fix-141764, r=jieyouxu
Fix borrowck mentioning a name from an external macro we (deliberately) don't save

Most of the info is already in the title 🤷

Closes rust-lang/rust#141764
2025-06-03 07:03:46 +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
8db6881620 Rollup merge of #141741 - nnethercote:overhaul-UsePath, r=petrochenkov
Overhaul `UsePath`

It currently uses `SmallVec<[Res; 3]>` which is really weird. Details in the individual commits.

r? `@petrochenkov`
2025-06-03 07:03:43 +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
bors
99426c570e Auto merge of #141750 - Noratrieb:gold-rush, r=bjorn3
Warn when gold was used as the linker

gold has been deprecated recently and is known to behave incorrectly around Rust programs, including miscompiling `#[used(linker)]`. Tell people to switch to a different linker instead.

closes rust-lang/rust#141748

r? bjorn3
2025-06-02 23:56:54 +00:00
Nicholas Nethercote
8747ccbcdf Overhaul UsePath.
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res`
results, one per namespace (type, value, or macro). `lower_import_res`
takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the
`SmallVec`. This is pretty weird. The input `PerNS` makes it clear which
`Res` belongs to which namespace, but the `SmallVec` throws that
information away.

And code that operates on the `SmallVec` tends to use iteration (or even
just grabbing the first entry!) without knowing which namespace the
`Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible
type to use here, because it can contain any number of elements (even
though it's optimized for 3 in this case).

This commit changes `UsePath` so it also contains a
`PerNS<Option<Res<HirId>>>`. This type preserves more information and is
more self-documenting. The commit also changes a lot of the use sites to
access the result for a particular namespace. E.g. if you're looking up
a trait, it will be in the `Res` for the type namespace if it's present;
it's silly to look in the `Res` for the value namespace or macro
namespace. Overall I find the new code much easier to understand.

However, some use sites still iterate. These now use `present_items`
because that filters out the `None` results.

Also, `redundant_pub_crate.rs` gets a bigger change. A
`UseKind:ListStem` item gets no `Res` results, which means the old `all`
call in `is_not_macro_export` would succeed (because `all` succeeds on
an empty iterator) and the `ListStem` would be ignored. This is what we
want, but was more by luck than design. The new code detects `ListStem`
explicitly. The commit generalizes the name of that function
accordingly.

Finally, the commit also removes the `use_path` arena, because
`PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be
allocated in the arena shared by all `Copy` types.
2025-06-03 08:23:21 +10:00
Vadim Petrochenkov
6a5bad36a8 resolve: Tweak private_macro_use lint to be compatible with upcoming macro prelude changes 2025-06-03 00:09:54 +03:00
bors
5d707b07e4 Auto merge of #141912 - Kobzol:rollup-wurlnsx, r=Kobzol
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#141767 (ci: use free runner for aarch64-gnu-llvm-19-1 PR job)
 - rust-lang/rust#141858 (Fix typo in `StructuralPartialEq` docs)
 - rust-lang/rust#141865 (Optionally don't steal the THIR)
 - rust-lang/rust#141874 (add f16_epsilon and f128_epsilon diagnostic items)
 - rust-lang/rust#141904 (test-float-parse: apply `cfg(not(bootstrap))`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-02 19:35:39 +00:00
Michael Goulet
9899464906 Fast path for subtype and coercion goals 2025-06-02 19:23:20 +00: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
Jakub Beránek
b2743c7fb1 Rollup merge of #141874 - usamoi:eps, r=tgross35
add f16_epsilon and f128_epsilon diagnostic items

cc https://github.com/rust-lang/rust/issues/116909
r? ``@tgross35``
2025-06-02 15:19:19 +02:00
Jakub Beránek
f8e756b0eb Rollup merge of #141865 - Nadrieril:dont-steal-thir, r=oli-obk
Optionally don't steal the THIR

The THIR being stolen is a recurrent pain for authors of rustc drivers. This makes it optional, so that the `thir_body` query can still be used after analysis of the crate has completed.
2025-06-02 15:19:19 +02: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
Yukang
8d9fc03773 Rollup merge of #141884 - bvanjoi:issue-140255, r=petrochenkov
allow macro_use as first segment

Fixes rust-lang/rust#140255

This issue may raise a question: It's reasonable an external crate name or import target be legally named `macro_use`?
2025-06-02 20:57:41 +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
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
bohan
9b94caef4f allow macro_use as first segment 2025-06-02 16:30:21 +08:00
bors
52882f6522 Auto merge of #119899 - onur-ozkan:redesign-stage0-std, r=albertlarsan68,jieyouxu,mark-simulacrum,kobzol,jyn514,Noratrieb,WaffleLapkin,RalfJung,bjorn3
redesign stage 0 std

### Summary

**Blog post: https://blog.rust-lang.org/inside-rust/2025/05/29/redesigning-the-initial-bootstrap-sequence/**

This PR changes how bootstrap builds the stage 1 compiler by switching to precompiled stage 0 standard library instead of building the in-tree one. The goal was to update bootstrap to use the beta standard library at stage 0 rather than compiling it from source (see the motivation at https://github.com/rust-lang/compiler-team/issues/619).

Previously, to build a stage 1 compiler bootstrap followed this path:

```
download stage0 compiler -> build in-tree std -> compile stage1 compiler with in-tree std
```

With this PR, the new path is:

```
download stage0 compiler -> compile stage1 compiler with precompiled stage0 std
```

This also means that `cfg(bootstrap)`/`cfg(not(bootstrap))` is no longer needed for library development.

### Building "library"

Since stage0 `std` is no longer in-tree `x build/test/check library --stage 0` is now no-op. The minimum supported stage to build `std` is now 1. For the same reason, default stage values in the library profile is no longer 0.

Because building the in-tree library now requires a stage1 compiler, I highly recommend library developers to enable `download-rustc` to speed up compilation time.

<hr>

**Blog post: https://blog.rust-lang.org/inside-rust/2025/05/29/redesigning-the-initial-bootstrap-sequence/**

If you encounter a bug or unexpected results please open a topic in the [#t-infra/bootstrap](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap) Zulip channel or create a [bootstrap issue](https://github.com/rust-lang/rust/issues/new?template=bootstrap.md).

(Review thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Review.20thread.3A.20stage.200.20redesign.20PR/with/508271433)

~~Blocked on https://github.com/rust-lang/rust/pull/122709~~

try-job: dist-x86_64-linux
try-job: `x86_64-msvc*`
try-job: `x86_64-apple-*`
try-job: `aarch64-apple`
try-job: x86_64-gnu
try-job: `x86_64-gnu-llvm*`
2025-06-02 07:49:18 +00:00
bors
91fad92585 Auto merge of #141773 - oli-obk:coro-borrow-parallel-loop, r=compiler-errors
Merge coroutine obligation checking into borrowck parallel loop

r? `@ghost`

attempts at increasing parallelism in parallel rustc by merging parallel blocks that run in sequence
2025-06-02 04:18:14 +00: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
bors
2fc3deed9f Auto merge of #141760 - bjorn3:intrinsic_rework_part2, r=fee1-dead
Improve intrinsic handling in cg_ssa (part 2)

* Avoid computing function type and signature for intrinsics where possible
* Nicer handling of bool returning intrinsics

Follow up to https://github.com/rust-lang/rust/pull/141404
2025-06-02 00:57:45 +00:00
usamoi
d948907f80 add f16_epsilon and f128_epsilon 2025-06-02 08:00:15 +08:00
Nicholas Nethercote
bb063e6e1d Factor out repeated code into is_mod_inherent. 2025-06-02 09:53:35 +10:00
Guillaume Gomez
fc32992a00 Rollup merge of #141834 - Timmmm:user/timh/wasi, r=Noratrieb
Add unimplemented `current_dll_path()` for WASI

This is the only change needed to Rust to allow compiling rustfmt for WASI (rustfmt uses some internal rustc crates).
2025-06-01 19:35:45 +02:00
Guillaume Gomez
b0b98a078d Rollup merge of #141823 - amandasystems:reverse_scc_graph_once_cell, r=jieyouxu
Drive-by refactor: use `OnceCell` for the reverse region SCC graph

During region inference, the reverse SCC region graph is sometimes computed lazily. This changes the implementation for that from using an `Option` to a `OnceCell` which clearly communicates the intention and simplifies the code somewhat.

There shouldn't be any performance impact, except that this pulls the computation of the reverse SCC graph slightly later than before, and so may avoid computing it in some instances.

Note that this changes a mutable reference into an immutable (interior mutable) one.
2025-06-01 19:35:44 +02:00
Guillaume Gomez
d843809b9d Rollup merge of #141666 - lolbinarycat:rustdoc-source_span_for_markdown_range-bug-141665, r=GuillaumeGomez
source_span_for_markdown_range: fix utf8 violation

it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test.

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

r? ``@GuillaumeGomez``
2025-06-01 19:35:43 +02:00
Guillaume Gomez
cf4fbc0695 Rollup merge of #141622 - folkertdev:powerpc-va_arg, r=workingjubilee
implement `va_arg` for `powerpc`

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

The llvm `va_arg` implementation is well-known to have serious limitations. Some planned changes to rust's `VaList` make it much more likely that LLVM miscompiles `va_arg`, so this PR adds support for the various powerpc targets. Now at least the targets that `core` has explicit support for will continue to work.

For `powerpc` (the 32-bit variant) this implementation also fixes a bug where only up to 20 variadic arguments were supported.

Locally (with qemu), these targets now pass the tests in https://github.com/rust-lang/rust/blob/master/tests/run-make/c-link-to-rust-va-list-fn/checkrust.rs. That test does not actually run for the powerpc targets in CI though.

The implementation is based on clang:

- handling of big endian architectures 3c8089d1ea/clang/lib/CodeGen/ABIInfoImpl.cpp (L191-L193)
- 64-bit 3c8089d1ea/clang/lib/CodeGen/Targets/PPC.cpp (L969)
- 32-bit 3c8089d1ea/clang/lib/CodeGen/Targets/PPC.cpp (L430)

cc `@daltenty` (target maintainer)
r? `@workingjubilee`
`@rustbot` label: +F-c_variadic
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
Nadrieril
1e169d8dc4 Optionally don't steal the THIR 2025-06-01 19:14:13 +02:00
bors
9b0268a43b Auto merge of #141731 - compiler-errors:tweak-fast-path-trait, r=lcnr
Tweak fast path trait handling

(1.) Make it more sound by considering polarity (lol)

(2.) Make it more general, by considering higher-ranked size/copy/clone

(2.) Make it less observable, by only doing copy/clone fast path if there are no regions involved

r? lcnr
2025-06-01 10:59:38 +00: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
Tim Hutt
bdd680ffd1 Add unimplemented current_dll_path() for WASI
This is the only change needed to Rust to allow compiling rustfmt for WASI (rustfmt uses some internal rustc crates).
2025-06-01 09:20:05 +01:00
bors
ba55b7ce3c Auto merge of #141730 - osiewicz:collect-crate-deps-postorder-use-indexset, r=nnethercote
cstore: Use IndexSet as backing store for postorder dependencies

`<rustc_metadata::creader::CStore>::push_dependencies_in_postorder` showed up in new benchmarks from https://github.com/rust-lang/rustc-perf/pull/2143, hence I gave it a shot to remove an obvious O(n) there.

r? nnethercote
2025-06-01 07:40:52 +00: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
Deadbeef
c33b08552b Add visit_id to ast Visitor
This helps with efforts to deduplicate the `MutVisitor` and the
`Visitor` code. All users of `Visitor`'s methods that have extra
`NodeId` as parameters really just want to visit the id on its
own.

Also includes some methods deduplicated and cleaned up as
a result of this change.
2025-06-01 02:38:24 +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
Folkert de Vries
be13ce341a implement va_arg for powerpc
This actually fixes a bug where before only 20 arguments could be passed. As far as I can tell, an arbitrary number of arguments is now supported
2025-06-01 00:51:01 +02: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
Jacob Pratt
ac49339e03 Rollup merge of #141521 - ruancomelli:const-float-rounding, r=RalfJung
Add `const` support for float rounding methods

# Add `const` support for float rounding methods

This PR makes the following float rounding methods `const`:

- `f64::{floor, ceil, trunc, round, round_ties_even}`
- and the corresponding methods for `f16`, `f32` and `f128`

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

## Procedure

I followed c09ed3e767 as closely as I could in making float methods `const`, and also received great guidance from https://internals.rust-lang.org/t/const-rounding-methods-in-float-types/22957/3?u=ruancomelli.

## Note

This is my first code contribution to the Rust project, so please let me know if I missed anything - I'd be more than happy to revise and learn more. Thank you for taking the time to review it!
2025-06-01 00:35:53 +02:00
Jacob Pratt
241ec137fb Rollup merge of #141072 - Rynibami:stabilize-const-result-flatten, r=jhpratt
Stabilize feature `result_flattening`

Stabilizes the `Result::flatten` method

## Implementations

- [x] Implementation `Result::flatten`: https://github.com/rust-lang/rust/pull/70140
- [x] Implementation `const` `Result::flatten`: https://github.com/rust-lang/rust/pull/130692
- [x] Update stabilization attribute macros (this PR)

## Stabilization process

- [x] Created this PR [suggested](https://github.com/rust-lang/rust/issues/70142#issuecomment-2885044548) by ``@RalfJung``
- [x] FCP (haven't found any, is it applicable here?)
- [ ] Close issue rust-lang/rust#70142
2025-06-01 00:35:50 +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
binarycat
a8b5e706b7 source_span_for_markdown_range: fix utf8 violation
it is non-trivial to reproduce this bug through rustdoc,
which uses this function less than clippy,
so the regression test was added as a unit test
instead of an integration test.
2025-05-31 14:51:16 -05:00
Jubilee Young
f57ed46bc6 compiler: add CanonAbi 2025-05-31 12:36:01 -07:00