Commit Graph

50507 Commits

Author SHA1 Message Date
usamoi
21dd997aec support link modifier as-needed for raw-dylib-elf 2025-10-06 08:56:40 +08:00
bors
839222065a Auto merge of #147384 - workingjubilee:rollup-2qqqfn4, r=workingjubilee
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#147327 (cg_llvm: Remove inherent methods from several LLVM FFI types)
 - rust-lang/rust#147332 (Set opt-level flag for installing tool only on CI)
 - rust-lang/rust#147374 (bootstrap: don't build book redirect pages during dry-run/test)
 - rust-lang/rust#147376 (bootstrap: relax `compiler-rt` root assertion)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-05 19:03:28 +00:00
Jubilee
d8fc465bbb Rollup merge of #147327 - Zalathar:inherent, r=workingjubilee
cg_llvm: Remove inherent methods from several LLVM FFI types

This is mainly motivated by rust-lang/rust#142897, which proposes to move the LLVM FFI bindings out of `rustc_codegen_llvm` and into `rustc_llvm`, which is arguably the more correct place for them from a linking perspective.

---

In order to perform that migration, all of the types used in FFI signatures also need to be moved. However, several of those types have inherent methods that convert from backend-independent types to LLVM FFI types.

Moving the inherent methods as-is would require adding a lot of otherwise-unnecessary dependencies to `rustc_llvm`. And we can't leave them behind as-is, because inherent methods can't be defined in another crate.

Therefore, this PR replaces several of those inherent methods with either extension trait methods or free functions.
2025-10-05 11:59:23 -07:00
bors
981353ca16 Auto merge of #147345 - Kivooeo:tidy-flt-fix, r=Kobzol
Tidy: revert `flt` to `ftl`

As was explained here https://github.com/rust-lang/rust/pull/147191#issuecomment-3353801210, this reverting this change because `flt` is incorrect format

Also maybe there is existed PR for that? I didn't found one

Follow up https://github.com/rust-lang/rust/pull/147191

cc `@GuillaumeGomez`
2025-10-05 15:55:18 +00:00
Stuart Cook
21b5d6bd86 Rollup merge of #147369 - Noratrieb:avr-metadata, r=jieyouxu
Fill out AVR target metadata

This will make `-Zbuild-std` automatically build the right crates, notably not building `std` by default, which will both be useful for users and also fix the build for https://does-it-build.noratrieb.dev, which currently tries to build std: http://localhost:3000/build?nightly=2025-07-12&target=avr-none&mode=std.

cc `@Patryk27` but I don't think this necessarily needs your approval
2025-10-05 22:15:08 +11:00
Stuart Cook
94e04993a1 Rollup merge of #147367 - chenyukang:yukang-trivial-cleanup, r=jieyouxu
Trivial code cleanup in resolve

r? `@jieyouxu`
2025-10-05 22:15:07 +11:00
Stuart Cook
d97e346ac7 Rollup merge of #147262 - JonathanBrouwer:fix-link, r=jieyouxu
Make #[link="dl"] an FCW rather than an error

Fixes https://github.com/rust-lang/rust/issues/147254
I forgot to implement the T-lang decision in https://github.com/rust-lang/rust/pull/143193#issuecomment-3138479942, this implements that decision

r? ``@jdonszelmann``
Can be reviewed commit-by-commit
This needs a beta backport
2025-10-05 22:15:06 +11:00
nora
9ccaf080cb Fill out AVR target metadata
This will make `-Zbuild-std` automatically build the right crates, notably not building `std` by default, which will both be useful for users and also fix the build for https://does-it-build.noratrieb.dev.
2025-10-05 12:01:23 +02:00
yukang
95445f9b96 Trivial code cleanup in resolve 2025-10-05 17:27:45 +08:00
Stuart Cook
80759350c7 Rollup merge of #147337 - ada4a:write-diag-item, r=fmease
Make `fmt::Write` a diagnostic item

I'm working on an enhancement to [`clippy::format_push_string`](https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string), which would suggest an autofix to replace `push_str`/`+=` with `write!`. But that could require importing `std::fmt::Write`, and so I need this diagnostic item to check if it's already in scope.

The reason I called it `FmtWrite` and not just `Write` is that there's already an `IoWrite` defined.
2025-10-05 15:35:04 +11:00
Stuart Cook
cae84c695a Rollup merge of #147320 - chenyukang:yukang-fix-147303-fn-arg, r=jieyouxu
Avoid to suggest pattern match on the similarly named in fn signature

Fixes rust-lang/rust#147303
2025-10-05 15:35:03 +11:00
Stuart Cook
620ffe6595 Rollup merge of #147310 - Jules-Bertholet:maybe-incorrect-pattern-typo, r=chenyukang
Mark `PatternTypo` suggestion as maybe incorrect

Partial fix for https://github.com/rust-lang/rust/issues/147303.

`@rustbot` label A-diagnostics A-suggestion-diagnostics D-invalid-suggestion
2025-10-05 15:35:03 +11:00
bors
227ac7c3cd Auto merge of #147293 - nnethercote:avoid-dep_dep_node, r=saethlin
Avoid getting `dep_dep_node` unnecessarily.

It's gotten on a hot path but only for use within `debug!`.

r? `@saethlin`
2025-10-04 21:23:46 +00:00
Kivooeo
67bc030833 change flt back to ftl 2025-10-04 18:18:58 +00:00
Matthias Krüger
dade9fe04b Rollup merge of #147251 - jackh726:global-cache-non-concurrent-change, r=lcnr
Do not assert that a change in global cache only happens when concurrent

Fixes rust-lang/trait-system-refactor-initiative#234

I think it should just be safe to remove this assert (rather than delaying a bug). If the previous and current result are the same, I wouldn't expect issues.

r? lcnr
2025-10-04 17:11:12 +02:00
Matthias Krüger
3f7b8c5198 Rollup merge of #147117 - iximeow:ixi/illumos-used-attr, r=Noratrieb
interpret `#[used]` as `#[used(compiler)]` on illumos

helps rust-lang/rust#146169 not be as painful: fixes the illumos regression in rust-lang/rust#140872, but `#[used(linker)]` is still erroneous on illumos generally.

illumos' `ld` does not support a flag like either SHF_GNU_RETAIN or SHF_SUNW_NODISCARD, so there is no way to communicate `#[used(linker)]` for that target. Setting `USED_LINKER` to try results in LLVM setting SHF_SUNW_NODISCARD for Solaris-like targets, which is an unknown section header flag for illumos `ld` and prevents sections from being merged that otherwise would.

As a motivating example, the `inventory` crate produces `#[used]` items to merge into `.init_array`. Because those items have an unknown section header flag they are not merged with the default `.init_array` with `frame_dummy`, and end up never executed.

Downgrading `#[used]` to `#[used(compiler)]` on illumos keeps so-attributed items as preserved as they had been before https://github.com/rust-lang/rust/pull/140872. As was the case before that change, because rustc passes `-z ignore` to illumos `ld`, it's possible that `used` sections are GC'd at link time. https://github.com/rust-lang/rust/issues/146169 describes this unfortunate circumstance.

----

as it turns out, `tests/ui/attributes/used_with_archive.rs` had broken on `x86_64-unknown-illumos`, and this patch fixes it. the trials and tribulations of tier 2 :(

r? ````@Noratrieb```` probably?
2025-10-04 17:11:11 +02:00
Ada Alakbarova
2688f601dd Make fmt::Write a diagnostic item 2025-10-04 16:07:06 +02:00
Jonathan Brouwer
1c85a1dc2e Make #[link="dl"] a warning rather than an error 2025-10-04 11:22:56 +02:00
yukang
e9a45e6646 Avoid to suggest pattern match on the similarly named in fn signature 2025-10-04 17:12:41 +08:00
Zalathar
f8c54d24e2 Remove inherent methods from llvm::CallConv::from_conv 2025-10-04 18:47:18 +10:00
Zalathar
3831b60ef3 Remove inherent methods from llvm::Type 2025-10-04 18:47:18 +10:00
Zalathar
0661a3d6fe Remove inherent methods from coverageinfo::ffi::Counter
This patch also moves `Regions` to a different module, since that type can stay
put when the FFI bindings move to another crate.
2025-10-04 18:46:15 +10:00
Zalathar
f955c76a5b Remove inherent methods from several LLVM FFI types
Using a helper trait allows the conversions to remain in `rustc_codegen_llvm`,
even if the FFI types are moved to a different crate.
2025-10-04 18:16:13 +10:00
bors
a0f398e89d Auto merge of #147308 - matthiaskrgr:rollup-ov04tbi, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#147245 (only replace the intended comma in pattern suggestions)
 - rust-lang/rust#147269 (Add regression test for 123953)
 - rust-lang/rust#147277 (Extract common logic for iterating over features)
 - rust-lang/rust#147292 (Respect `-Z` unstable options in `rustdoc --test`)
 - rust-lang/rust#147300 (Add xtensa arch to object file creation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-04 06:19:58 +00:00
bors
7950f244e7 Auto merge of #147299 - compiler-errors:hr-norm, r=jackh726
Don't normalize higher-ranked assumptions if they're not used

See the comment in the code.

Normalizing these assumptions may cause us to register things like new placeholder outlives obligations that cause higher-ranked lifetime errors, and this is problematic if we're not even using these assumptions in borrowck.

Fixes rust-lang/rust#147244
Fixes rust-lang/rust#147285
2025-10-04 00:02:26 +00:00
iximeow
c721fa2438 interpret #[used] as #[used(compiler)] on illumos
illumos' `ld` does not support a flag like either SHF_GNU_RETAIN or
SHF_SUNW_NODISCARD, so there is no way to communicate `#[used(linker)]`
for that target. Setting `USED_LINKER` to try results in LLVM setting
SHF_SUNW_NODISCARD for Solaris-like targets, which is an unknown section
header flag for illumos `ld` and prevents sections from being merged
that otherwise would.

As a motivating example, the `inventory` crate produces
`#[used]` items to merge into `.init_array`. Because those items have an
unknown section header flag they are not merged with the default
`.init_array` with `frame_dummy`, and end up never executed.

Downgrading `#[used]` to `#[used(compiler)]` on illumos keeps
so-attributed items as preserved as they had been before
https://github.com/rust-lang/rust/pull/140872. As was the case before
that change, because rustc passes `-z ignore` to illumos `ld`, it's
possible that `used` sections are GC'd at link time.
https://github.com/rust-lang/rust/issues/146169 describes this
unfortunate circumstance.
2025-10-03 22:03:24 +00:00
jackh726
55aeb1747d Do not assert that a change in global cache only happens when concurrent 2025-10-03 16:21:15 -04:00
Jules Bertholet
d5ba5c1c92 Mark PatternTypo suggestion as maybe incorrect 2025-10-03 16:00:15 -04:00
Matthias Krüger
30442dc496 Rollup merge of #147300 - esp-rs:xtensa-meta, r=saethlin
Add xtensa arch to object file creation

Just something that was missed in the xtensa target PRs.
2025-10-03 21:10:34 +02:00
Matthias Krüger
9e477c4386 Rollup merge of #147277 - fee1-dead-contrib:featiter, r=Zalathar
Extract common logic for iterating over features

Two places doing the same thing is enough to motivate me to extract this to a method :)
2025-10-03 21:10:33 +02:00
Matthias Krüger
2e06dcdbeb Rollup merge of #147245 - karolzwolak:only-replace-intended-bar-not-all-in-pattern, r=lcnr
only replace the intended comma in pattern suggestions

Only suggest to replace the intended comma, not all bars in the pattern.
Fixes rust-lang/rust#143330.
This continues rust-lang/rust#143331, the credit for making the fix goes to `@A4-Tacks.` I just blessed tests and added a regression test.
2025-10-03 21:10:31 +02:00
Scott Mabin
3f9c493da1 Add xtensa arch to object file creation 2025-10-03 16:10:26 +01:00
bors
f437c86ef8 Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Fix backtraces with `-C panic=abort` on linux; emit unwind tables by default

The linux backtrace unwinder relies on unwind tables to work properly, and generating and printing a backtrace is done by for example the default panic hook.

Begin emitting unwind tables by default again with `-C panic=abort` (see history below) so that backtraces work.

Closes https://github.com/rust-lang/rust/issues/81902 which is **regression-from-stable-to-stable**
Closes https://github.com/rust-lang/rust/issues/94815

### History

Backtraces with `-C panic=abort` used to work in Rust 1.22 but broke in Rust 1.23, because in 1.23 we stopped emitting unwind tables with `-C panic=abort` (see https://github.com/rust-lang/rust/pull/45031 and https://github.com/rust-lang/rust/issues/81902#issuecomment-3046487084).

In 1.45 a workaround in the form of `-C force-unwind-tables=yes` was added (see https://github.com/rust-lang/rust/pull/69984).

`-C panic=abort` was added in [Rust 1.10](https://blog.rust-lang.org/2016/07/07/Rust-1.10/#what-s-in-1-10-stable) and the motivation was binary size and compile time. But given how confusing that behavior has turned out to be, it is better to make binary size optimization opt-in with `-C force-unwind-tables=no` rather than default since the current default breaks backtraces.

Besides, if binary size is a primary concern, there are many other tricks that can be used that has a higher impact.

# Release Note Entry Draft:

## Compatibility Notes

* [Fix backtraces with `-C panic=abort` on Linux by generating unwind tables by default](https://github.com/rust-lang/rust/pull/143613). Build with `-C force-unwind-tables=no` to keep omitting unwind tables.

try-job: aarch64-apple
try-job: armhf-gnu
try-job: aarch64-msvc-1
2025-10-03 15:02:37 +00:00
Michael Goulet
e3f104608c Don't normalize higher-ranked assumptions if they're not used 2025-10-03 10:32:23 -04:00
bors
8b6b15b877 Auto merge of #142771 - dianqk:mir-stmt-debuginfo, r=cjgillot
Introduce debuginfo to statements in MIR

The PR introduces support for debug information within dead statements. Currently, only the reference statement is supported, which is sufficient to fix rust-lang/rust#128081.

I don't modify Stable MIR, as I don't think we need debug information when using it.

This PR represents the debug information for the dead reference statement via `#dbg_value`. For example, `let _foo_b = &foo.b` becomes `#dbg_value(ptr %foo, !22, !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value), !26)`. You can see this here: https://rust.godbolt.org/z/d43js6adv.

The general principle for handling debug information is to never provide less debug information than the optimized LLVM IR.

The current rules for dropping debug information in this PR are:

- If the LLVM IR cannot represent a reference address, it's replaced with poison or simply dropped. For example, see: https://rust.godbolt.org/z/shGqPec8W. I'm using poison in all such cases now.
- All debuginfos is dropped when merging multiple successor BBs. An example is available here: https://rust.godbolt.org/z/TE1q3Wq6M.

I doesn't drop debuginfos in `MatchBranchSimplification`, because LLVM also pick one branch for it.
2025-10-03 11:49:42 +00:00
Nicholas Nethercote
3a287e6034 Remove some unnecessary locals.
They both have a single use. (They can't be united, though, because
`self.colors` might change between the two `get` calls.)
2025-10-03 20:36:21 +10:00
Nicholas Nethercote
cb0f969b62 Avoid getting dep_dep_node unnecessarily.
It's gotten on a hot path but only for use within `debug!`.
2025-10-03 20:34:56 +10:00
bors
3b8665c5ab Auto merge of #147282 - Zalathar:rollup-7wz3k9r, r=Zalathar
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#141839 (make rust-analyzer use a dedicated build directory)
 - rust-lang/rust#146166 (Implement range support in `//@ edition`)
 - rust-lang/rust#147259 (cg_llvm: Use helper methods for all calls to `LLVMMDNodeInContext2`)
 - rust-lang/rust#147263 (Disable triagebot auto stable-regression compiler backport nominations pending redesign)
 - rust-lang/rust#147268 (add arm-maintainers to various targets)
 - rust-lang/rust#147270 (Move doc_cfg-specific code into `cfg.rs`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-03 00:49:22 +00:00
dianqk
c2a03cefd8 debuginfo: Use LocalRef to simplify reference debuginfos
If the `LocalRef` is `LocalRef::Place`, we can refer to it directly,
because the local of place is an indirect pointer.
Such a statement is `_1 = &(_2.1)`.
If the `LocalRef` is `LocalRef::Operand`,
the `OperandRef` should provide the pointer of the reference.
Such a statement is `_1 = &((*_2).1)`.

But there is a special case that hasn't been handled, scalar pairs like `(&[i32; 16], i32)`.
2025-10-03 08:08:22 +08:00
Stuart Cook
7a011558aa Rollup merge of #147259 - Zalathar:node-in-context, r=nnethercote
cg_llvm: Use helper methods for all calls to `LLVMMDNodeInContext2`

Originally I was only planning on extracting an `md_node_in_context` method, but then I noticed that all callers of `LLVMMDNodeInContext2` could be covered by a small number of additional helper methods.

There should be no change in compiler output.
2025-10-03 09:16:27 +10:00
Deadbeef
a5c9030271 Extract common logic for iterating over features
Two places doing the same thing is enough to motivate me to extract this to a method :)
2025-10-02 21:43:14 +00:00
bors
8d603ef287 Auto merge of #147231 - CrooseGit:dev/reucru01/extend_rustc_force_inline, r=saethlin
Extending `#[rustc_force_inline]` to be applicable to inherent methods

`#[rustc_force_inline]` is an internal-only attribute similar to `#[inline(always)]` but which emits an error if inlining cannot occur. rustc_force_inline uses the MIR inliner to do this and has limitations on where it can be applied to ensure that an error is always emitted if inlining can't happen (e.g. it can't be applied to trait methods because calls to those can't always be resolved).

`#[rustc_force_inline]` is motivated by AArch64 pointer authentication intrinsics where it is vital for the security properties of these intrinsics that they do not exist in standalone functions that could be used as gadgets in an exploit (if they could, then you could sign whatever pointers you want, for example, which is bad, but if you force inlining, then you can't jump to a reusable function containing only these instructions).

Since its initial implementation, `#[rustc_force_inline]` could only be applied to free functions. This can be relaxed to also allow inherent methods while still preserving the desired properties. In a work-in-progress patch for manual pointer authentication intrinsics, it is useful to introduce types with inherent methods that would need to be force inlined.

r? `@saethlin`
2025-10-02 21:43:10 +00:00
Karol Zwolak
d1d7b9472a bring back plural 'alternatives' in suggestion message 2025-10-02 20:24:34 +02:00
Martin Nordholts
fe66eaa67a Fix backtraces with -C panic=abort on linux; emit unwind tables by default
The linux backtrace unwinder relies on unwind tables to work properly,
and generating and printing a backtrace is done by for example the
default panic hook.

Begin emitting unwind tables by default again with `-C panic=abort` (see
history below) so that backtraces work.

History
=======

Backtraces with `-C panic=abort` used to work in Rust 1.22 but broke in
Rust 1.23, because in 1.23 we stopped emitting unwind tables with `-C
panic=abort` (see 24cc38e3b0).

In 1.45 (see cda994633e) a workaround in the form
of `-C force-unwind-tables=yes` was added.

`-C panic=abort` was added in [Rust
1.10](https://blog.rust-lang.org/2016/07/07/Rust-1.10/#what-s-in-1-10-stable)
and the motivation was binary size and compile time. But given how
confusing that behavior has turned out to be, it is better to make
binary size optimization opt-in with `-C force-unwind-tables=no` rather
than default since the current default breaks backtraces.

Besides, if binary size is a primary concern, there are many other
tricks that can be used that has a higher impact.
2025-10-02 19:46:41 +02:00
bors
94ecb52bbe Auto merge of #147261 - matthiaskrgr:rollup-yh3fgvc, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#146281 (Support `#[rustc_align_static]` inside `thread_local!`)
 - rust-lang/rust#146535 (mbe: Implement `unsafe` attribute rules)
 - rust-lang/rust#146585 (indexing: reword help)
 - rust-lang/rust#147004 (Tweak handling of "struct like start" where a struct isn't supported)
 - rust-lang/rust#147221 (Forbid `//@ compile-flags: -Cincremental=` in tests)
 - rust-lang/rust#147225 (Don't enable shared memory by default with Wasm atomics)
 - rust-lang/rust#147227 (implement `Box::take`)
 - rust-lang/rust#147233 (Initialize llvm submodule if not already the case to run citool)
 - rust-lang/rust#147236 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-02 11:14:37 +00:00
Reuben Cruise
5bf5e71160 Extends rustc_force_inline to inherent methods
- Changes parser to allow application to inherent methods.
- Adds tests to confirm extended functionality works just as the existing.
2025-10-02 11:30:11 +01:00
Matthias Krüger
8a18176c92 Rollup merge of #147225 - daxpedda:wasm-u-u-atomics-threads, r=alexcrichton
Don't enable shared memory by default with Wasm atomics

This prepares us for a future where LLVM eventually stabilizes the atomics target feature, in which case we don't want to inflate atomics with threads. Otherwise users would be stuck with shared memory even when they don't want it/need it.

### Context

Currently the atomics target features is unstable and can't be used without re-building Std with it (`-Zbuild-std`).
Enabling the atomics target feature automatically enables shared memory.
Shared memory is required to actually allow multi-threading.
However, shared memory comes with a performance overhead when atomic instructions aren't able to be lowered to regular memory access instructions or when interacting with certain Web APIs.
So it is very undesirable to enable shared memory by default for the majority of users.

While it is possible to use atomics without shared memory, the question remains what use-case this scenario has.
The only one I can think of would involve multiple memories, where the main memory remains un-shared but a second shared memory exists. While Rust doesn't support multiple memories, it might be possible with inline assembly (rust-lang/rust#136382).

So alternatively, we might consider *not* enabling atomics by default even when LLVM does. In which case everything would remain the same.

---

This will break current Web multi-threading users. To address this they can add the following `RUSTFLAGS`:
```
-Clink-args=--shared-memory,--max-memory=1073741824,--import-memory,--export=__wasm_init_tls,--export=__tls_size,--export=__tls_align,--export=__tls_base
```

We could add a new experimental flag that enables the right linker arguments for users, but I feel that's not in Rusts scope. Or like suggested before: a Rust-only `threads` target feature.

Addresses rust-lang/rust#77839.
r? ``@alexcrichton``
2025-10-02 10:27:52 +02:00
Matthias Krüger
e041b2c078 Rollup merge of #147004 - estebank:ascription-in-pat, r=fee1-dead
Tweak handling of "struct like start" where a struct isn't supported

This improves the case where someone tries to write a `match` expr where the patterns have type ascription syntax. Makes them less verbose, by giving up on the first encounter in the block, and makes them more accurate by only treating them as a struct literal if successfully parsed as such.

Before, encountering something like `match a { b:` would confuse the parser and think everything after `match` *must* be a struct, and if it wasn't it would generate a cascade of unnecessary diagnostics.
2025-10-02 10:27:50 +02:00
Matthias Krüger
7320d3ed61 Rollup merge of #146585 - hkBst:indexing-1, r=jdonszelmann
indexing: reword help

After looking at https://github.com/rust-lang/rust/issues/40850, I thought I'd try to improve wording around error E0608 a bit. Hopefully I've succeeded.
2025-10-02 10:27:49 +02:00
Matthias Krüger
ac7beab527 Rollup merge of #146535 - joshtriplett:mbe-unsafe-attr, r=petrochenkov
mbe: Implement `unsafe` attribute rules

This implements `unsafe attr` rules for declarative `macro_rules!` attributes, as specified in [RFC 3697](https://github.com/rust-lang/rfcs/pull/3697).

An invocation of an attribute that uses an `unsafe attr` rule requires the `unsafe(attr(...))` syntax.

An invocation of an attribute that uses an ordinary `attr` rule must *not* use the `unsafe(attr(...))` syntax.

`unsafe` is only supported on an `attr` rule, not any other kind of `macro_rules!` rule.

Tracking issue for `macro_rules!` attributes: https://github.com/rust-lang/rust/issues/143547
2025-10-02 10:27:49 +02:00