51056 Commits

Author SHA1 Message Date
Matthias Krüger
5695a88298 Rollup merge of #147805 - LorrensP-2158466:extern-mod-disamb, r=petrochenkov
use module_child index as disambiguator for external items

When defining the items of an external module, if that item is an underscore we use it's index as the disambiguator. This is needed for parallel import resolution, which is being worked on in rust-lang/rust#145108.

r? `@petrochenkov`
2025-10-18 08:08:39 +02:00
Matthias Krüger
756d3a0fb7 Rollup merge of #147764 - beepster4096:oopsies_sorry, r=saethlin
Undo CopyForDeref assertion in const qualif

Fixes rust-lang/rust#147733 caused by rust-lang/rust#145513

This code in fact does not run only on runtime MIR.
2025-10-18 08:08:38 +02:00
Matthias Krüger
8527b5471f Rollup merge of #147454 - ferrocene:hoverbear/panic-abort-uwtables-qnx, r=wesleywiser
Fix backtraces with `-C panic=abort` on qnx; emit unwind tables by default

While syncing https://github.com/rust-lang/rust/pull/143613 into Ferrocene as part of https://github.com/ferrocene/ferrocene/pull/1803, we noted a failure on our QNX targets:

```
---- [ui] tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs stdout ----

error: test did not exit with success! code=Some(134) so test would pass with `run-crash`
status: exit status: 134
command: RUSTC="/home/ci/project/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUST_TEST_THREADS="1" "/home/ci/project/build/x86_64-unknown-linux-gnu/stage1-tools-bin/remote-test-client" "run" "0" "/home/ci/project/build/x86_64-unknown-linux-gnu/test/ui/panics/panic-abort-backtrace-without-debuginfo/a"
--- stdout -------------------------------
uploaded "/home/ci/project/build/x86_64-unknown-linux-gnu/test/ui/panics/panic-abort-backtrace-without-debuginfo/a", waiting for result
died due to signal 6
------------------------------------------
--- stderr -------------------------------

thread 'main' (1) panicked at /home/ci/project/tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs:39:9:
ERROR: no `this_function_must_be_in_the_backtrace` in stderr! actual stderr:
thread 'main' (1) panicked at /home/ci/project/tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs:27:5:
generate panic backtrace
stack backtrace:
   0:       0x4e66a53643 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h55e010263b1e3169
   1:       0x4e66a68cd2 - core::fmt::write::h0d6e2e8752abc333
   2:       0x4e66a16919 - std::io::Write::write_fmt::h71c4c024d832b384
   3:       0x4e66a1f8e2 - std::sys::backtrace::BacktraceLock::print::hdd80dfdf90bb7100
   4:       0x4e66a221e0 - std::panicking::default_hook::{{closure}}::h77758f25a686500f
   5:       0x4e66a21f69 - std::panicking::default_hook::ha63f7d476af6c267
   6:       0x4e66a22999 - std::panicking::panic_with_hook::h3a36a8a0f0dd8ccd
   7:       0x4e66a21cac - std::panicking::begin_panic::{{closure}}::h570dedb92e232392
   8:       0x4e66a1fa69 - std::sys::backtrace::__rust_end_short_backtrace::h5366eec354f92733
   9:       0x4e669f9589 - std::panicking::begin_panic::h04a4bd4c33dd4056
  10:       0x4e66a00aca - panic_abort_backtrace_without_debuginfo::and_this_function_too::h5b034b94cbe9c3d3

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------------------------------------------

---- [ui] tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs stdout end ----

failures:
    [ui] tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs

test result: FAILED. 19958 passed; 1 failed; 328 ignored; 0 measured; 0 filtered out; finished in 1827.71s

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-pc-nto-qnx710
Build completed unsuccessfully in 0:43:28

Exited with code exit status 1
```

This patch applies the same fix as the one found in https://github.com/rust-lang/rust/pull/143613 of adding the `default_uwtable: true` to the target.

I've run it locally, when https://github.com/ferrocene/ferrocene/pull/1803 merges we'll know it has passed within our CI, which is about a close an analog as I can offer to Rust.
2025-10-18 08:08:37 +02:00
Matthias Krüger
a5d38ede1d Rollup merge of #145724 - folkertdev:track-caller-drop-no-mangle, r=fee1-dead
the `#[track_caller]` shim should not inherit `#[no_mangle]`

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

builds on https://github.com/rust-lang/rust/pull/143293 which introduced a mechanism to strip attributes from shims.

cc `@Jules-Bertholet` `@workingjubilee` `@bjorn3`

---

Summary:

This PR fixes an interaction between `#[track_caller]`, `#[no_mangle]`, and casting to a function pointer.

A function annotated with `#[track_caller]` internally has a hidden extra argument for the panic location. The `#[track_caller]` attribute is only allowed on `extern "Rust"` functions. When a function is annotated with both `#[no_mangle]` and `#[track_caller]`, the exported symbol has the signature that includes the extra panic location argument. This works on stable rust today:

```rust
extern "Rust" {
    #[track_caller]
    fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static>;
}

mod provides {
    use std::panic::Location;
    #[track_caller] // UB if we did not have this!
    #[no_mangle]
    fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static> {
        Location::caller()
    }
}
```

When a `#[track_caller]` function is converted to a function pointer, a shim is added to drop the additional argument. So this is a valid program:

```rust
#[track_caller]
fn foo() {}

fn main() {
    let f = foo as fn();
    f();
}
```

The issue arises when `foo` is additionally annotated with `#[no_mangle]`, the generated shim currently inherits this attribute, also exporting a symbol named `foo`, but one without the hidden panic location argument. The linker rightfully complains about a duplicate symbol.

The solution of this PR is to have the generated shim drop the `#[no_mangle]` attribute.
2025-10-18 08:08:36 +02:00
bors
32892a37b4 Auto merge of #146913 - camsteffen:refactor-lint-syntax, r=fee1-dead
mismatched_lifetime_syntax lint refactors and optimizations

I found several opportunities to return early so I'm hoping those will have a perf improvement. Otherwise, it's various refactors for simplicity.
2025-10-18 03:18:09 +00:00
reddevilmidzy
a1a9113aa8 Rename "non-inline module" to "file module" in proc macro diagnostics 2025-10-18 11:54:57 +09:00
Zalathar
98c95c966b Remove current code for embedding command-line args in PDB 2025-10-18 12:24:40 +11:00
Deadbeef
3c6ae00204 Make diagnostics clearer for binop-related errors in foreign crates
Fixes redundant language and bad grammar.
2025-10-18 01:20:25 +00:00
bors
2170b4da84 Auto merge of #144607 - camsteffen:impl-trait-header-option, r=lcnr
Limit impl_trait_header query to only trait impls

Changes `impl_trait_header` to panic on inherent impls intstead of returning None. A few downstream functions are split into option and non-option returning functions. This gets rid of a lot of unwraps where we know we have a trait impl, while there are still some cases where the Option is helpful.

Summary of changes to tcx methods:
* `impl_is_of_trait` (new)
* `impl_trait_header` -> `impl_trait_header`/`impl_opt_trait_header`
* `impl_trait_ref` -> `impl_trait_ref`/`impl_opt_trait_ref`
* `trait_id_of_impl` -> `impl_trait_id`/`impl_opt_trait_id`
2025-10-18 00:08:18 +00:00
Ralf Jung
781432e355 clarify 'no fields' 2025-10-17 23:18:14 +00:00
Noratrieb
d66647ba2c Reword unstable finterprint ICE to ask for reproduction
When the unstable finterprint error was added, Rust was on fire, and we
needed a quick way for people to sort of understand what's going on,
follow the tracking issue, and leave some information without
overwhelming the issue tracker and focusing on getting their code
working.

This is what motivated the previous message. It called this a "known
issue", provided help on how to fix it, and only secondarily asked for a
bug report.

This is no longer true. These days incremental compilation is fairly
solid and these issues are supposed to be rare, we expect *none* of them
to exist (but obviously know that's not true). As such, it's time to
reword this message.

Recently someone mentioned how they didn't bother reporting this issue
because it said that it was a "known issue", and I only got awareness of
their problem because they complained about all the rustc-ice files
hanging around their directories. This is not at all what we want, we
want reports from people, ideally with a reproduction.

To get this, I reworded the error. It now explicitly asks for a
reproduction (and explaining what that means) and no longer calls it a
"known issue". It also does not link to the tracking issue anymore,
because I don't think this tracking issue is useful. It should probably
be closed.

I still mention the workaround, but explicitly call it a "workaround".
People should report a reproduction and only *then* use the workaround.
2025-10-17 23:28:54 +02:00
Camille Gillot
0b02102dc0 Attempt to compress representation. 2025-10-17 21:20:50 +00:00
bors
28fad95989 Auto merge of #142540 - cjgillot:renumber-cfg, r=fee1-dead
Pre-compute MIR CFG caches for borrowck and other analyses

I was puzzled that https://github.com/rust-lang/rust/pull/142390 introduces additional computations of CFG traversals: borrowck computes them, right?

It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses.

This PR:
- forces the computation of all caches in `mir_promoted` query;
- modifies region renumbering to avoid dropping that cache.
2025-10-17 21:01:25 +00:00
Camille Gillot
73264f21e9 Restrict drop to empty projections. 2025-10-17 21:00:12 +00:00
Shunpoco
845ff73d39 address review 2025-10-17 18:20:21 +01:00
Shunpoco
8e59e3ba33 treat an error taint from const eval lint in late_lint and check_mod_deathness
error from const eval lint causes ICE at check_pat in late_lint, because the function expects the typeck result isn't tainted by error but it is.
To avoid the ICE, check_pat returns earlier if the typeck_result is tainted.

check_mod_deathness also has an issue from the same reason. visit_body for making live symbols expects the typeck result has no error.
So this commit adds a check in visit_nested_body to avoid the ICE.
However, if visit_nested_body just returns without doing anything, all codes with the error are marked as dead, because live_symbols is empty.
To avoid this side effect, visit_nested_body and other visit_* functions in MarkSymbolVistior should return appropriate error.
If a function returns ControlFlow::Break, live_symbols_and_ignore_derived_traits returns earlier with error,
then check_mod_deathness, the caller of the function returns earlier without pushing everything into dead_codes.
2025-10-17 18:20:21 +01:00
Camille Gillot
97f88f5603 Generalize the non-freeze and needs_drop handling. 2025-10-17 16:28:37 +00:00
LorrensP-2158466
8492b24424 use module_child index as disambiguator for external items 2025-10-17 18:04:28 +02:00
Osama Abdelkader
e67d502d4e Fix autodiff incorrectly applying fat-lto to proc-macro crates
When -Z autodiff=Enable is used, the compiler automatically enables
fat-lto for all crates. However, proc-macro crates cannot use fat-lto
without the -Zdylib-lto flag, causing compilation errors.

This commit modifies the lto() method in Session to exclude proc-macro
crates from fat-lto when autodiff is enabled, while preserving the
existing behavior for all other crate types.

The fix ensures that:
- Non-proc-macro crates still get fat-lto when autodiff is enabled
- Proc-macro crates are excluded from fat-lto when autodiff is enabled
- Existing autodiff functionality remains unchanged for regular crates

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
2025-10-17 16:52:55 +03:00
Cameron Steffen
b323f567d9 Remove Option from impl_trait_header 2025-10-17 08:36:34 -05:00
Cameron Steffen
e60e9f0826 Split impl_(opt_)trait_ref 2025-10-17 08:36:34 -05:00
Cameron Steffen
ae8ff943c1 Remove some impl_opt_trait_header usages 2025-10-17 08:36:34 -05:00
Cameron Steffen
ca5073759c Remove some impl_trait_ref usages 2025-10-17 08:36:34 -05:00
Cameron Steffen
c17b2dc283 Split trait_id_of_impl into impl(_opt)_trait_id 2025-10-17 08:36:34 -05:00
Cameron Steffen
dcf76b6811 Move some TyCtxt trait methods close together 2025-10-17 08:36:34 -05:00
Cameron Steffen
9b2c9a8c5b Refactor default_could_be_derived 2025-10-17 08:36:34 -05:00
Cameron Steffen
4d03de651d Optimize impl_trait_ref usage in sanitizer 2025-10-17 08:36:33 -05:00
Waffle Lapkin
82b0cd8bee deny never type lints by default 2025-10-17 11:46:25 +02:00
Makai
5b28752281 add Cacheable trait alias 2025-10-17 14:50:27 +08:00
bors
28c4c7d7ab Auto merge of #147508 - nnethercote:TaskDeps-improvements, r=saethlin
`TaskDeps` improvements

Some cleanups and minor perf improvements relating to `TaskDeps`.

r? `@saethlin`
2025-10-17 04:47:43 +00:00
León Orell Valerian Liehr
65814c80e8 Guard us against degenerate default traits 2025-10-16 19:53:32 +02:00
León Orell Valerian Liehr
03dfb84ee1 More robustly reject relaxing non-default trait bounds 2025-10-16 19:53:32 +02:00
León Orell Valerian Liehr
aee9d3b4c0 Don't permit ?Sized in more places just because more_maybe_bounds was enabled
The internal feature `more_maybe_bounds` doesn't influence sized elaboration in
HIR ty lowering and therefore doesn't get to dictate where `?Sized` is allowed.
2025-10-16 19:53:31 +02:00
León Orell Valerian Liehr
ce68cd3762 Reject relaxed bounds inside trait alias bounds 2025-10-16 19:53:31 +02:00
León Orell Valerian Liehr
690a8a6dfd Tweak diagnostics for relaxed bounds in invalid positions 2025-10-16 19:53:29 +02:00
Matthias Krüger
7604d12e05 Rollup merge of #147751 - nnethercote:bit_set-Word, r=Zalathar
Use `bit_set::Word` in a couple more places.

It's a synonym for `u64` and there are a couple of places where we use `u64` where we should use `Word`, which this commit fixes.

I found this when I tried changing `Word` to `u128` (which made performance worse).

r? `````@Zalathar`````
2025-10-16 19:35:27 +02:00
Matthias Krüger
d8dd468ff1 Rollup merge of #147738 - pommicket:issue-147665, r=madsmtm
Don't highlight `let` expressions as having type `bool` in let-chain error messages

Fixes rust-lang/rust#147665.
2025-10-16 19:35:25 +02:00
Matthias Krüger
5408ec3069 Rollup merge of #147576 - Mark-Simulacrum:fix-offset-zst, r=nnethercote,RalfJung
Fix ICE on offsetted ZST pointer

I'm not sure this is the *right* fix, but it's simple enough and does roughly what I'd expect. Like with the previous optimization to codegen usize rather than a zero-sized static, there's no guarantee that we continue returning a particular value from the offsetting.

A grep for `const_usize.*align` found the same code copied to rustc_codegen_gcc and cranelift but a quick skim didn't find other cases of similar 'optimization'. That said, I'm not convinced I caught everything, it's not trivial to search for this.

Closes rust-lang/rust#147516
2025-10-16 19:35:24 +02:00
Matthias Krüger
334b3af42c Rollup merge of #144438 - dawidl022:contracts/guarded-lowering, r=oli-obk
Guard HIR lowered contracts with `contract_checks`

Refactor contract HIR lowering to ensure no contract code is executed when contract-checks are disabled.

The call to `contract_checks` is moved to inside the lowered fn body, and contract closures are built conditionally, ensuring no side-effects present in contracts occur when those are disabled. This partially addresses rust-lang/rust#139548, i.e. the bad behavior no longer happens with contract checks disabled (`-Zcontract-checks=no`).

The change is made in preparation for adding contract variable declarations - variables declared before the `requires` assertion, and accessible from both `requires` and `ensures`, but not in the function body (PR rust-lang/rust#144444). As those declarations may also have side-effects, it's good to guard them with `contract_checks` - the new lowering approach allows for this to be done easily.

Contracts tracking issue: rust-lang/rust#128044

**Known limiatations**:

- It is still possible to early return from the *function* from within a contract, e.g.

  ```rust
  #[ensures({if x > 0 { return 0 }; |_| true})]
  fn foo(x: u32) -> i32 {
      42
  }
  ```

  When `foo` is called with an argument greater than 0, instead of `42`, `0` will be returned.

  As this is not a regression, it is not addressed in this PR. However, it may be worth revisiting later down the line, as users may expect a form of early return from *contract specifications*, and so returning from the entire *function* could cause confusion.

- ~Contracts are still not optimised out when disabled. Currently, even when contracts are disabled, the code generated causes existing optimisations to fail, meaning even disabled contracts could impact runtime performance. This issue is blocking rust-lang/rust#136578, and has not been addressed in this PR, i.e. the `mir-opt` and `codegen` tests that fail in rust-lang/rust#136578 still fail with these new HIR lowering changes.~ Contracts should now be optimised out when disabled, however some regressions tests still need to be added to be sure that is indeed the case.
2025-10-16 19:35:22 +02:00
dianqk
afff0502a6 GVN: Preserve derefs at terminators that cannot write to memory 2025-10-16 23:03:05 +08:00
bjorn3
a077dbd686 Better timers for LTO 2025-10-16 15:01:34 +00:00
bjorn3
53867f23b2 Separate thin LTO message and work item types 2025-10-16 15:01:34 +00:00
bjorn3
3cf3ec667a Move thin LTO out of the main loop too 2025-10-16 15:01:34 +00:00
bjorn3
a6725ab7b3 Move fat LTO out of the main coordinator loop 2025-10-16 15:01:33 +00:00
bjorn3
b1d5922285 Move desc out of WorkItem::short_description to allow reusing in a future commit 2025-10-16 15:01:33 +00:00
bors
779e19d8ba Auto merge of #147644 - cjgillot:bitsetvec, r=jackh726
Use regular Vec in BitSet.

That code is hot enough for the branch in all accesses to `SmallVec` to appear in profiles.
2025-10-16 14:06:35 +00:00
dianqk
a673575b24 mir-opt: Simplify trivial constants in SimplifyConstCondition 2025-10-16 21:30:06 +08:00
Weihang Lo
e7130d3085 feat(rustdoc): --emit=depinfo output to stdout via -
rustdoc's `--emit=depinfo` flag now supports using `-`
to write the output to stdout.
2025-10-16 07:47:02 -04:00
yukang
4a886add5c Fix ICE in pattern matching with generic const array length errors 2025-10-16 19:15:32 +08:00
bors
f5242367f4 Auto merge of #146221 - camsteffen:ast-boxes, r=cjgillot
Remove boxes from ast list elements

Less indirection should be better perf.
2025-10-16 02:31:44 +00:00