Commit Graph

23828 Commits

Author SHA1 Message Date
Stuart Cook 867a480232 Rollup merge of #152963 - JonathanBrouwer:revert-str-as-str, r=jhpratt
Revert "Stabilize `str_as_str`"

Reverts https://github.com/rust-lang/rust/pull/151603, clean revert.
Fixes https://github.com/rust-lang/rust/issues/152961
2026-02-23 13:32:00 +11:00
Stuart Cook 565d1bb950 Rollup merge of #151744 - enthropy7:fix-refining-impl-trait-rtn, r=davidtwco
fix refining_impl_trait suggestion with return_type_notation

using `#![feature(return_type_notation)] `on top of `refining_impl_trait` made the lint suggest a pretty wild “wrap the body in `<Self as Trait>::f(..)”` fix instead of the simple “just copy the return type from the trait”. this patch makes the lint always suggest the plain return-type replacement based on the trait signature (by grabbing the original snippet when possible), so you don’t get RTN-style desugarings in the help

new test here

fixes rust-lang/rust#151663
2026-02-23 13:31:59 +11:00
Stuart Cook 6bcb461903 Rollup merge of #149783 - folkertdev:stabilize-cfg-select, r=JonathanBrouwer
stabilize `cfg_select!`

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/149783)*

tracking issue: https://github.com/rust-lang/rust/issues/115585
closes https://github.com/rust-lang/rust/issues/115585
reference PR:

- https://github.com/rust-lang/reference/pull/2103

# Request for Stabilization

## Summary

The `cfg_select!` macro picks the expansion corresponding to the first `cfg` condition that evaluates to `true`. It simplifies complex conditional expressions.

```rust
cfg_select! {
    unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}

let is_unix_str = cfg_select! {
    unix => "unix",
    _ => "not unix",
};
println!("{is_unix_str}");
```
## Semantics

The expansion of a `cfg_select!` call is the right-hand side of the first `cfg` rule that evaluates to true.

This can be roughly expressed using this macro:
```rust
macro_rules! cfg_select {
    ({ $($tt:tt)* }) => {{
        $crate::cfg_select! { $($tt)* }
    }};
    (_ => { $($output:tt)* }) => {
        $($output)*
    };
    (
        $cfg:meta => $output:tt
        $($( $rest:tt )+)?
    ) => {
        #[cfg($cfg)]
        $crate::cfg_select! { _ => $output }
        $(
            #[cfg(not($cfg))]
            $crate::cfg_select! { $($rest)+ }
        )?
    }
}
```

The actual implementation uses a builtin macro so that `cfg_select!` can be used both in item and expression position.

## Documentation

reference PR:

- https://github.com/rust-lang/reference/pull/2103

## Tests

The `cfg_select!` macro is already used extensively in the rust compiler codebase. It has several dedicated tests:

- [`tests/ui/check-cfg/cfg-select.rs`](https://github.com/rust-lang/rust/blob/main/tests/ui/check-cfg/cfg-select.rs)tests that warnings are emitted when an unexpected `cfg` condition is used.
- [`tests/ui/macros/cfg_select.rs`](https://github.com/rust-lang/rust/blob/main/tests/ui/macros/cfg_select.rs) tests that `cfg_select!` has the expected expansion, and tests that the expected syntax is accepted.
## History

- rust-lang/rust#115416
- rust-lang/rust#117162
- rust-lang/rust#133720
- rust-lang/rust#135625
- rust-lang/rust#137198
- rust-lang/rust#138993
- rust-lang/rust#138996
- rust-lang/rust#143461
- rust-lang/rust#143941
- rust-lang/rust#145233
- rust-lang/rust#148712
- rust-lang/rust#149380
- https://github.com/rust-lang/rust/pull/149925

# Resolved questions

# Unresolved questions

The style team has decided on how to format `cfg_select!`, but this formatting has not yet been implemented. See https://github.com/rust-lang/rust/pull/144323.

r? @traviscross

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_CONCERN-ISSUE_START -->

> [!NOTE]
> # Concerns (0 active)
>
> - ~~[allowing-comma-after-closing-brace](https://github.com/rust-lang/rust/pull/149783#issuecomment-3808533494)~~ resolved in [this comment](https://github.com/rust-lang/rust/pull/149783#issuecomment-3882251672)
>
> *Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*

<!-- TRIAGEBOT_CONCERN-ISSUE_END -->
<!-- TRIAGEBOT_END -->
2026-02-23 13:31:59 +11:00
Stuart Cook 62bc8727c3 Rollup merge of #152970 - RalfJung:unpin-noalias-tests, r=Mark-Simulacrum
extend unpin noalias tests to cover mutable references

https://github.com/rust-lang/rust/pull/152946 made a change to the logic for this attribute that the test should have flagged as problematic -- but the test only checked `Box`, not `&mut`, and those have independent code paths. So extend the test to also cover `&mut`.

@b-naber would be nice if you could confirm that the added tests do fail with your PR.
2026-02-23 13:31:58 +11:00
Jonathan Brouwer 6aa7b3102b Rollup merge of #152927 - AlexCeleste:thir-missing-index-subexpressions, r=TaKO8Ki
Index expressions rendered the index: subexpression as the id, instea…

…d of actually showing the content of the subexpression

This meant the content of the subexpression was completely missing from tree view (as the id did not reference anything)
2026-02-22 20:14:25 +01:00
Jonathan Brouwer 6aad1042ff Rollup merge of #152926 - makai410:final-on-assoc-type, r=fmease
Fix ICE when an associated type is wrongly marked as `final`

Fixes: rust-lang/rust#152797.

cc @mu001999 .
2026-02-22 20:14:24 +01:00
Jonathan Brouwer 388032363d Rollup merge of #152385 - LaneAsade:gate-type-const-defaults, r=BoxyUwU
Feature gate for defaulted associated type_consts with associated_type_defaults

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152385)*

This PR for issue rust-lang/rust#130288 extends a feature gate that was already present for defaulted associated types to defaulted type consts under associated_type_defaults.

Code added:
```
if ctxt == AssocCtxt::Trait && rhs.is_some() {
                    gate!(
                        &self,
                        associated_type_defaults,
                        i.span,
                        "associated type defaults are unstable"
                    );
                }
```

Error produced:
```
error[E0658]: associated type defaults are unstable
  --> $DIR/type-const-associated-default.rs:4:5
   |
LL |     type const N: usize = 10;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
   = help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
  --> $DIR/type-const-associated-default.rs:1:12
   |
LL | #![feature(min_generic_const_args)]
   |            ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
   = note: `#[warn(incomplete_features)]` on by default

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.

```
Thanks to @BoxyUwU for the guidance on this issue.
2026-02-22 20:14:23 +01:00
Folkert de Vries 14d29f9ae2 Stabilize cfg_select 2026-02-22 19:59:25 +01:00
Makai bde075b6f3 Fix ICE when an associated type or const is wrongly marked as final
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2026-02-22 23:54:51 +08:00
Ralf Jung b56949bddf extend unpin noalias tests to cover mutable references 2026-02-22 15:24:20 +01:00
Jonathan Brouwer 51d72725a2 Add regression test 2026-02-22 11:40:27 +01:00
Jonathan Brouwer 4486e4f235 Rollup merge of #152837 - TKanX:bugfix/152340-codegen-fn-attrs-const-caller, r=dingxiangfei2009
fix(codegen): Use `body_codegen_attrs` For Caller In `adjust_target_feature_sig`

### Summary:

#### Problem:

Coercing a `#[target_feature]` `const fn` to a function pointer inside a `const` body triggers an ICE (debug builds only):

```rust
#[target_feature(enable = "sse2")]
const fn with_target_feature() {}

const X: () = unsafe {
    let _: unsafe fn() = with_target_feature; // ICE
};
```

```text
assertion failed: def_kind.has_codegen_attrs()
unexpected `def_kind` in `codegen_fn_attrs`: Const
```

#### Root Cause:

Introduced in rust-lang/rust#135504 (2025-01-14, commit `8fee6a77394`). `adjust_target_feature_sig` unconditionally calls `codegen_fn_attrs(caller)` to get the caller's target features. `codegen_fn_attrs` requires that the `DefId` satisfies `has_codegen_attrs()`. `DefKind::Const`, `AssocConst`, and `InlineConst` do not — they have no codegen attributes by design. The debug assertion fires.

In release builds the call "worked" accidentally: `codegen_fn_attrs` on a const would reach the query machinery and happen to return empty attributes, producing a correct (but unguaranteed) result. The bug was latent until debug builds exposed it.

#### Solution:

Replace `codegen_fn_attrs(caller)` with `body_codegen_attrs(caller)`. `body_codegen_attrs` exists precisely for this case: it delegates to `codegen_fn_attrs` for function-like `DefKind`s and returns `CodegenFnAttrs::EMPTY` for const items. A const body has no target features, so returning empty is semantically correct.

Also fix the pre-existing variable name `callee_features` → `caller_features` (the variable holds the *caller*'s features, not the callee's).

### Changes:

- `compiler/rustc_middle/src/ty/context.rs`: `adjust_target_feature_sig` — use `body_codegen_attrs` for `caller`; rename `callee_features` → `caller_features`.
- `tests/ui/target-feature/const-target-feature-fn-ptr-coercion.rs`: regression test covering `Const`, `AssocConst`, and `InlineConst` caller contexts.

Fixes rust-lang/rust#152340.
2026-02-22 11:31:15 +01:00
Jonathan Brouwer 66cccfde99 Rollup merge of #147859 - cyrgani:nonfatal-tokenstream-parse, r=petrochenkov,JonathanBrouwer
reduce the amount of panics in `{TokenStream, Literal}::from_str` calls

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/147859)*

Before this PR, calling `TokenStream::from_str` or `Literal::from_str` with an invalid argument would always cause a compile error, even if the `TokenStream` is not used afterwards at all.
This PR changes this so it returns a `LexError` instead in some cases.

This is very theoretically a breaking change, but the doc comment on the impl already says
```
/// NOTE: some errors may cause panics instead of returning `LexError`. We reserve the right to
/// change these errors into `LexError`s later.
```

Fixes some cases of rust-lang/rust#58736.
2026-02-22 11:31:14 +01:00
Jonathan Brouwer 00d849a1b9 Rollup merge of #152591 - alexcrichton:simplify-rc-arc-default, r=joboet
Simplify internals of `{Rc,Arc}::default`

This commit simplifies the internal implementation of `Default` for these two pointer types to have the same performance characteristics as before (a side effect of changes in rust-lang/rust#131460) while avoid use of internal private APIs of Rc/Arc. To preserve the same codegen as before some non-generic functions needed to be tagged as `#[inline]` as well, but otherwise the same IR is produced before/after this change.

The motivation of this commit is I was studying up on the state of initialization of `Arc` and `Rc` and figured it'd be nicer to reduce the use of internal APIs and instead use public stable APIs where possible, even in the implementation itself.
2026-02-22 11:31:13 +01:00
Jonathan Brouwer 8a3d112fad Rollup merge of #151628 - enthropy7:fix-simd-const-eval-ice, r=RalfJung
Fix ICE in const eval of packed SIMD types with non-power-of-two element counts

fixes rust-lang/rust#151537

const evaluation of packed SIMD types with non-power-of-two element counts (like `Simd<_, 3>`) was hitting an ICE. the issue was in `check_simd_ptr_alignment` - it asserted that `backend_repr` must be `BackendRepr::SimdVector`, but for packed SIMD types with non-power-of-two counts the compiler uses `BackendRepr::Memory` instead (as mentioned in `rustc_abi/src/layout.rs:1511`).

was fixed by making `check_simd_ptr_alignment` accept both `BackendRepr::SimdVector` and `BackendRepr::Memory` for SIMD types. added a check to ensure we're dealing with a SIMD type, and the alignment logic works the same for both representations.

also i added a test that reproduces the original ICE.
2026-02-22 11:31:11 +01:00
bors d8b2222b11 Auto merge of #152737 - scottmcm:box_new_uninit_layout, r=RalfJung
Just pass `Layout` directly to `box_new_uninit`

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152737)*

We have a constant for it already (used in `RawVec` for basically the same polymorphization) so let's use it.

This is a simple follow-up to rust-lang/rust#148190 from one of the comments.
2026-02-22 01:21:56 +00:00
Matthias Krüger 3faf2826d0 Rollup merge of #152925 - ferrocene:hoverbear/improve-revision-flag-check, r=clubby789,jieyouxu
Improve runtest revision redundant cfg check

While attempting to ingest https://github.com/rust-lang/rust/pull/148034 via https://github.com/ferrocene/ferrocene/pull/2172 we noticed a test failure, as we add some `compile_flags` to tests.

We saw a failure looking like this:

```
Testing stage1 with compiletest suite=mir-opt mode=mir-opt (x86_64-unknown-linux-gnu)

running 2 tests
2026-02-20T20:21:28.846102Z ERROR compiletest::runtest: redundant cfg argument `copy` is already created by the revision

[mir-opt] tests/mir-opt/pre-codegen/copy_and_clone.rs#COPY ... F
.
```

While my Rust checkout passed:

```
Testing stage1 with compiletest suite=mir-opt mode=mir-opt (x86_64-unknown-linux-gnu)

running 2 tests
..

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 381 filtered out; finished in 107.10ms
```

This caused me to add some debugging statements.

Ferrocene:

```
2026-02-20T21:05:39.808427Z ERROR compiletest::runtest: "copy": does ["--edition=2015", "--cfg=copy"] contain `"--cfg=copy"` or `["--cfg", "copy"]`? true
2026-02-20T21:05:39.808427Z ERROR compiletest::runtest: "clone": does ["--edition=2015"] contain `"--cfg=clone"` or `["--cfg", "clone"]`? false
2026-02-20T21:05:39.808435Z ERROR compiletest::runtest: redundant cfg argument `copy` is already created by the revision
```

Rust:

```
2026-02-20T21:04:18.493158Z ERROR compiletest::runtest: "copy": does ["--cfg=copy"] contain `"--cfg=copy"` or `["--cfg", "copy"]`? false
2026-02-20T21:04:18.493158Z ERROR compiletest::runtest: "clone": does [] contain `"--cfg=clone"` or `["--cfg", "clone"]`? false
```

I noticed while reviewing the related functionality that there is a call to `.windows(2)` in the relevant check for redundant cfgs:

https://github.com/rust-lang/rust/blob/0376d43d443cba463a0b6a6ec9140ea17d7b7130/src/tools/compiletest/src/runtest.rs#L507-L511

Noting:

https://github.com/rust-lang/rust/blob/0376d43d443cba463a0b6a6ec9140ea17d7b7130/library/core/src/slice/mod.rs#L1064-L1066

Because of this, the revision check was getting an empty iterator when `self.props.compile_flags` was length 0 or 1.

This fix adjusts the check to handle such cases.

I went ahead and fixed the relevant test (4b3cd9b289ce0a36bda2756321f5fe455ea301e1) that was impacted by this. I do not suspect there are others, at least within the scope that Ferrocene tests, as we have not previously seen this failure.
2026-02-21 13:03:30 +01:00
Matthias Krüger 48cf90f337 Rollup merge of #152915 - CrooseGit:dev/reucru01/error-illegal-sv-init, r=mati865
Error on attempt to construct scalable vector type

If you attempt to construct a scalable vector type rust will ICE.

E.g.:
```rust
#[rustc_scalable_vector(4)]
#[allow(non_camel_case_types)]
struct svint32_t(i32);
fn main() {
    let foo = svint32_t(1);
    // This will ICE
}
```

This PR adds a check that will emit an error if you attempt to use a SV constructor and a test to ensure it works.
2026-02-21 13:03:29 +01:00
Matthias Krüger 7339fc5cec Rollup merge of #152929 - scottmcm:better-alignment-ranges, r=mati865
Tighten the `!range` bounds on alignments in vtables

Right now we're only telling LLVM that they're non-zero, but alignments must be powers of two so can't be more than `isize::MAX+1`.  And we actually never emit anything beyond LLVM's limit of 2²⁹, so outside of 16-bit targets the limit is that.

(Pulled out from rust-lang/rust#152867 which is starting to have too much in it.)
2026-02-21 13:03:28 +01:00
Scott McMurray 0187acccad Include the Align::MAX limit in the !range metadata for loading alignment from a vtable 2026-02-20 20:22:31 -08:00
Alex Celeste b7c28a8471 Index expressions rendered the index: subexpression as the id, instead of actually showing the content of the subexpression
This meant the content of the subexpression was completely missing from tree view (as the id did not reference anything)
2026-02-21 01:20:19 +00:00
Ana Hobden 7c011122e9 Fix copy_and_clone.rs 2026-02-20 13:25:11 -08:00
Jonathan Brouwer b0cdafbd4a Rollup merge of #152455 - JonathanBrouwer:remove_translation, r=jdonszelmann
Remove the translation `-Z` options and the `Translator` type.

This PR implements MCP https://github.com/rust-lang/compiler-team/issues/967

It is split up into individually reviewable commits, each commit passes tests:

* https://github.com/rust-lang/rust/commit/678211956793a2e772414a71700a21525af6e67b Removes the translation compiler options from the session
* https://github.com/rust-lang/rust/commit/8f300d02fe8d2f01a39425925afd4cf3e15a822b Removes the now empty `Translator` type
* https://github.com/rust-lang/rust/commit/ab715c536fbd4ac09409e9a44eea2e25ea8a4f48 Renames `translate_message` to `format_diag_message`, as the function no longer does any translation
* https://github.com/rust-lang/rust/commit/8bcbc3f766af6242dcb52afe1ef4f6b1a9685019 Removes a section describing the removed compiler options from the rustc dev guide
2026-02-20 22:00:57 +01:00
Jonathan Brouwer fd38ec4690 Rollup merge of #152907 - aerooneqq:delegation-generics-new-tests, r=petrochenkov
Add tests for delegation generics

This PR adds tests from rust-lang/rust#151864 as discussed in this [comment](https://github.com/rust-lang/rust/pull/151864#issuecomment-3928053049). Part of rust-lang/rust#118212.

The majority of new tests are added in `mapping` folder, (`ast-hir-engine` folder in rust-lang/rust#151864), those tests test mapping between generic params of delegee and our generated function for delegation (that is why the name of the folder was changed, I think it better reflects what those tests testing). In each mapping test comments were added to each test case and one comment describing the goal of mapping tests was added at the top of each file.

Next, tests for defaults in generic params (`generic-params-defaults.rs`), params with the same name (`generic-params-same-names`), errors in providing user-specified generic args (`generics-gen-args-errors.rs`) and wrong signature of a generated function in impl trait case (`impl-trait-wrong-args-count.rs`, renamed from `wrong-args-count-ice.rs` in rust-lang/rust#151864). `generic-aux-pass.rs` test was not added, as all reuses in this test produce known ICE `DefId::expect_local DefId(..) isn't local` rust-lang/rust#143498 (which will be fixed in rust-lang/rust#151864, however it will not close mentioned issue, as synthetic generic params are not yet supported in new generics implementation).

r? @petrochenkov
2026-02-20 22:00:57 +01:00
Jonathan Brouwer bbce734ce0 Rollup merge of #152527 - bjorn3:remove_z_emit_thin_lto, r=cuviper
Remove -Zemit-thin-lto flag

As far as I can tell it was introduced in https://github.com/rust-lang/rust/pull/98162 to allow fat LTO with `-Clinker-plugin-lto`. In https://github.com/rust-lang/rust/pull/136840 a change was made to automatically disable ThinLTO summary generation when `-Clinker-plugin-lto -Clto=fat` is used, so we can safely remove it.

Fixes rust-lang/rust#152490
2026-02-20 22:00:56 +01:00
Jonathan Brouwer ff7d14e17d Rollup merge of #146972 - mu001999-contrib:fix/use-dollar-crate, r=petrochenkov
Support importing path-segment keyword with renaming

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/146972)*

#### Reference PR

- https://github.com/rust-lang/reference/pull/2010
- https://github.com/rust-lang/reference/pull/2136

#### Description

This PR unifies and extends the behavior of importing path-segment keywords (`crate`/`$crate`/`super`/`self`), resolving several long-standing inconsistencies.

Previously, Rust only allowed `use crate as name;` without renaming support for other path keywords. This PR enables importing these keywords with explicit renaming. And it also denies importing these keywords without renaming.

##### What's now allowed

For **`crate`** and **`$crate`**:
- `use crate as name;`
- `use crate::{self as name};`
- `use $crate as name;`
- `use $crate::{self as name};`

For **`super`** (including chained `super::super`):
- `use super as name;`
- `use super::{self as name};`
- `use super::super as name;`
- `use super::super::{self as name};`

For **`self`**:
- `use self as name;`
- `use self::{self as name};`

##### Removed error codes

Two error codes are no longer emitted:

- **E0430**: Previously emitted for duplicate `self` imports like `std::fmt::{self, self}`. The existing E0252 ("name defined multiple times") provides sufficient guidance.
- **E0431**: Previously emitted for `use {self [as name]};` and `use ::{self [as name]};`. These patterns are now allowed or denied but with new clearer errors.
    - For `use {self as name};` and `use ::{self as name};` (in edition 2015), they are allowed now and equivalent to `use crate as name`;
    - For `use {self};` and `use ::{self};` (in edition 2015) without renaming, they are equivalent to `use crate;`, the new clearer error suggests adding an explicit rename.
    - For `use ::{self [as name]};` after edition 2015, it is equivalent to `use ${extern-prelude} [as name];`, it is denied with new errors.

##### Future

We plan to remove error [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) and support `self` at the end of paths (https://github.com/rust-lang/rust/pull/146972#issuecomment-3719825627). This language extension and lint for redundant `::self` instead of hard error `E0429` will be landed separately in the future.

---

Fixes rust-lang/rust#29036
Fixes rust-lang/rust#35612
Fixes rust-lang/rust#37156
Fixes rust-lang/rust#146967
Fixes rust-lang/rust#149811

r? petrochenkov
2026-02-20 22:00:54 +01:00
Jonathan Brouwer fb6d93917e Rollup merge of #146832 - Natural-selection1:not-in-chains, r=petrochenkov
Not linting irrefutable_let_patterns on let chains

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/146832)*

# Description

this PR makes the lint `irrefutable_let_patterns` not check for `let chains`,
only check for single `if let`, `while let`, and `if let guard`.

# Motivation

Since `let chains` were stabilized, the following code has become common:

```rust
fn max() -> usize { 42 }

fn main() {
    if let mx = max() && mx < usize::MAX { /* */ }
}
```

This code naturally expresses "please call that function and then do something if the return value satisfies a condition".
Putting the let binding outside the if would be bad as then it remains in scope after the if, which is not the intent.

Current Output:

```bash
warning: leading irrefutable pattern in let chain
 --> src/main.rs:7:8
  |
7 |     if let mx = max() && mx < usize::MAX {
  |        ^^^^^^^^^^^^^^
  |
  = note: this pattern will always match
  = help: consider moving it outside of the construct
  = note: `#[warn(irrefutable_let_patterns)]` on by default
```

Another common case is progressively destructuring a struct with enum fields, or an enum with struct variants:

```rust
struct NameOfOuterStruct {
    middle: NameOfMiddleEnum,
    other: (),
}
enum NameOfMiddleEnum {
    Inner(NameOfInnerStruct),
    Other(()),
}
struct NameOfInnerStruct {
    id: u32,
}

fn test(outer: NameOfOuterStruct) {
    if let NameOfOuterStruct { middle, .. } = outer
        && let NameOfMiddleEnum::Inner(inner) = middle
        && let NameOfInnerStruct { id } = inner
    {
        /* */
    }
}
```

Current Output:

```bash
warning: leading irrefutable pattern in let chain
  --> src\main.rs:17:8
   |
17 |     if let NameOfOuterStruct { middle, .. } = outer
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this pattern will always match
   = help: consider moving it outside of the construct
   = note: `#[warn(irrefutable_let_patterns)]` on by default

warning: trailing irrefutable pattern in let chain
  --> src\main.rs:19:12
   |
19 |         && let NameOfInnerStruct { id } = inner
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this pattern will always match
   = help: consider moving it into the body
```

To avoid the warning, the readability would be much worse:

```rust
fn test(outer: NameOfOuterStruct) {
    if let NameOfOuterStruct {
        middle: NameOfMiddleEnum::Inner(NameOfInnerStruct { id }),
        ..
    } = outer
    {
        /* */
    }
}
```

# related issue

* rust-lang/rust#139369

# possible questions

1. Moving the irrefutable pattern at the head of the chain out of it would cause a variable that was intended to be temporary to remain in scope, so we remove it.
   However, should we keep the check for moving the irrefutable pattern at the tail into the body?

2. Should we still lint `entire chain is made up of irrefutable let`?

---

This is my first time contributing non-documentation code to Rust. If there are any irregularities, please feel free to point them out.
: )
2026-02-20 22:00:54 +01:00
reucru01 a561a4b8e1 Errors on illegal SV init 2026-02-20 14:24:08 +00:00
aerooneqq 7348ffbfbf Add tests 2026-02-20 16:13:02 +03:00
Jonathan Brouwer a196a001b3 Rollup merge of #152883 - mu001999-contrib:fix/final-bad-use, r=Kivooeo
Deny final not followed by item

Fixes rust-lang/rust#152820
2026-02-20 13:25:01 +01:00
Jonathan Brouwer c013bcca0b Rollup merge of #152861 - ozankenangungor:fix-underscore-import-suggestion, r=Kivooeo
resolve: do not suggest `_` for unresolved imports

Fix invalid unresolved-import suggestion when a module contains an item named `_`.

`use _` is never valid syntax, so `_` should not be suggested as a similar name.

Closes rust-lang/rust#152812
2026-02-20 13:24:59 +01:00
bjorn3 6366a698e3 Remove -Zemit-thin-lto flag
As far as I can tell it was introduced to allow fat LTO with
-Clinker-plugin-lto. Later a change was made to automatically disable
ThinLTO summary generation when -Clinker-plugin-lto -Clto=fat is used,
so we can safely remove it.
2026-02-20 12:19:41 +00:00
Jana Dönszelmann 8e7bc3c7d1 fix src/tools 2026-02-20 10:35:52 +01:00
Jana Dönszelmann be4f92fc45 emit unreachable pattern lint 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 2bed584742 add lint for using AttributeKind in find_attr 2026-02-20 09:50:16 +01:00
mu001999 59781157a7 Deny final not followed by item 2026-02-20 12:12:21 +08:00
mu001999 6609e4bacf Support use self::super as name; 2026-02-20 11:11:31 +08:00
mu001999 a348051f59 Recover supporting use std::{io::self} 2026-02-20 11:08:52 +08:00
mu001999 58e5475683 Rewrite build_reduced_graph_for_use_tree 2026-02-20 10:58:58 +08:00
bors ef70767064 Auto merge of #152689 - scottmcm:also-simplify-of-sized-val-alt, r=cjgillot
Simplify `size/align_of_val<T: Sized>` to `size/align_of<T>` instead

This is relevant to things like `Box<[u8; 1024]>` where the drop looks at the `size_of_val` (since obviously it might be DST in general) but where we don't actually need to do that since it's always that same value for the `Sized` type.

(Equivalent to rust-lang/rust#152681, but flipped in the rebase so it can land before rust-lang/rust#152641 instead of depending on it.)
2026-02-19 22:03:50 +00:00
bors 7f99507f57 Auto merge of #149375 - oli-obk:const_typeck, r=fee1-dead
Perform many const checks in typeck

Some smaller diagnostic changes, the biggest ones avoided by https://github.com/rust-lang/rust/pull/148641

We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).

r? @fee1-dead
2026-02-19 18:41:36 +00:00
Ozan Kenan Güngör aebafba4bb resolve: do not suggest _ for unresolved imports
`use _` is never valid, so it should not be suggested as a similar name.
2026-02-19 21:24:47 +03:00
Hegui Dai 4f31ff893d Not linting irrefutable_let_patterns on let chains
inline rest of the check
try fix ci errors
inline in check_let
2026-02-19 22:27:26 +08:00
bors b6bed6f2d9 Auto merge of #152839 - JonathanBrouwer:rollup-iPaprtK, r=JonathanBrouwer
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#151733 (Use function shims to make sure EII works on apple targets)
 - rust-lang/rust#152558 (rustc_expand: improve diagnostics for non-repeatable metavars in repetition)
 - rust-lang/rust#152596 (Make all multipart suggestions verbose)
 - rust-lang/rust#152815 (Add CURRENT_RUSTC_VERSION support for Clippy)
 - rust-lang/rust#152733 (Port #[rustc_doc_primitive] to the new attribute parser)
 - rust-lang/rust#152817 (Update enzyme submodule to match upstream)
 - rust-lang/rust#152819 (explicitly show behavior of <_>::assoc_fn)
 - rust-lang/rust#152823 (fix stale comments left over from ed3711e)
 - rust-lang/rust#152824 (Enable "View all comments" link feature in `triagebot.toml`)
2026-02-19 14:07:01 +00:00
Jonathan Brouwer 9330931a2b Rollup merge of #152596 - estebank:multipart_suggestions, r=petrochenkov
Make all multipart suggestions verbose

The ShowAlways style of suggestions is usually easier to understand than the inline style.
2026-02-19 10:56:37 +01:00
Jonathan Brouwer 610e63b9ba Rollup merge of #152558 - Unique-Usman:ua/decmacrorepeatable, r=estebank
rustc_expand: improve diagnostics for non-repeatable metavars in repetition

Enhance `NoSyntaxVarsExprRepeat` by suggesting similarly named metavariables, distinguishing repeatable vs non-repeatable bindings, and listing available repeatable variables when no match exists.
2026-02-19 10:56:37 +01:00
Jonathan Brouwer 46126ac931 Rollup merge of #151733 - jdonszelmann:eii-on-apple, r=oli-obk
Use function shims to make sure EII works on apple targets

Use function shims to make sure EII works on apple targets (and generally accepts target-arch attributes)

Explainer: https://github.com/rust-lang/rust/pull/146348#issuecomment-3631810110
Tracking issue: https://github.com/rust-lang/rust/issues/125418
2026-02-19 10:56:36 +01:00
bors 41198cb965 Auto merge of #148034 - dianqk:matchbr-copy, r=cjgillot
Simplify the canonical enum clone branches to a copy statement

I have overhauled MatchBranchSimplification in this PR. This pass tries to unify statements one by one, which is more readable and extensible.

This PR also unifies the following pattern that is mostly generated by GVN into one basic block that contains the copy statement:

```rust
match a {
    Foo::A(_) => *a,
    Foo::B => Foo::B
}
```

Fixes https://github.com/rust-lang/rust/issues/128081.
2026-02-19 09:56:26 +00:00
Tony Kan 034f7f058a test(codegen): Add regression test for issue #152340 2026-02-18 21:52:55 -08:00
LaneAsade 84140cf4e1 gate defaulted type consts with associated_type_defaults 2026-02-19 10:07:06 +05:30