Commit Graph

318939 Commits

Author SHA1 Message Date
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
bors 0376d43d44 Auto merge of #152904 - JonathanBrouwer:rollup-8vFeFeZ, r=JonathanBrouwer
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#152759 (Simpler `find_attr!()`)
 - rust-lang/rust#152057 (bootstrap: respect POSIX jobserver)
 - rust-lang/rust#152818 (DOC: do not link to "nightly" in Iterator::by_ref() docstring)
 - rust-lang/rust#152840 (Add bootstrap snapshot tests for {`install`, `install src`})
 - rust-lang/rust#152844 (Rename `DepGraphQuery` to `RetainedDepGraph`)
 - rust-lang/rust#152846 (Clarify some variable names in the query proc-macro)
 - rust-lang/rust#152858 (Fix typo in doc for core::mem::type_info::Struct)
 - rust-lang/rust#152861 (resolve: do not suggest `_` for unresolved imports)
 - rust-lang/rust#152873 (std::ops::ControlFlow - use "a" before `Result`)
 - rust-lang/rust#152877 (std::ops::ControlFlow - use normal comment for internal methods)
 - rust-lang/rust#152883 (Deny final not followed by item)
2026-02-20 16:26:56 +00: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 a2abf2a018 Rollup merge of #152877 - DanielEScherzer:patch-3, r=scottmcm
std::ops::ControlFlow - use normal comment for internal methods

Rather than a doc comment, which causes rustdoc to output the impl documentation even though the impl block only has non-public methods.
2026-02-20 13:25:00 +01:00
Jonathan Brouwer be340852ba Rollup merge of #152873 - DanielEScherzer:patch-2, r=jhpratt
std::ops::ControlFlow - use "a" before `Result`

Rather than "an"
2026-02-20 13:24:59 +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
Jonathan Brouwer e21941a20b Rollup merge of #152858 - apasel422:patch-1, r=oli-obk
Fix typo in doc for core::mem::type_info::Struct
2026-02-20 13:24:58 +01:00
Jonathan Brouwer 412b0c3efc Rollup merge of #152846 - Zalathar:query-proc-macro, r=nnethercote
Clarify some variable names in the query proc-macro

These are some cleanups to the `rustc_macros::query`, extracted from https://github.com/rust-lang/rust/pull/152833.

r? nnethercote
2026-02-20 13:24:58 +01:00
Jonathan Brouwer eb5f275181 Rollup merge of #152844 - Zalathar:retain-dep-graph, r=JonathanBrouwer
Rename `DepGraphQuery` to `RetainedDepGraph`

This is a revised subset of https://github.com/rust-lang/rust/pull/152836 that only performs an internal renaming, and does not touch the `-Zquery-dep-graph` flag.

The new name and comments for `RetainedDepGraph` should hopefully do a better job of communicating that it is not used in normal compiler operation, even in incremental mode.
2026-02-20 13:24:57 +01:00
Jonathan Brouwer 29871ea667 Rollup merge of #152840 - jieyouxu:bootstrap-install-src-no-docs, r=clubby789
Add bootstrap snapshot tests for {`install`, `install src`}

And `install src` with `build.docs = false`.

This is mostly to get coverage for the baseline to make it easier to review rust-lang/rust#150845.
2026-02-20 13:24:57 +01:00
Jonathan Brouwer cfc274c3bc Rollup merge of #152818 - mgeier:doc-by_ref-link, r=scottmcm
DOC: do not link to "nightly" in Iterator::by_ref() docstring

I happened to see that the link in the docstring https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.by_ref points to the "nightly" docs instead of "stable".

I'm not sure if my fix actually works because I didn't get `cargo doc` to run on my local computer.
2026-02-20 13:24:56 +01:00
Jonathan Brouwer 12c80d252d Rollup merge of #152057 - haampie:hs/fix/bootstrap-respect-jobserver-protocol, r=clubby789
bootstrap: respect POSIX jobserver

When bootstrapping Rust, the `-j N` flag was passed to CMake, which was
then forwarded to Ninja. This prevents the jobserver from being used,
and as a result leads to oversubscription when Rust is just one of the
many packages built as part of a larger software stack.

Since Cargo and the Rust compiler have long supported the jobserver, it
would be good if also bootstrapping Rust itself would participate in the
protocol, leading to composable parallelism.

This change allows bootstrapping to respect an existing FIFO based
jobserver. Old pipe based jobservers are not supported, because they are
brittle: currently the Python scripts in bootstrap do not inherit the
file descriptors, but do pass on `MAKEFLAGS`, which has lead to errors
like "invalid file descriptor" in the past. Because Ninja only supports
FIFO based jobservers, it's better to focus on new jobservers only,
which shouldn't suffer from the "invalid file descriptor" issue.

In summary:

* Bootstrap Cargo passes `MAKEFLAGS` verbatim to subprocesses if it
  advertises a FIFO style jobserver, otherwise it unsets it. This ensures
  subprocesses respect the jobserver during bootstrap.
* `llvm.rs` does not pass `-j` to `cmake` when a FIFO style jobserver is
  set in `MAKEFLAGS`. This ensures Ninja respects the jobserver.
* Bootstrap Cargo no longer unsets `MKFLAGS`: from git blame, GNU Make
  considered it a historical artifact back in 1992, and it is never read
  by GNU Make, it's only set for backwards compatibility in case sub-Makefiles
  read it.

---

I've tested this with the [Spack package manager](https://github.com/spack/spack) starting the POSIX jobserver,
building node.js and rust in parallel with `-j16`, which looks like this:

```console
$ pstree 382710
python3─┬─python3
        └─python3─┬─python3─┬─make───make───6*[ccache───g++───cc1plus]
                  │         └─{python3}
                  └─python3─┬─python3.11───bootstrap───cmake───ninja-build───10*[sh───ccache───g++───cc1plus]
                            └─{python3}
```

As you can see there are 10 `g++` processes running for rust, and `6` for node.js, and
with a mix of `make` and `ninja` as build tools :).

(The only violation I see now is `rust-lld`, but I think that'll be fixed with the LLVM 23
release)
2026-02-20 13:24:56 +01:00
Jonathan Brouwer c0fe6943ae Rollup merge of #152759 - jdonszelmann:simpler-get-attrs, r=jonathanbrouwer
Simpler `find_attr!()`

r? @JonathanBrouwer
cc: @jyn514
2026-02-20 13:24:55 +01:00
Zalathar 19e0c62e10 Rename DepGraphQuery to RetainedDepGraph 2026-02-20 20:55:09 +11:00
Jana Dönszelmann 8e7bc3c7d1 fix src/tools 2026-02-20 10:35:52 +01:00
Jana Dönszelmann df23df54a6 tidy 2026-02-20 09:50:55 +01:00
Jana Dönszelmann be4f92fc45 emit unreachable pattern lint 2026-02-20 09:50:16 +01:00
Jana Dönszelmann decec173ec remove AttributeKind everywhere 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
Jana Dönszelmann a2367eca47 star-import AttributeKind 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 04f762d842 allow deprecated for some valid uses 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 54d673dd69 deprecate functions 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 7477a5b48e update docs 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 9a9443950d change all uses 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 07f46cec49 Convenience matcher in find_attrs for crate attrs 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 63edc913fa change all uses 2026-02-20 09:50:16 +01:00
Jana Dönszelmann c3fe049a25 change find_attr macro to search tcx.get_all_attrs automatically 2026-02-20 09:50:16 +01:00
bors 59fd4ef94d Auto merge of #152747 - nnethercote:bring-back-enum-DepKind, r=Zalathar
Bring back `enum DepKind`.

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

It was removed in rust-lang/rust#115920 to enable it being moved to `rustc_query_system`, a move that has recently been reversed. It's much simpler as an enum.

r? @Zalathar
2026-02-20 06:07:20 +00: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
Daniel Scherzer be83f55595 std::ops::ControlFlow - use normal comment for internal methods
Rather than a doc comment, which causes rustdoc to output the impl
documentation even though the impl block only has non-public methods.
2026-02-19 16:44:09 -08:00
Daniel Scherzer 4ab6d1f4cc std::ops::ControlFlow - use "a" before Result
Rather than "an"
2026-02-19 15:04:36 -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
Andrew Paseltiner 27c04763e1 Fix typo in doc for core::mem::type_info::Struct 2026-02-19 10:27:22 -05: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
Zalathar ede72796ba Clarify some variable names in the query proc-macro 2026-02-19 22:54:22 +11:00
Jieyou Xu a9e6a89b06 bootstrap: add snapshot tests for {install, install src}
And `install src` with `build.docs = false`.
2026-02-19 18:34:04 +08:00
Jonathan Brouwer cad5b1a46f Rollup merge of #152824 - Urgau:triagebot-view-all-comments, r=Kobzol
Enable "View all comments" link feature in `triagebot.toml`

This PR enables triagebot "View all comments" link feature.

Documentation: https://forge.rust-lang.org/triagebot/view-all-comments-link.html

Example for this PR: [View all comments](https://triage.rust-lang.org/gh-comments/rust-lang/rust/issues/152824)
2026-02-19 10:56:41 +01:00
Jonathan Brouwer 8f8af0b5ba Rollup merge of #152823 - Zeromemer:fix-stale-comments, r=jhpratt
fix stale comments left over from ed3711e

Remove stale overflow comments in core::str.

Commit ed3711ea introduced stale comments in library/core/src/str/iter.rs.

Prior to that commit, the comments explained why `(len + 3)` and `(len + 2)` couldn't overflow.
Since the code now uses `div_ceil`, these specific overflow justifications are no longer relevant to the current implementation.
2026-02-19 10:56:40 +01:00
Jonathan Brouwer f17139477b Rollup merge of #152819 - yaahc:explicit_probe_assembly, r=Kivooeo
explicitly show behavior of <_>::assoc_fn

Inspired by a conversation with @lcnr about type relative name resolution.

From lcnr:

> and i hate the fact that this match isn't exhaustive (hiding the behavior for `<_>::assoc_fn` https://github.com/rust-lang/rust/blob/13c38730d981289cc7ae4cc109fd7756bf83ee67/compiler/rustc_hir_typeck/src/method/probe.rs#L893

This PR changes that match to be exhaustive.
2026-02-19 10:56:40 +01:00
Jonathan Brouwer 8b74e12f3e Rollup merge of #152817 - ZuseZ4:update-enzyme-to-main, r=Kobzol
Update enzyme submodule to match upstream

For a while we were carying one extra commit to handle static builds on macos. That commit got upstreamed, so we can drop it (and update to a newer Enzyme while at it).

r? @Kobzol
Can I get a rollup, please?
2026-02-19 10:56:39 +01:00
Jonathan Brouwer 9a90ad485e Rollup merge of #152733 - Ozzy1423:attr-doc, r=jdonszelmann
Port #[rustc_doc_primitive] to the new attribute parser

Tracking issue: https://github.com/rust-lang/rust/issues/131229

r? @JonathanBrouwer
2026-02-19 10:56:39 +01:00
Jonathan Brouwer 6b227bb187 Rollup merge of #152815 - blyxyas:current-rustc-version-clippy, r=Mark-Simulacrum
Add CURRENT_RUSTC_VERSION support for Clippy

We've been talking about this since Sept. 2022, finally decided to add the dreaded 1-line diff.

cc https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Using.20CURRENT_RUSTC_VERSION.20in.20clippy.3A.3Aversion.3F/with/516468805

cc https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Use.20CURRENT_RUSTC_VERSION.20for.20version.20attribute/with/299900715

Overrides the currently unmerged rust-lang/rust-clippy#14299

cc @rust-lang/clippy

---

This PR does not modify in any way the needed behaviour of T-Release when releasing (I hope)
2026-02-19 10:56:38 +01: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