311444 Commits

Author SHA1 Message Date
bors
e0e204f3e9 Auto merge of #149096 - chenyukang:yukang-fix-unused-vars-148373, r=oli-obk
Skip unused variables warning for unreachable code

Fixes rust-lang/rust#148373

These warnings are not reported on stable branch, but are now reported on the beta.

I tried another solution to record whether a `local` is reachable in `find_dead_assignments`, but the code in this PR seems simpler.

r? `@cjgillot`
2025-11-23 04:14:38 +00:00
bors
94b49fd998 Auto merge of #149222 - matthiaskrgr:rollup-cl428i7, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#148407 (Warn against calls which mutate an interior mutable `const`-item)
 - rust-lang/rust#149065 (Address annotate-snippets test differences)
 - rust-lang/rust#149072 (Fix the issue of unused assignment from MIR liveness checking)
 - rust-lang/rust#149077 (feat: Enable annotate-snippets' simd feature)
 - rust-lang/rust#149168 (Fix ICE when collecting opaques from trait method declarations)
 - rust-lang/rust#149180 (Couple of refactors to SharedEmitter)
 - rust-lang/rust#149185 (Handle cycles when checking impl candidates for `doc(hidden)`)
 - rust-lang/rust#149194 (Move safe computation out of unsafe block)
 - rust-lang/rust#149204 (Fix typo in HashMap performance comment)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-22 19:51:05 +00:00
Matthias Krüger
be4c672cbc
Rollup merge of #149204 - winningMove:patch-1, r=chenyukang
Fix typo in HashMap performance comment
2025-11-22 18:41:25 +01:00
Matthias Krüger
115aa626bd
Rollup merge of #149194 - chirizxc:patch-1, r=Noratrieb
Move safe computation out of unsafe block
2025-11-22 18:41:24 +01:00
Matthias Krüger
cb50c01887
Rollup merge of #149185 - Jules-Bertholet:fix-149092, r=chenyukang
Handle cycles when checking impl candidates for `doc(hidden)`

Fixes https://github.com/rust-lang/rust/issues/149092
2025-11-22 18:41:23 +01:00
Matthias Krüger
3b432a2a1e
Rollup merge of #149180 - bjorn3:lto_refactors9, r=dianqk
Couple of refactors to SharedEmitter

I was trying to get rid of a dedicated `inline_asm_error` method in favor the regular error methods on `DiagCtxt` to allow replacing `SharedEmitter` with `sess.dcx()` when running on the main thread, but the `sess.source_map().new_source_file()` for the inline asm snippets prevents doing this. I'm going to solve the original motivating problem in a different way for this reason, but I figured these refactors do improve things a tiny bit.
2025-11-22 18:41:23 +01:00
Matthias Krüger
e33b17837e
Rollup merge of #149168 - lapla-cogito:ice_148622, r=tiif
Fix ICE when collecting opaques from trait method declarations

fixes rust-lang/rust#148622

When using an `opaque` type as a `const` generic parameter, the compiler would attempt to collect TAIT from trait method declarations, causing an ICE by panicking in `hir_body_owned_by`.
2025-11-22 18:41:22 +01:00
Matthias Krüger
d48305fa5b
Rollup merge of #149077 - Muscraft:annotate-snippets-simd, r=davidtwco
feat: Enable annotate-snippets' simd feature

`annotate-snippets` `simd` feature enables the use of `memchr` when searching for `char`/`str`. This should hopefully improve performance when [`annotate-snippets` is passed large `source`](https://github.com/rust-lang/rust/pull/148188#issuecomment-3550280300).
2025-11-22 18:41:22 +01:00
Matthias Krüger
cef578b3a9
Rollup merge of #149072 - chenyukang:yukang-fix-unused-148960, r=davidtwco
Fix the issue of unused assignment from MIR liveness checking

Fixes rust-lang/rust#148960
Fixes rust-lang/rust#148418

r? ``@davidtwco``

cc ``@cjgillot``

My first try on MIR related code, so it may not be the best fix.
2025-11-22 18:41:21 +01:00
Matthias Krüger
0279cba1f6
Rollup merge of #149065 - Muscraft:annotate-snippets-regressions, r=davidtwco
Address annotate-snippets test differences

When `annotate-snippets` became the default renderer on `nightly`, it came with a few rendering differences. I was not entirely happy with a few of the differences, and after talking with ``@davidtwco`` about them, I decided to address those that seemed like regressions.

r? ``@davidtwco``
2025-11-22 18:41:20 +01:00
Matthias Krüger
a2138ef8e6
Rollup merge of #148407 - Urgau:suspicious_int_mutable_consts, r=JonathanBrouwer
Warn against calls which mutate an interior mutable `const`-item

## `const_item_interior_mutations`

~~`interior_mutable_const_item_mutations`~~

~~`suspicious_mutation_of_interior_mutable_consts`~~

*warn-by-default*

The `const_item_interior_mutations` lint checks for calls which mutates an interior mutable const-item.

### Example

```rust
use std::sync::Once;

const INIT: Once = Once::new(); // using `INIT` will always create a temporary and
                                // never modify it-self on use, should be a `static`
                                // instead for shared use

fn init() {
    INIT.call_once(|| {
        println!("Once::call_once first call");
    });
}
```

```text
warning: mutation of an interior mutable `const` item with call to `call_once`
  --> a.rs:11:5
   |
11 |       INIT.call_once(|| {
   |       ^---
   |       |
   |  _____`INIT` is a interior mutable `const` item of type `std::sync::Once`
   | |
12 | |         println!("Once::call_once first call");
13 | |     });
   | |______^
   |
   = note: each usage of a `const` item creates a new temporary
   = note: only the temporaries and never the original `const INIT` will be modified
   = help: for more details on interior mutability see <https://doc.rust-lang.org/reference/interior-mutability.html>
   = note: `#[warn(const_item_interior_mutations)]` on by default
help: for a shared instance of `INIT`, consider making it a `static` item instead
   |
 6 - const INIT: Once = Once::new(); // using `INIT` will always create a temporary and
 6 + static INIT: Once = Once::new(); // using `INIT` will always create a temporary and
   |
```

### Explanation

Calling a method which mutates an interior mutable type has no effect as const-item are essentially inlined wherever they are used, meaning that they are copied directly into the relevant context when used rendering modification through interior mutability ineffective across usage of that const-item.

The current implementation of this lint only warns on significant `std` and `core` interior mutable types, like `Once`, `AtomicI32`, ... this is done out of prudence and may be extended in the future.

----

This PR is an targeted alternative to rust-lang/rust#132146. It avoids false-positives by adding an internal-only attribute `#[rustc_should_not_be_called_on_const_items]` on methods and functions that mutates an interior mutale type through a shared reference (mutable refrences are already linted by the `const_item_mutation` lint).

It should also be noted that this is NOT an uplift of the more general [`clippy::borrow_interior_mutable_const`](https://rust-lang.github.io/rust-clippy/master/index.html#/borrow_interior_mutable_const) lint, which is a much more general lint regarding borrow of interior mutable types, but has false-positives that are completly avoided by this lint.

A simple [GitHub Search](https://github.com/search?q=lang%3Arust+%2F%28%3F-i%29const+%5Ba-zA-Z0-9_%5D*%3A+Once%2F&type=code) reveals many instance where the user probably wanted to use a `static`-item instead.

----

````@rustbot```` labels +I-lang-nominated +T-lang
cc ````@traviscross````
r? compiler

Fixes [IRLO - Forbidding creation of constant mutexes, etc](https://internals.rust-lang.org/t/forbidding-creation-of-constant-mutexes-etc/19005)
Fixes https://github.com/rust-lang/rust/issues/132028
Fixes https://github.com/rust-lang/rust/issues/40543
2025-11-22 18:41:20 +01:00
bors
4b1b6dde0c Auto merge of #147536 - mati865:gnullvm-self-contained, r=petrochenkov
Add `rust-mingw` component for `*-windows-gnullvm` hosts

Cc https://github.com/rust-lang/rust/issues/146634
2025-11-22 16:34:09 +00:00
Urgau
c48dce1187 Allow const_item_interior_mutations in tests 2025-11-22 14:48:40 +01:00
Urgau
ddabb1c139 Allow const_item_interior_mutations in Clippy tests 2025-11-22 14:48:40 +01:00
Urgau
dc2a61eccd Add const_item_interior_mutations lint 2025-11-22 14:48:40 +01:00
Urgau
0e8d1e1f8e Add #[rustc_should_not_be_called_on_const_items] to std methods 2025-11-22 14:48:35 +01:00
Urgau
e2a69cea60 Add #[rustc_should_not_be_called_on_const_items] attribute 2025-11-22 14:27:28 +01:00
bors
1dd43f247e Auto merge of #149159 - cuviper:library-hashbrown-0.16.1, r=Amanieu
library: upgrade to hashbrown v0.16.1

This is another step toward unspecializing `Copy`.

See also rust-lang/rust#135634 and rust-lang/hashbrown#662

r? `@Amanieu`
cc `@joboet`
2025-11-22 09:40:59 +00:00
winningMove
8094934b9a
Fix typo in HashMap performance comment 2025-11-22 10:37:31 +01:00
bors
af17d59d71 Auto merge of #149044 - clubby789:implicit-return-span, r=cjgillot
Reduce confusing `unreachable_code` lints

Closes rust-lang/rust#149042

Attempts to be smarter about identifying 'real'/user-written unreachable code to raise the lint
2025-11-22 06:28:24 +00:00
bors
ea98522531 Auto merge of #149199 - weihanglo:update-cargo, r=weihanglo
Update cargo submodule

7 commits in 5c0343317ce45d2ec17ecf41eaa473a02d73e29c..9fa462fe3a81e07e0bfdcc75c29d312c55113ebb
2025-11-18 19:05:44 +0000 to 2025-11-21 20:49:51 +0000
- Enable CARGO_CFG_DEBUG_ASSERTIONS in build scripts based on profile (rust-lang/cargo#16160)
- fix(config-include): disallow glob and template syntax (rust-lang/cargo#16285)
- test(config-include): include always relative to including config (rust-lang/cargo#16286)
- docs(guide): When suggesting alt dev profile, link to related issue (rust-lang/cargo#16275)
- refactor(timings): separate data collection and presentation (rust-lang/cargo#16282)
- test(build-std): Add test for LTO (rust-lang/cargo#16277)
- fix(bindeps): do not propagate artifact dependency to proc macro or build deps (rust-lang/cargo#15788)

r? ghost
2025-11-22 03:17:22 +00:00
bors
5934b06557 Auto merge of #148831 - clubby789:cargo-update-11-11-25, r=jieyouxu
Bump compiler dependencies

https://github.com/rust-lang/rust/pull/145849#issuecomment-3394832713
This manually downgrades the `wasip`/`wit-bindgen`/`getrandom` deps to avoid pulling in a binary blob, but it would be good to pin this automatically in a way which doesn't cause these blobs to be pulled in.
2025-11-22 00:00:06 +00:00
Weihang Lo
e9440fb24e
Update cargo submodule 2025-11-21 17:40:55 -05:00
bors
27b076af7e Auto merge of #149196 - GuillaumeGomez:rollup-pn0aoy3, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#146978 (Emit error when using path-segment keyword as cfg pred)
 - rust-lang/rust#148719 (Allow unnormalized types in drop elaboration)
 - rust-lang/rust#148795 (add `rust.rustflags` and per target `rustflags` options to `bootstrap.toml`)
 - rust-lang/rust#149028 ([rustdoc] Remove `UrlFragment::render` method to unify `clean::types::links` and `anchor`)
 - rust-lang/rust#149043 ( rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution)
 - rust-lang/rust#149098 (Fix error message for calling a non-tuple struct)
 - rust-lang/rust#149151 (Add test for importing path-segment keyword)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-21 20:45:11 +00:00
Guillaume Gomez
228b49e791
Rollup merge of #149151 - mu001999-contrib:test/use-path-kw, r=petrochenkov
Add test for importing path-segment keyword

Adding new test to make a snapshot of current compiler's behavior. See https://github.com/rust-lang/rust/pull/146972#issuecomment-3532148571

r? `@petrochenkov`
2025-11-21 21:34:29 +01:00
Guillaume Gomez
b2f5cc7827
Rollup merge of #149098 - Jamesbarford:fix/148919-tuple-struct-lint, r=JonathanBrouwer
Fix error message for calling a non-tuple struct

This feels a bit odd checking for `"0"` but I can't see how else to check for it being a Tuple

closes https://github.com/rust-lang/rust/issues/148919
2025-11-21 21:34:28 +01:00
Guillaume Gomez
629a283b98
Rollup merge of #149043 - aDotInTheVoid:is-this-real-is-this-out-of-spite-does-it-matter, r=GuillaumeGomez
rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution

Historically, it's not been possible to robustly resolve a cross-crate item in rustdoc-json. If you had a `Id` that wasn't in `Crate::index` (because it was defined in a different crate), you could only look it up it `Crate::paths`. But there, you don't get the full information, only an `ItemSummary`. This tells you the `path` and the `crate_id`.

But knowing the `crate_id` isn't enough to be able to build/find the rustdoc-json output with this item. It's only use is to get a `ExternalCrate` (via `Crate::external_crates`). But that only tells you the `name` (as a string). This isn't enough to uniquely identify a crate, as there could be multiple versions/features [^1] [^2].

This was originally proposed to be solved via `@LukeMathWalker's` `--orchestrator-id` proposal (https://github.com/rust-lang/compiler-team/issues/635). But that requires invasive changes to cargo/rustc. This PR instead implements `@Urgau's` proposal to re-use the path to a crate's rmeta/rlib as a unique identifer. Callers can use that to determine which package it corresponds to in the language of the build-system above rustc. E.g. for cargo, `cargo rustdoc --message-format=json --output-format=json -Zunstable-options`).

(Once you've found the right external crate's rustdoc-json output, you still need to resolve the path->id in that crate. But that's """just""" a matter of walking the module tree. We should probably still make that nicer (by, for example, allowing sharing `Id`s between rustdoc-json document), but that's a future concern)

For some notes from RustWeek 2025, where this was designed, see https://hackmd.io/0jkdguobTnW7nXoGKAxfEQ

CC `@obi1kenobi` (who wants this for cargo-semver-checks [^3]), `@epage` (who's conversations on what and wasn't possible with cargo informed taking this approach to solve this problem)

r? `@GuillaumeGomez`

## TODO:

- [x] Docs: [Done](e4cdd0c24a..457ed4edb1)
- [x] Tests: [Done](2e1b954dc5..4d00c1a7ee)

[^1]: https://github.com/rust-lang/compiler-team/issues/635#issue-1714254865 § Problem
[^2]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Identifying.20external.20crates.20in.20Rustdoc.20JSON/with/352701211
[^3]: https://github.com/obi1kenobi/cargo-semver-checks/issues/638
2025-11-21 21:34:26 +01:00
Guillaume Gomez
110471b229
Rollup merge of #149028 - GuillaumeGomez:unify-anchor, r=lolbinarycat
[rustdoc] Remove `UrlFragment::render` method to unify `clean::types::links` and `anchor`

Fixes https://github.com/rust-lang/rust/issues/148648.
First part of https://github.com/rust-lang/rust/issues/148547.

The last part will be about handle `AssocItemLink` differently (either remove it or change how we do it).

r? `@lolbinarycat`
2025-11-21 21:34:25 +01:00
Guillaume Gomez
8d66eb5001
Rollup merge of #148795 - karolzwolak:rustflags-bootstrap-toml, r=Kobzol
add `rust.rustflags` and per target `rustflags` options to `bootstrap.toml`

Part of rust-lang/rust#148782; see also rust-lang/rust#148708

Add new options `rust.rustflags` for all targets and `rustflags` par target that will pass specified flags to rustc for all stages. Target specific flags override (are passed after) global `rust.rustflags` ones.

This makes easy to persistently pass any flag to the compiler when building rustc. For example you can use a different linker by putting the following in `bootstrap.toml`:
```toml
[rust]
rustflags = ["-Clinker=clang", "-Clink-arg=--ld-path=wild"]
```
r? bootstrap
2025-11-21 21:34:24 +01:00
Guillaume Gomez
60ed1ab0ec
Rollup merge of #148719 - Nadrieril:poly-drop-glue, r=saethlin
Allow unnormalized types in drop elaboration

I work on a [rustc driver](https://github.com/AeneasVerif/charon) that aims to extract the full polymorphic MIR of a crate. Currently the one thing I can't get is drop glue because it fails on unnormalizable types like the fields of `Cow` or `NonZero`.

This PR removes the one check for unnormalized types in drop elaboration. It's a `span_delay_bug` so only there to help catch mistakes. I think that's fine to remove? If something downstream relies on types being normalized the right approach is for MIR validation to check for normalized types, not that one random check.
2025-11-21 21:34:23 +01:00
Guillaume Gomez
33d11ef7b1
Rollup merge of #146978 - mu001999-contrib:fix/path-kw-as-cfg-pred, r=petrochenkov
Emit error when using path-segment keyword as cfg pred

Fixes rust-lang/rust#146968

Emit error `CfgPredicateIdentifier` if the word is path-segment keyword.

Detailed change description - https://github.com/rust-lang/rust/pull/146978#issuecomment-3437353950.

r? petrochenkov
2025-11-21 21:34:22 +01:00
chiri
3386da8f6f
Move safe computation out of unsafe block 2025-11-21 22:52:19 +03:00
Guillaume Gomez
8f76773041 Return impl Display instead of String in fragment 2025-11-21 19:49:19 +01:00
Jules Bertholet
f580357863
Handle cycles when checking impl candidates for doc(hidden)
Fixes https://github.com/rust-lang/rust/issues/149092
2025-11-21 11:43:53 -05:00
Jamie Hill-Daniel
36bdffea59 Bump compiler dependencies 2025-11-21 16:11:00 +00:00
Jamie Hill-Daniel
98141e0beb Reduce confusing unreachable_code lints 2025-11-21 16:07:54 +00:00
Karol Zwolak
6e63c39467 feat: add rust.rustflags and per target rustflags options to bootstrap.toml
This makes easy to persistently pass any flag to the compiler when
building rustc.
For example you can use a different linker by putting the following in
`bootstrap.toml`:
```toml
[rust]
rustflags = ["-Clinker=clang", "-Clink-arg=--ld-path=wild"]
```
2025-11-21 16:25:36 +01:00
Mateusz Mikuła
3ad82500ba Add rust-mingw component for *-windows-gnullvm
hosts
2025-11-21 15:59:44 +01:00
bjorn3
2a280130db Allow passing primary spans to SharedEmitter 2025-11-21 14:37:10 +00:00
bjorn3
bba5f7f72b Remove unused pop_span_label method 2025-11-21 14:16:12 +00:00
bjorn3
7f7b3488c0 Introduce InlineAsmError type 2025-11-21 14:16:12 +00:00
lapla-cogito
d340ea520b
Fix ICE when collecting opaques from trait method declarations 2025-11-21 21:42:40 +09:00
mu001999
640990f64c Add test for importing path-segment keyword 2025-11-21 19:38:15 +08:00
mu001999
fc822f8c85 Emit error when using path-segment keyword as cfg pred 2025-11-21 18:48:04 +08:00
Alona Enraght-Moony
361af821ab rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution
Historically, it's not been possible to robustly resolve a cross-crate
item in rustdoc-json. If you had a `Id` that wasn't in `Crate::index`
(because it was defined in a different crate), you could only look it up
it `Crate::paths`. But there, you don't get the full information, only
an `ItemSummary`. This tells you the `path` and the `crate_id`.

But knowing the `crate_id` isn't enough to be able to build/find the
rustdoc-json output with this item. It's only use is to get a
`ExternalCrate` (via `Crate::external_crates`). But that only tells you
the `name` (as a string). This isn't enough to uniquely identify a
crate, as there could be multiple versions/features [1] [2].

This was originally proposed to be solved via LukeMathWalker's
`--orchestrator-id` proposal
(https://www.github.com/rust-lang/compiler-team/issues/635). But that
requires invasive changes to cargo/rustc. This PR instead implements
Urgau's proposal to re-use the path to a crate's rmeta/rlib as a unique
identifer. Callers can use that to determine which package it
corresponds to in the language of the build-system above rustc. E.g. for
cargo, `cargo rustdoc --message-format=json --output-format=json
-Zunstable-options`).

(Once you've found the right external crate's rustdoc-json output, you
still need to resolve the path->id in that crate. But that's """just"""
a matter of walking the module tree. We should probably still make that
nicer (by, for example, allowing sharing `Id`s between rustdoc-json
document), but that's a future concern)

For some notes from RustWeek 2025, where this was designed, see
https://hackmd.io/0jkdguobTnW7nXoGKAxfEQ

[1]: https://www.github.com/rust-lang/compiler-team/issues/635#issue-1714254865 § Problem
[2]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Identifying.20external.20crates.20in.20Rustdoc.20JSON/with/352701211
2025-11-21 09:22:59 +00:00
bors
e22dab387f Auto merge of #149166 - Zalathar:rollup-fyrwtcb, r=Zalathar
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#148990 (Exhaustively specify names and stability of `--print` values)
 - rust-lang/rust#149127 (unwrap ret ty of `iter::ArrayChunks::into_remainder` )
 - rust-lang/rust#149134 (std: sys: net: uefi: Implement read_vectored)
 - rust-lang/rust#149135 (Constify `residual_into_try_type`)
 - rust-lang/rust#149160 (Check for intrinsic to fn ptr casts in unified coercions)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-21 03:46:25 +00:00
Stuart Cook
db505171a3
Rollup merge of #149160 - maxdexh:fix-instrinsic-unifying-coercion-ice, r=Kivooeo,BoxyUwU
Check for intrinsic to fn ptr casts in unified coercions

Fixes rust-lang/rust#149143 by ensuring that when coercing multiple expressions to a unified type, the same "intrinsic to fn ptr" check is applied as for other coercions.
2025-11-21 14:44:44 +11:00
Stuart Cook
e7b9935fc5
Rollup merge of #149135 - nxsaken:const_residual_into_try_type, r=scottmcm
Constify `residual_into_try_type`

Feature: `const_try_residual` (related to `try_trait_v2_residual`)
Tracking issue: rust-lang/rust#91285

Constify `residual_into_try_type` introduced in rust-lang/rust#148725.

r? ``@scottmcm``
2025-11-21 14:44:43 +11:00
Stuart Cook
e397c5ddc1
Rollup merge of #149134 - Ayush1325:uefi-tcp4-vector, r=joboet
std: sys: net: uefi: Implement read_vectored

- Basically a copy of write_vectored [0]
- Tested on QEMU ovmf.

[0]: https://github.com/rust-lang/rust/pull/146301
2025-11-21 14:44:43 +11:00
Stuart Cook
f8bc31a804
Rollup merge of #149127 - bend-n:iter_array_chunks_into_remainder_is_non_optional, r=dtolnay
unwrap ret ty of `iter::ArrayChunks::into_remainder`

changes [`iter::ArrayChunks::into_remainder`](https://github.com/rust-lang/rust/issues/100450) to return `array::IntoIter` instead of `Option<array::IntoIter>` as suggested by [`@WaffleLapkin](https://github.com/rust-lang/rust/issues/100450#issuecomment-3555519025)`
2025-11-21 14:44:42 +11:00