2385 Commits

Author SHA1 Message Date
Jonathan Brouwer b0c869a35e Rollup merge of #156596 - nnethercote:split-LintExpectation, r=GuillaumeGomez
Split `LintExpectationId`s

This PR makes clearer where stable and unstable `LintExpectationIds` can occur, plus a few other small cleanups. Details in individual commits.

r? @GuillaumeGomez
2026-05-17 15:52:37 +02:00
Nicholas Nethercote 22cf1fb6fe Split LintExpectationId
`LintExpectationId` has two variants, `Unstable` and `Stable`. There are
some places where both variants are possible, but there are also places
where only one of `Unstable` or `Stable` is possible.

This commit encodes this into the type system by introducing
new types `UnstableLintExpectationId` and `StableLintExpectationId`. The
variants of `LintExpectationId` now enclose these. This makes it clearer
what values are possible where.

Other things of note:
- `LintLevelsProvider` gets an associated type and some method changes.
- `LintContext` gets an associated type.
- `LevelSpec` is made generic. `UnstableLevelSpec` and `StableLevelSpec`
  typedefs are added.
- The unstable types are now guaranteed by the type system to never be
  stably hashed. Previously this was a runtime check.
2026-05-16 21:16:35 +10:00
Jonathan Brouwer 1a3ed2e62d Rollup merge of #156319 - bjorn3:eii_dylib_require_def, r=jdonszelmann
Require EIIs to be defined when we compile a rust dylib

The linker will complain about undefined symbols otherwise and on object file formats with two level namespaces (Mach-O and PE/COFF) it is required to know which dylib a symbol will be imported from when linking a dylib or executable.

r? @jdonszelmann
2026-05-15 20:11:41 +02:00
bjorn3 860813dd9d Require EIIs to be defined when we compile a rust dylib
The linker will complain about undefined symbols otherwise and on object
file formats with two level namespaces (Mach-O and PE/COFF) it is
required to know which dylib a symbol will be imported from when linking
a dylib or executable.
2026-05-15 15:49:35 +02:00
Nicholas Nethercote 530a73f17e Prevent invalid LevelSpec values
`LevelSpec` has two related fields, `level` and `lint_id`. This commit
makes the fields private (and introduces getters) to ensure they are set
together using only valid combinations.

The commit also introduces `is_allow` and `is_expect` methods because
those are useful.
2026-05-14 16:28:50 +10:00
Nicholas Nethercote f9fd7f76f2 Rename DeadItem::level
The name is misleading because the field contains a `Level` *and* an
`Option<LintExpectationId>`. This commit renames it `level_plus` which
better communicates that it's more than just a level.
2026-05-14 13:20:59 +10:00
Nicholas Nethercote ccfac5469a Rename LevelAndSource
It is misnamed, given that it has three fields: `level`, `lint_id`, and
`src`. (Presumably the `lint_id` was added later.)

This commit renames it as `LevelSpec`. (I also considered `LevelInfo`
but that's very generic. `Spec` has pre-existing uses in
`LintLevelsProvider::current_specs` and `LintSet::specs` and
`ShallowLintLevelMap::specs`.)

Related things renamed as well:
- `level` -> `level_spec` (where appropriate)
- `lint_levels` -> `lint_level_specs`
- `get_lint_level` -> `get_lint_level_spec`
- `level_and_source` -> `level_spec`
- `CodegenLintLevels` -> `CodegenLintLevelSpecs`
- `raw_lint_id_level` -> `raw_lint_level_spec`
- `lint_level_at_node` -> `lint_level_spec_at_node`
- `reveal_actual_level` -> `reveal_actual_level_spec`
- `probe_for_lint_level` -> `probe_for_lint_level_spec`

This clears up a lot of `Level` vs. `LevelSpec` ambiguity. E.g. no more
`level.level` expressions.
2026-05-14 13:20:57 +10:00
Oli Scherer 3a2ae6a204 Stop putting owner's DefId into their own node_id_to_def_id map
Now they unfortunately land in their parent, which is not necessary
2026-05-13 09:29:22 +02:00
Oli Scherer adb2b0fd57 Split the resolver tables into per-owner tables, starting with node_id_to_def_id 2026-05-13 09:22:55 +02:00
Jonathan Brouwer 65d0e52cff Rollup merge of #156466 - kpreid:checkattr, r=JonathanBrouwer
Refactor `CheckAttrVisitor` so rustfmt can format it.

I don’t have any need for this myself, but [I heard it was annoying people](https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/.60.23.5Bdiagnostic.3A.3Aon_unimplemented.5D.60.20on.20trait.20methods.3F/near/594113991) and I like fixing formatting and structure problems.

The key change is that the do-nothing cases are now individual match arms instead of an enormous or-pattern. In order to achieve this cleanly, I moved the code handling `Attribute::Parsed` into a separate function matching `AttributeKind`s rather than `Attribute`s.

This also fixes `RustcAllowIncoherentImpl` being non-alphabetical because it was spelled without a leading “|” (though that by itself could be achieved by adding the optional leading “|”).
2026-05-11 23:03:10 +02:00
Jonathan Brouwer 1db77ea560 Rollup merge of #155023 - TaKO8Ki:move-expr-1, r=nikomatsakis
Introduce move expressions (`move($expr)`)

This is an experimental first version of move expressions.

This first version implements it just in plain closures. A support for coroutine closures will be added in follow up pull requests.

RFC: will be added later
Tracking issue: https://github.com/rust-lang/rust/issues/155050
Project goal:
- https://github.com/rust-lang/rust-project-goals/issues/107
- https://rust-lang.github.io/rust-project-goals/2026/ergonomic-rc.html

r? @nikomatsakis
2026-05-11 23:03:03 +02:00
Kevin Reid a194d65213 Refactor CheckAttrVisitor so rustfmt can format it.
The key change is that the do-nothing cases are now individual
match arms instead of an enormous or-pattern. In order to achieve this
cleanly, I moved the code handling `Attribute::Parsed` into a separate
function matching `AttributeKind`s rather than `Attribute`s.

This also fixes `RustcAllowIncoherentImpl` being non-alphabetical
because it was spelled without a leading “|”.
2026-05-11 11:33:45 -07:00
Frank King 0fc0057f8d Fix: Add a span to AttributeKind::PinV2 2026-05-09 19:10:18 +08:00
Takayuki Maeda 98348de63a add move(expr) syntax 2026-05-07 22:22:56 +09:00
bors 0e5924a4a0 Auto merge of #149509 - mu001999-contrib:flag/pub-as-pub-crate, r=jdonszelmann
Lint unused pub items in binary crates



~~This PR adds a new unstable flag -Ztreat-pub-as-pub-crate as [@Kobzol](https://github.com/Kobzol) suggested.~~
~~When compiling binary crates with this flag, the seed worklist will only contain the entry fn and won't contain other reachable items. Then we can do the dead code analysis for pub items just like they are pub(crate).~~

Related zulip thread [#general > pub/pub(crate) within a binary is a footgun](https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/pub.2Fpub.28crate.29.20within.20a.20binary.20is.20a.20footgun/with/558931034).

---

Updated:

Adds a new lint `unused_pub_items_in_binary` (crate-level, default allow for now) instead of the previous unstable flag to lint unused `pub` items for binary crates.

See more details of implementation in https://github.com/rust-lang/rust/pull/149509#issuecomment-4102337689.

This lint is allowed by default, but I believe this has been better than the unstable flag. Making it warn-by-default will lead to a lot of noise for this PR (like bless many tests). So I'd like to make it warn-by-default in a separate PR in the future.
2026-05-07 05:38:32 +00:00
bors 4ddd4538a8 Auto merge of #154327 - WaffleLapkin:drop_in_place_ref, r=RalfJung,scottmcm,saethlin
change the type of the argument of `drop_in_place` lang item to `&mut _`



We used to special case `core::ptr::drop_in_place` when computing LLVM argument attributes with this hack:

https://github.com/rust-lang/rust/blob/db5e2dc248fe5bb26f70d7baec46a3bca9fa3e1d/compiler/rustc_ty_utils/src/abi.rs#L383-L392

This is because even though `drop_in_place` takes a `*mut T` it is semantically a `&mut T` (remember how `&mut Self` is passed to `Drop::drop`). This is apparently relevant for perf.

This PR replaces this hack with a simpler solution -- it makes `drop_in_place` a thin wrapper around newly added `core::ptr::drop_glue`, which is the actual lang item and takes a `&mut T`:

https://github.com/rust-lang/rust/blob/d2563d5003bbecff1efc40c1f5673ceec603825b/library/core/src/ptr/mod.rs#L810-L833

------

The rest of the PR is blessing tests and cleaning up things which are not necessary after this change.

One thing that is a bit awkward is that now that `drop_glue` is the actual lang item, a lot of the comments referring to `drop_in_place` are outdated. Should I try fixing that?

I've also changed `async_drop_in_place` to take a `&mut T`, and it simplified the code handling it a bit. (since it's unstable we don't need to introduce a wrapper)

-------

cc @RalfJung 
Closes https://github.com/rust-lang/rust/issues/154274
2026-05-07 00:52:53 +00:00
mu001999 26bfcf3f35 Rename unused_pub_items_in_binary to dead_code_pub_in_binary 2026-05-06 19:34:18 +08:00
mu001999 27a8bb677b Implement unused_pub_items_in_binary lint 2026-05-06 19:34:15 +08:00
mu001999 c44e9222a0 Refactor dead code liveness plumbing 2026-05-06 19:33:34 +08:00
Waffle Lapkin 810eae99af rename drop_in_place lang item to drop_glue 2026-05-05 12:36:39 +02:00
Oli Scherer a015eb119a Revert const hack and use const closure 2026-05-05 11:36:18 +02:00
Oli Scherer 664177fdf1 Remove const closure hacks in libstd 2026-05-05 11:35:29 +02:00
Jonathan Brouwer 081e7c4481 Rollup merge of #155433 - oli-obk:bye-bye-long-attribute, r=RalfJung,ShoyuVanilla
Rip out rustc_layout_scalar_valid_range_* attribute support

And either removes tests for it or replaces the uses with pattern types.

primarily fixes rust-lang/rust#135996

fixes rust-lang/rust#147761
fixes rust-lang/rust#133652
2026-05-03 16:33:22 +02:00
Oli Scherer 11d88ee42b Rip out rustc_layout_scalar_valid_range_* attribute support 2026-05-03 10:59:52 +02:00
mejrs 4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
mejrs 1cd3a3d1cf remove unused diagnostic attr spans 2026-05-02 17:33:10 +02:00
Nicholas Nethercote 6d79bc6f01 Move feature* methods from parse mod to errors mod.
As the FIXME comment says, these no longer use `ParseSess` and so the
`parse` mod is not a good place for them. The `errors` mod is a better
home.
2026-04-30 12:02:33 +10:00
Jonathan Brouwer 67cf0dee49 Remove most usages of Stage 2026-04-29 07:41:14 +02:00
Jonathan Brouwer e8ad7f25e4 Rollup merge of #155702 - mejrs:itemkind_trait-fields, r=petrochenkov
Change `ItemKind::Trait` to a field variant.

This changes `ItemKind::Trait` from an octuple(!!) to an enum variant with fields. Their names were chosen to match up with existing usage and minimize renaming.

I'm leaning towards renaming `ident` to `name` as well; let me know if that's desired.
2026-04-27 19:54:46 +02:00
Jonathan Brouwer cafe02e1e3 Add first_span to doc attribute 2026-04-27 09:47:23 +02:00
mejrs c2916be8d7 Permit {This} in diagnostic attribute format literals 2026-04-24 19:59:32 +02:00
mejrs 9515f52d61 Change ItemKind::Trait to have named fields. 2026-04-24 19:03:16 +02:00
yukang 8d75f0cbfc add on_unmatch_args 2026-04-22 19:28:44 +08:00
Jacob Pratt 02fc33b679 Rollup merge of #155572 - mejrs:move_target_checks, r=JonathanBrouwer,GuillaumeGomez
Move diagnostic attribute target checks from check_attr

Move diagnostic attribute target checks into their targets. Part of https://github.com/rust-lang/rust/issues/131229#issuecomment-3959910413

This is much easier with `emit_dyn_lint` :) (thanks @GuillaumeGomez !)

I think there might be some opportunity to simplify all these `check_diagnostic_*` methods in `check_attr`. However there are some diagnostic attribute prs in flight and I'd like to wait for those to land first and then think about it. So that PR is not for today.

r? @JonathanBrouwer (or @GuillaumeGomez if you want)
2026-04-21 08:22:17 -04:00
Jacob Pratt 3b4c17915e Rollup merge of #154377 - mu001999-contrib:fix/dead-code, r=TaKO8Ki
Fix `#[expect(dead_code)]` liveness propagation

Fixes https://github.com/rust-lang/rust/issues/154324
Fixes https://github.com/rust-lang/rust/issues/152370 (cc @eggyal)

Previously, when traversing from a `ComesFromAllowExpect::Yes` item (i.e., with `#[allow(dead_code)]` or `#[expect(dead_code)]`), other `ComesFromAllowExpect::Yes` items reached during propagation would be updated to `ComesFromAllowExpect::No` and inserted into `live_symbols`. That caused `dead_code` lint couldn't be emitted correctly.

After this PR, `ComesFromAllowExpect::Yes` items no longer incorrectly update other `ComesFromAllowExpect::Yes` items during propagation or mark them live by mistake, then `dead_code` lint could behave as expected.
2026-04-21 08:22:16 -04:00
mejrs 3990dda860 say "implementation(s) in "not on trait impl" lints 2026-04-21 11:30:14 +02:00
mejrs 80fb0aa44e Move diagnostic::do_not_recommend target checking 2026-04-21 11:30:00 +02:00
mejrs c62be6e992 Move diagnostic::on_unknown target check 2026-04-21 11:30:00 +02:00
mejrs 59503ecb5e Move diagnostic::on_unimplemented target check 2026-04-21 11:30:00 +02:00
mejrs 26d2c30682 Move diagnostic::on_move target check 2026-04-21 11:29:59 +02:00
mejrs 39f517fd18 Move diagnostic::on_const target check 2026-04-21 11:29:41 +02:00
Adwin White 6279106e72 fix all errors 2026-04-20 00:18:28 +08:00
bors 6f109d8a2d Auto merge of #155223 - teor2345:fndef-refactor, r=mati865
Refactor FnDecl and FnSig non-type fields into a new wrapper type





#### Why this Refactor?

This PR is part of an initial cleanup for the [arg splat experiment](https://github.com/rust-lang/rust/issues/153629), but it's a useful refactor by itself.

It refactors the non-type fields of `FnDecl`, `FnSig`, and `FnHeader` into a new packed wrapper types, based on this comment in the `splat` experiment PR:
https://github.com/rust-lang/rust/pull/153697#discussion_r3004637413

It also refactors some common `FnSig` creation settings into their own methods. I did this instead of creating a struct with defaults.

#### Relationship to `splat` Experiment

I don't think we can use functional struct updates (`..default()`) to create `FnDecl` and `FnSig`, because we need the bit-packing for the `splat` experiment.

Bit-packing will avoid breaking "type is small" assertions for commonly used types when `splat` is added.
This PR packs these types:
- ExternAbi: enum + `unwind` variants (38) -> 6 bits
- ImplicitSelfKind: enum variants (5) -> 3 bits
- lifetime_elision_allowed, safety, c_variadic: bool -> 1 bit

#### Minor Changes

Fixes some typos, and applies rustfmt to clippy files that got skipped somehow.
2026-04-18 23:46:37 +00:00
Jonathan Brouwer c5f6afc3e8 Remove target arguments & features from parse_limited 2026-04-18 19:13:30 +02:00
Dominik Schwaiger da2bbfbbec add llvm writable attribute conditionally 2026-04-16 12:29:39 +00:00
teor dafb6bb801 Refactor FnDecl and FnSig flags into packed structs 2026-04-16 07:08:08 +10:00
Edvin Bryntesson 2598b50f92 remove PointeeParser 2026-04-14 20:25:43 +02:00
bors 12f35ad39e Auto merge of #155209 - JonathanBrouwer:attr_cleanup2, r=jdonszelmann
Post-attribute ports cleanup pt. 1 (again)

This is a re-implementation of most (but not all) of https://github.com/rust-lang/rust/pull/154808

The code is the same as in that PR, other than a few changes, I'll leave comments where I changed things.
I did re-implement most of the commits rather than cherry-picking, so it's probably good to check the entire diff regardless

r? @jdonszelmann
2026-04-14 08:59:40 +00:00
Jonathan Brouwer 034de09cb3 Remove AttributeType from BUILTIN_ATTRIBUTES 2026-04-13 20:51:29 +02:00
Jonathan Brouwer da8cf97e64 Remove AttributeDuplicates from BUILTIN_ATTRIBUTES 2026-04-13 20:51:24 +02:00