Commit Graph

48721 Commits

Author SHA1 Message Date
bors
2b5e239c6b Auto merge of #144225 - purplesyringa:unwinding-intrinsics, r=nikic
Don't special-case llvm.* as nounwind

Certain LLVM intrinsics, such as `llvm.wasm.throw`, can unwind. Marking them as nounwind causes us to skip cleanup of locals and optimize out `catch_unwind` under inlining or when `llvm.wasm.throw` is used directly by user code.

The motivation for forcibly marking llvm.* as nounwind is no longer present: most intrinsics are linked as `extern "C"` or other non-unwinding ABIs, so we won't codegen `invoke` for them anyway.

Closes rust-lang/rust#132416.

`@rustbot` label +T-compiler +A-panic
2025-07-27 23:05:48 +00:00
bors
f8e355c230 Auto merge of #144434 - nnethercote:preintern-ty-bounds, r=compiler-errors
Preintern some `TyKind::Bound` values

The new trait solver produces a lot of these.

r? `@compiler-errors`
2025-07-27 18:58:43 +00:00
bors
4b596bbd84 Auto merge of #144425 - nnethercote:avoid-new_adt-new_fn_def, r=compiler-errors
Avoid unnecessary `new_adt`/`new_fn_def` calls.

They can be skipped if there are no arguments, avoiding the "relate" operation work and also the subsequent interning.

r? `@ghost`
2025-07-27 15:56:47 +00:00
bors
edc3841c5d Auto merge of #143884 - LorrensP-2158466:resolve-split-define, r=petrochenkov
Resolve: refactor `define` into `define_local` and `define_extern`

Follow up on rust-lang/rust#143550 and part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/with/527348747).

Split up `define` into `define_local` and `define_extern`. Refactor usages of `define` into either one where it's "correct" (idk if everything is correct atm). Big part of this is that `resolution` can now take a `&Resolver` instead of a mutable one.

r? `@petrochenkov`
2025-07-27 12:40:46 +00:00
LorrensP-2158466
451a93e2b8 split up define into define_extern and define_local 2025-07-27 12:17:23 +02:00
bors
eed187cfce Auto merge of #144528 - matthiaskrgr:rollup-felcjc1, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#144226 (Do not assert layout in KnownPanicsLint.)
 - rust-lang/rust#144385 (Optimize performance by inline in macro hygiene system)
 - rust-lang/rust#144454 (move uefi test to run-make)
 - rust-lang/rust#144455 (Unify LLVM ctlz/cttz intrinsic generation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-27 09:38:27 +00:00
Matthias Krüger
dd6e4a9206 Rollup merge of #144455 - TDecking:ctlz-cttz, r=SparrowLii
Unify LLVM ctlz/cttz intrinsic generation

The type signature for `llvm.ctlz` is the same as the one for `llvm.cttz`, which enables a small simplification.
2025-07-27 10:19:02 +02:00
Matthias Krüger
e0a42996d5 Rollup merge of #144385 - xizheyin:macro-hygiene, r=petrochenkov
Optimize performance by inline in macro hygiene system

I inline some small method in `rustc_span/src/hygiene.rs` and so on.
2025-07-27 10:19:01 +02:00
Matthias Krüger
58f10376f4 Rollup merge of #144226 - cjgillot:known-panics-panics, r=oli-obk
Do not assert layout in KnownPanicsLint.

Fixes rust-lang/rust#121176
Fixes rust-lang/rust#129109
Fixes rust-lang/rust#130970
Fixes rust-lang/rust#131347
Fixes rust-lang/rust#139872
Fixes rust-lang/rust#140332
2025-07-27 10:19:00 +02:00
bors
86ef320294 Auto merge of #144347 - scottmcm:ssa-enums-v0, r=WaffleLapkin
No longer need `alloca`s for consuming `Result<!, i32>` and similar

In optimized builds GVN gets rid of these already, but in `opt-level=0` we actually make `alloca`s for this, which particularly impacts `?`-style things that use actually-only-one-variant types like this.

While doing so, rewrite `LocalAnalyzer::process_place` to be non-recursive, solving a 6+ year old FIXME.

r? codegen
2025-07-27 06:37:55 +00:00
Jacob Pratt
8aa3d41b85 Rollup merge of #144480 - Zalathar:revert-empty-span, r=Zalathar
Revert "coverage: Enlarge empty spans during MIR instrumentation, not codegen"

Surprisingly, rust-lang/rust#144298 alone (extracted from rust-lang/rust#140847) was enough to re-trigger the failures observed in https://github.com/rust-lang/rust/issues/141577#issuecomment-3120667286.

---

This reverts commit f877aa7d14.

---

r? ghost
2025-07-26 22:42:39 -04:00
Jacob Pratt
aaa37e55d7 Rollup merge of #144429 - Gelbpunkt:outline-atomics-aarch64-musl, r=Amanieu
Enable outline-atomics for aarch64-unknown-linux-musl

They were disabled in bd287fa508 and haven't been causing problems for a while anymore, see https://github.com/rust-lang/rust/issues/89626 for details.

The entire testsuite still passes on `aarch64-unknown-linux-musl` with this feature enabled.
2025-07-26 22:42:36 -04:00
Jacob Pratt
c92d61d121 Rollup merge of #144409 - GuillaumeGomez:macro-expansion-early-abort, r=oli-obk
Stop compilation early if macro expansion failed

Fixes rust-lang/rust#116180.

So there isn't really a type that is central for macro expansion and some errors are actually emitted (because the resolution happens after the expansion I suppose) after the expansion pass (like "not found macro"). Sometimes, errors are only emitted on the second "try" (to improve error output). So I couldn't reach a similar solution than what was done in https://github.com/rust-lang/rust/pull/133937 and suggested by ````@estebank```` in https://github.com/rust-lang/rust/issues/116180#issuecomment-3109468922. But maybe I missed something?

So in the end, I realized that there is method called every time (except one, described below) a macro error is actually emitted: `ExtCtxt::trace_macros_diag`. Considering I updated what it did, I renamed it into `macro_error_and_trace_macros_diag` to better reflect it.

There is only one call of `trace_macros_diag` which isn't reporting an error but just used for `macro_trace` feature, so I kept it as is.

r? ````@oli-obk````
2025-07-26 22:42:35 -04:00
Jacob Pratt
2c395c7759 Rollup merge of #144383 - ZuseZ4:disable-f128-on-amdgcn, r=oli-obk
disable cfg.has_reliable_f128 on amdgcn

I was experimenting with compiling a few kernels for amd while working on std::offload. It seems like the logic in https://github.com/rust-lang/compiler-builtins/pull/737 got removed, so I re-introduce it here. Probably should have a test to avoid another regression and make sure that f128 doesn't show up as target feature for amdgcn. It looks like currently we neither check that for nvptx, nor amdgpu. Maybe I could add two revisions to https://github.com/rust-lang/rust/blob/master/tests/ui/float/target-has-reliable-nightly-float.rs?
r? ````@Flakebi````

fixes: https://github.com/rust-lang/rust/issues/144381
2025-07-26 22:42:34 -04:00
bors
283a0746a2 Auto merge of #143860 - scottmcm:transmute-always-rvalue, r=WaffleLapkin
Let `codegen_transmute_operand` just handle everything

When combined with rust-lang/rust#143720, this means `rvalue_creates_operand` can just return `true` for *every* `Rvalue`.  (A future PR could consider removing it, though just letting it optimize out is fine for now.)

It's nicer anyway, IMHO, because it avoids needing the layout checks to be consistent in the two places, and thus is an overall reduction in code.  Plus it's a more helpful building block when used in other places this way.

(TBH, it probably would have been better to have it this way the whole time, but I clearly didn't understand `rvalue_creates_operand` when I originally wrote rust-lang/rust#109843.)
2025-07-26 22:45:18 +00:00
Camille GILLOT
8817572b45 Do not check Sync during type_of. 2025-07-26 21:53:13 +00:00
bors
ce5fdd7d42 Auto merge of #143500 - compiler-errors:characterize-less, r=lcnr
Skip walking into param-env component if it has no placeholder/re-var

Although it only provides a minor perf improvement, it seems like it could matter in more pathological cases.
2025-07-26 16:57:45 +00:00
Matthias Krüger
429cc9a0dd Rollup merge of #144468 - petrochenkov:resolution, r=lqd,SparrowLii
resolve: Do not create `NameResolutions` on access unless necessary

`fn resolution` now just performs the access, and `fn resolution_or_default` will insert a default entry if the entry is missing.
2025-07-26 15:28:04 +02:00
Matthias Krüger
576af9b779 Rollup merge of #144462 - Kobzol:pretty-print-self-profile-args, r=RalfJung
Allow pretty printing paths with `-Zself-profile-events=args`

`-Zself-profile-events=args` is pretty heavy and can pretty print a lot of stuff. Rather than hunting down specific cases where this happens, I'd just allow calling `trimmed_def_paths` in this mode.

Fixes: https://github.com/rust-lang/rust/issues/144457

r? `@RalfJung`
2025-07-26 15:28:03 +02:00
Matthias Krüger
d88aa06cd9 Rollup merge of #144448 - camsteffen:defaultness-impl-trait-only, r=compiler-errors
Limit defaultness query to impl of trait

I separated this out from https://github.com/rust-lang/rust/pull/144386.
2025-07-26 15:28:02 +02:00
Matthias Krüger
b2659bf7e5 Rollup merge of #144421 - JonathanBrouwer:cleanup-malformed-list, r=oli-obk
Call `is_parsed_attribute` rather than keeping track of a list of parsed attributes manually

r? ```@oli-obk```

Nicer code & will prevent issues like https://github.com/rust-lang/rust/pull/144358 in the future
2025-07-26 15:28:00 +02:00
Matthias Krüger
43096cc932 Rollup merge of #144376 - estebank:issue-143795, r=lcnr
Suggest unwrapping when private method name is available in inner type

Given

```rust
fn main() {
    let maybe_vec = Some(vec![1,2,3]);
    assert_eq!(maybe_vec.len(), 3);
}
```

suggest unwraping `maybe_vec` to call `.len()` on the `Vec<_>`.

```
error[E0624]: method `len` is private
  --> $DIR/enum-method-probe.rs:61:9
   |
LL |     res.len();
   |         ^^^ private method
  --> $SRC_DIR/core/src/option.rs:LL:COL
   |
   = note: private method defined here
   |
note: the method `len` exists on the type `Vec<{integer}>`
  --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
help: consider using `Option::expect` to unwrap the `Vec<{integer}>` value, panicking if the value is an `Option::None`
   |
LL |     res.expect("REASON").len();
   |        +++++++++++++++++
```

When a method isn't available, we emit E0599, but when it is private we emit E0624. We now just invoke the same suggestion logic from the later that we already did in the former.

Fix rust-lang/rust#143795.
2025-07-26 15:27:59 +02:00
Matthias Krüger
c9541a2bf8 Rollup merge of #144331 - jplatte:matches-allow-non_exhaustive_omitted_patterns, r=Nadrieril
Disable non_exhaustive_omitted_patterns within matches! macro

Closes rust-lang/rust#117304.

I believe I can skip all of the bootstrap stuff mentioned in https://github.com/rust-lang/rust/issues/117304#issuecomment-1784414453 due to https://blog.rust-lang.org/inside-rust/2025/05/29/redesigning-the-initial-bootstrap-sequence/, right?

cc `@Jules-Bertholet`
2025-07-26 15:27:58 +02:00
bors
8708f3cd1f Auto merge of #144490 - tgross35:rollup-ps0utme, r=tgross35
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#140871 (Don't lint against named labels in `naked_asm!`)
 - rust-lang/rust#141663 (rustdoc: add ways of collapsing all impl blocks)
 - rust-lang/rust#143272 (Upgrade the `fortanix-sgx-abi` dependency)
 - rust-lang/rust#143585 (`loop_match`: suggest extracting to a `const` item)
 - rust-lang/rust#143698 (Fix unused_parens false positive)
 - rust-lang/rust#143859 (Guarantee 8 bytes of alignment in Thread::into_raw)
 - rust-lang/rust#144160 (tests: debuginfo: Work around or disable broken tests on powerpc)
 - rust-lang/rust#144412 (Small cleanup: Use LocalKey<Cell> methods more)
 - rust-lang/rust#144431 (Disable has_reliable_f128_math on musl targets)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-26 10:12:14 +00:00
Trevor Gross
39141d01f1 Rollup merge of #144431 - Gelbpunkt:f128-math-musl, r=petrochenkov,tgross35
Disable has_reliable_f128_math on musl targets

musl does not implement the symbols required by rustc for f128 maths. Disable the associated cfg for all musl targets and adjust the tests accordingly.

Closes rust-lang/rust#144423
2025-07-26 02:19:31 -05:00
Trevor Gross
bfacbf2a3d Rollup merge of #144412 - camsteffen:localkey-cell-refactors, r=petrochenkov
Small cleanup: Use LocalKey<Cell> methods more
2025-07-26 02:19:30 -05:00
Trevor Gross
75ed6de1ee Rollup merge of #143698 - benschulz:unused-parens-2, r=lcnr,compiler-errors
Fix unused_parens false positive

Resolves rust-lang/rust#143653.

The "no bounds exception" was indiscriminately set to `OneBound` for referents and pointees. However, if the reference or pointer type itself appears in no-bounds position, any constraints it has must be propagated.

```rust
// unused parens: not in no-bounds position
fn foo(_: Box<(dyn Send)>) {}

// unused parens: in no-bounds position, but one-bound exception applies
fn bar(_: Box<dyn Fn(&u32) -> &(dyn Send)>) {}

// *NOT* unused parens: in no-bounds position, but no exceptions to be made
fn baz(_: Box<dyn Fn(&u32) -> &(dyn Send) + Send>) {}
```
2025-07-26 02:19:28 -05:00
Trevor Gross
d8f4ceb8c0 Rollup merge of #143585 - folkertdev:loop-match-suggest-const-block, r=oli-obk
`loop_match`: suggest extracting to a `const` item

tracking issue: https://github.com/rust-lang/rust/issues/132306
fixes https://github.com/rust-lang/rust/issues/143310
fixes https://github.com/rust-lang/rust/issues/143936
2025-07-26 02:19:28 -05:00
Trevor Gross
33ed3fc07f Rollup merge of #140871 - Amanieu:naked-asm-label, r=compiler-errors
Don't lint against named labels in `naked_asm!`

Naked functions are allowed to define global labels, just like `global_asm!`.
2025-07-26 02:19:26 -05:00
Trevor Gross
2671afeb9e Rollup merge of #144352 - heiher:llvm-22, r=dianqk
RustWrapper: Suppress getNextNonDebugInfoInstruction

Link: https://github.com/llvm/llvm-project/pull/144383
2025-07-26 01:15:08 -05:00
Trevor Gross
72e3767380 Rollup merge of #144201 - estebank:suggest-clone, r=SparrowLii
Mention type that could be `Clone` but isn't in more cases

When encountering a moved value of a type that isn't `Clone` because of unmet obligations, but where all the unmet predicates reference crate-local types, mention them and suggest cloning, as we do in other cases already:

```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
  --> f111.rs:14:25
   |
13 | fn do_stuff(foo: Option<Foo>) {
   |             --- captured outer variable
14 |     require_fn_trait(|| async {
   |                      -- ^^^^^ `foo` is moved here
   |                      |
   |                      captured by this `Fn` closure
15 |         if foo.map_or(false, |f| f.foo()) {
   |            ---
   |            |
   |            variable moved due to use in coroutine
   |            move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
   |
note: if `Foo` implemented `Clone`, you could clone the value
  --> f111.rs:4:1
   |
4  | struct Foo;
   | ^^^^^^^^^^ consider implementing `Clone` for this type
...
15 |         if foo.map_or(false, |f| f.foo()) {
   |            --- you could clone this value
```

CC rust-lang/rust#68119.
2025-07-26 01:15:05 -05:00
Trevor Gross
3f7d497c8a Rollup merge of #144171 - Nadrieril:exhaustive-witnesses, r=davidtwco
pattern_analysis: add option to get a full set of witnesses

This adds an option to the rustc_pattern_analysis machinery to have it report a complete set of patterns when a match is non-exhaustive (by default we only guarantee to report _some_ missing patterns). This is for use in rust-analyzer.

Leaving as draft until I'm sure this is what r-a needs.

r? ghost
2025-07-26 01:15:04 -05:00
Jens Reidel
53018dc2bc Disable has_reliable_f128_math on musl targets
musl does not implement the symbols required by std for f128 maths.
Disable the associated cfg for all musl targets and adjust the tests
accordingly.

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-07-26 07:01:55 +02:00
bors
f32b23204a Auto merge of #139597 - Kobzol:lint-skip, r=BoxyUwU
Do not run per-module late lints if they can be all skipped

We run ~70 late lints for all dependencies even if they use `--cap-lints=allow`, which seems wasteful. It looks like these lints are super fast (unlike early lints), but still.

r? `@ghost`
2025-07-26 02:31:12 +00:00
Zalathar
2b17897092 Revert "coverage: Enlarge empty spans during MIR instrumentation, not codegen"
This reverts commit f877aa7d14.
2025-07-26 11:14:40 +10:00
Amanieu d'Antras
1f4561b63d Don't lint against named labels in naked_asm!
Naked functions are allowed to define global labels, just like
`global_asm!`.
2025-07-26 00:42:21 +01:00
Camille GILLOT
7c6496145f Check statics' type in type_of. 2025-07-25 23:39:26 +00:00
Camille GILLOT
ec8146477e Look at layout for completeness. 2025-07-25 23:07:31 +00:00
Folkert de Vries
730d33dd64 loop_match: suggest extracting to a const item
if the expression cannot be evaluated in a straightforward way
2025-07-26 00:10:56 +02:00
Guillaume Gomez
96340f6714 Stop compilation if macro expansion failed 2025-07-25 23:46:28 +02:00
Vadim Petrochenkov
e82011255b resolve: Do not create NameResolutions on access unless necessary 2025-07-26 00:25:26 +03:00
Vadim Petrochenkov
2c65790160 resolve: Minimize borrow scopes for resolutions 2025-07-26 00:19:12 +03:00
Jakub Beránek
4ef18ab062 Allow pretty printing paths with -Zself-profile-events=args 2025-07-25 22:24:21 +02:00
Esteban Küber
11061831f7 Mention type that could be Clone but isn't in more cases
When encountering a moved value of a type that isn't `Clone` because of unmet obligations, but where all the unmet predicates reference crate-local types, mention them and suggest cloning, as we do in other cases already:

```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
  --> f111.rs:14:25
   |
13 | fn do_stuff(foo: Option<Foo>) {
   |             --- captured outer variable
14 |     require_fn_trait(|| async {
   |                      -- ^^^^^ `foo` is moved here
   |                      |
   |                      captured by this `Fn` closure
15 |         if foo.map_or(false, |f| f.foo()) {
   |            ---
   |            |
   |            variable moved due to use in coroutine
   |            move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
   |
note: if `Foo` implemented `Clone`, you could clone the value
  --> f111.rs:4:1
   |
4  | struct Foo;
   | ^^^^^^^^^^ consider implementing `Clone` for this type
...
15 |         if foo.map_or(false, |f| f.foo()) {
   |            --- you could clone this value
```
2025-07-25 18:34:10 +00:00
Tobias Decking
948c7952b8 Unify LLVM ctlz/cttz intrinsic generation 2025-07-25 17:56:10 +02:00
Cameron Steffen
cf4d7938cf Limit defaultness to impl of trait 2025-07-25 08:49:31 -05:00
Matthias Krüger
1caf701653 Rollup merge of #144392 - makai410:rm-mov, r=scottmcm
rustc_public: Remove movability from `RigidTy/AggregateKind::Coroutine`

Part of rust-lang/rust#119174 .
I think we should be good now to sync this change in rustc_public.
2025-07-25 11:16:39 +02:00
Matthias Krüger
acd4a1ccd2 Rollup merge of #144390 - oli-obk:arbitrary-enum-discrs, r=SparrowLii
Remove dead code and extend test coverage and diagnostics around it

I was staring a bit at the `dont_niche_optimize_enum` variable and figured out that part of it is dead code (at least today it is). I changed the diagnostic and test around the code that makes that part dead code, so everything that makes removing that code sound is visible in this PR
2025-07-25 11:16:39 +02:00
Matthias Krüger
9c257e59c2 Rollup merge of #144368 - petrochenkov:rmrootscope, r=b-naber
resolve: Remove `Scope::CrateRoot`

Use `Scope::Module` with the crate root module inside instead, which should be identical.
This is a simplification by itself, but it will be even larger simplification if something like https://github.com/rust-lang/rust/pull/144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs).

I also did some renamings for consistency:
- `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude`
- `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude`
- `is_absolute_path` -> `module_and_extern_prelude`
2025-07-25 11:16:38 +02:00
Matthias Krüger
f414e7ac54 Rollup merge of #144209 - scottmcm:assume_less, r=lcnr,dianqk
Don't emit two `assume`s in transmutes when one is a subset of the other

For example, transmuting between `bool` and `Ordering` doesn't need two `assume`s because one range is a superset of the other.

Multiple are still used for things like `char` <-> `NonZero<u32>`, which overlap but where neither fully contains the other.
2025-07-25 11:16:36 +02:00