Commit Graph

3420 Commits

Author SHA1 Message Date
Hanna Kruppe f8f740baf0 convert lossy_provenance_casts to late lint 2026-05-25 13:57:41 +02:00
Hanna Kruppe 4539a75716 convert fuzzy_provenance_casts to late lint 2026-05-25 13:57:41 +02:00
Jacob Pratt 794b44de55 Rollup merge of #156843 - onehr:fix-redundant-captures-143216, r=cjgillot
Make impl_trait_redundant_captures suggestion remove adjacent +

Closes rust-lang/rust#143216

The `impl_trait_redundant_captures` lint's machine-applicable suggestion only
spanned the `use<...>` syntax itself, leaving the adjacent `+` joiner behind.
Applying the suggestion produced uncompilable code, e.g.
`impl Sized + use<>` becoming `impl Sized + ` (stray trailing `+`).

This extends the removal span to also cover one adjacent `+`, preserving
valid syntax in the three bound-list positions covered by the regression test:

- `impl Sized + use<>` becomes `impl Sized`
- `impl use<> + Sized` becomes `impl Sized`
- `impl Sized + use<> + Send` becomes `impl Sized + Send`

A `//@ run-rustfix` UI test exercises all three positions, so the
rustfix-applied output is actually compiled — covering the gap the
existing `redundant.rs` test left (which only checks lint firing, not
suggestion correctness).

Tested:
- ./x test tests/ui/impl-trait/precise-capturing/redundant-machine-applicable.rs --bless
- ./x test tidy
2026-05-24 16:39:43 +02:00
Haoran Wang b6eb265902 Keep redundant-capture suggestions syntactically valid
The lint suggestion now removes the `+` joiner adjacent to a redundant
`use<...>` clause, so applying the suggestion does not leave a dangling
`+` that fails to parse.

The existing `tests/ui/impl-trait/precise-capturing/redundant.stderr`
baseline emits the same diagnostic with the expanded suggestion span and
is blessed along with the new `run-rustfix` test.

Tested:
- ./x test tests/ui/impl-trait/precise-capturing/redundant.rs --force-rerun
- ./x test tests/ui/impl-trait/precise-capturing/redundant-machine-applicable.rs --force-rerun
- ./x test tidy
2026-05-23 19:14:47 +08:00
Edvin Bryntesson 4f12864fab make lint_index field not Optional in LintExpectationId 2026-05-22 15:21:07 +02:00
Jonathan Brouwer 8162cf582b Rollup merge of #156242 - Jamesbarford:feat/remove-alwaysinline+target-feature, r=RalfJung,saethlin
Remove unsound `target_feature_inline_always` feature

## Summary
- Remove `target_feature_inline_always`
- Update stdarch generators to only use `#[inline]` & regenerate stdarch.

## Why?
Succinctly; the feature relies on LLVMs `AlwaysInlinerPass()` running before LLVMs heuristic based inliner pass. Which is not a basis for sound code.

This has been discussed in [the tracking issue](https://github.com/rust-lang/rust/issues/145574).

If the ordering of the passes were to change, of which they have in the past, it is very possible we could inline functions across callsites with mismatching target features leading to unsound code. Checks proposed in; https://github.com/rust-lang/rust/pull/155426 would only take into account caller -> callee which is not enough to guard against possibly of generating unsound code if the pass ordering were to change.

There doesn't seem to be a way, presently, this this mechanism to provide soundness guarantees nor does it seem like `AlwaysInlinerPass()` is a desired feature of LLVM, which this feature relies on.

r? @RalfJung
2026-05-21 12:21:45 +02:00
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
Yuki Okushi ee8949e513 Add FIXME for interior_mutability_suggestion 2026-05-17 15:03:24 +09:00
Yuki Okushi cbaee5df1b Tweak note condition 2026-05-17 14:09:51 +09:00
Yuki Okushi 2071c66f19 Add interior-mutability suggestion to static_mut_refs 2026-05-17 14:09:51 +09:00
bors 281c97c324 Auto merge of #156518 - estebank:match-rustfmt, r=mejrs
[style] rustfmt `match`es with comments in or-patterns

Using https://github.com/rust-lang/rustfmt/pull/6893, I reformatted the whole codebase. The result is that `match`es that *should have* been formatted under normal circumstances but are getting skipped now got their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.

(Introduced and) removed a bunch of stray backticks \` likely left after an editor autoclosed the intended closing \`, resulting in <code>\`name\`\`</code> in comments.
2026-05-17 01:27:37 +00:00
Nicholas Nethercote 36738a1f0e Remove some low-value method wrappers
I find these make the code harder to understand.
2026-05-16 21:20:02 +10: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
Nicholas Nethercote 40332688e0 Remove an unnecessary push argument
It's always `None`.
2026-05-15 17:57:58 +10:00
Nicholas Nethercote 19c6365110 Inline and remove late_lint_crate_inner
It has a single call site.
2026-05-15 17:56:27 +10:00
James Barford-Evans 812e230fb9 PR Feedback - grammatical changes, clear reason for removal and move register_removed(...) call 2026-05-14 11:11:55 +01: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 f439907325 Streamline Level::from_{attr,symbol}
These methods return `Option<(Self, Option<LintExpectationId>)>`. But
all the call sites except one don't look at the
`Option<LintExpectationId>`.

This commit simplifies these methods to not return the
`Option<LintExpectationId>`. This means they no longer need to be passed
a closure to compute an `AttrId` (which is usually discarded anyway).
The commit also renames `from_attr` as `from_opt_symbol`, because it
takes an `Option<Symbol>`, not an `Attribute`.

These changes simplify all the call sites that don't need the
`Option<LintExpectationId>`, and also the one call site that does (in
`LintLevelsBuilder::add`): that call site no longer needs to do an
awkward destructuring, and can instead build the appropriate
`LintExpectationId` directly.
2026-05-14 16:28:50 +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
Jonathan Brouwer 68e98f0d40 Rollup merge of #156536 - nnethercote:reveal_actual_level-improvements, r=GuillaumeGomez
`reveal_actual_level` improvements

Details in individual commits.

r? @GuillaumeGomez
2026-05-13 15:16:19 +02:00
Nicholas Nethercote b86ef89082 Change reveal_actual_level's closure's return type, again
Again, the returned triple is equivalent to `LevelAndSource`.
2026-05-13 19:54:30 +10:00
Nicholas Nethercote 7cd42a77fb Change reveal_actual_level's closure's return type
It's currrently `(Option<(Level, Option<LintExpectationId>)>,
LintLevelSource)`. But when the first element of the pair is `None` the
second element is always `LintLevelSource::Default`. So this commit
moves the `LintLevelSource` within the `Option`, which simplifies
things a bit.
2026-05-13 19:54:30 +10:00
Nicholas Nethercote 202e86102c Change reveal_actual_level return type
It currently returns a triple: `(Level, Option<LintExpectationId>,
LintLevelSource)`. That's structurally identical to `LevelAndSource`, so
this commit changes it accordingly.
2026-05-13 19:54:30 +10:00
Nicholas Nethercote 9de0b2dd65 Improve reveal_actual_level
`reveal_actual_level` has two call sites, which look like this:
```
let (level, mut src) = self.raw_lint_id_level(lint, idx, aux);
let (level, lint_id) = reveal_actual_level(level, &mut src, sess, lint, |id| {
    self.raw_lint_id_level(id, idx, aux)
});
```
and:
```
let (level, mut src) = self.probe_for_lint_level(tcx, lint, cur);
let (level, lint_id) = reveal_actual_level(level, &mut src, tcx.sess, lint, |lint| {
    self.probe_for_lint_level(tcx, lint, cur)
});
```
They both have the same pattern: there's a prior call expression that is then
repeated within a closure passed to `reveal_actual_level`.

This commit moves that prior call inside `reveal_actual_level`, making things
simpler.
2026-05-13 19:54:28 +10:00
Esteban Küber 31e0383ea6 rustfmt matches with comments in or-patterns
Using https://github.com/rust-lang/rustfmt/pull/6893, reformat the codebase. The result is that matches that *would have* been formatted under normal circumstances get their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.
2026-05-13 02:35:29 +00:00
bors c8c4c83d57 Auto merge of #156224 - khyperia:unnormalized-migration, r=BoxyUwU
Unnormalized migration: assert_fully_normalized, struct_tail, and `field.ty`



tracking issue: https://github.com/rust-lang/rust/issues/155345 (first checkbox, and partial second checkbox, of that issue)

I'm going a bit slower than expected (less free time than I'd hope, lots of GCA work that I'm doing instead), and figured I'd just submit what I have now rather than building up a big batch of changes. Slow and steady!

r? @lcnr
2026-05-13 00:16:00 +00:00
lcnr 3fb166fb6f tiny PR 2026-05-12 21:58:50 +02:00
cyrgani 3e557c88cf use deref_patterns in rustc_lint 2026-05-10 21:05:36 +00:00
bors ce89c89857 Auto merge of #148214 - WaffleLapkin:never-worn-never-type, r=fee1-dead
Consider `Result<T, Uninhabited>` and `ControlFlow<Uninhabited, T>` to be equivalent to `T` for must use lint





This is an extension to rust-lang/rust#147382.

With this PR `Result<T, Uninhabited>` and `ControlFlow<Uninhabited, T>` considered as must use iif `T` must be used.

For such cases the lint will mention that `T` is wrapped in a `Result`/`ControlFlow` with an uninhabited error/break.

The reasoning here is that `Result<T, Uninhabited>` is equivalent to `T` in which values can be represented and thus the must-used-ness should also be equivalent.

Fixes https://github.com/rust-lang/rust/issues/65861
2026-05-09 22:49:40 +00:00
Jacob Pratt 80263e17a3 Rollup merge of #156235 - rajgandhi1:compiler_stack_overflow_fix, r=adwinwhite
fix: Guard SizeSkeleton::compute against stack overflow

Fixes rust-lang/rust#156137

Fix: extract the recursion into a private `compute_inner` that carries a depth counter. When depth exceeds the crate's recursion limit, return `LayoutError::Unknown` and let the existing transmute size-check produce a normal error instead of crashing.

A regression test is included in `tests/ui/transmute/`.
2026-05-09 09:27:58 -04:00
rajgandhi1 7a900df1b9 Guard SizeSkeleton::compute against stack overflow 2026-05-09 16:02:15 +05:30
Jana Dönszelmann 0aefbd13c3 use the right typing mode in lints 2026-05-08 14:07:46 +02:00
Aapo Alasuutari 2d88ee87dd Reborrow traits 2026-05-07 21:55:44 +03:00
Jonathan Brouwer 5344306548 Rollup merge of #146273 - niacdoial:improperctypes-refactor2, r=petrochenkov
lint ImproperCTypes: refactor linting architecture (part 2)

This is the second PR in an effort to split https://github.com/rust-lang/rust/pull/134697 (refactor plus overhaul of the ImproperCTypes family of lints) into individually-mergeable parts.

Contains the changes of the first PR, and splits the core type checking function into several bits, each focused on a specific aspect of FFI-safety.
Some logic which was outside of said core function was also moved into the new functions.

Superset of: rust-lang/rust#146271
2026-05-07 14:13:49 +02:00
James Barford-Evans c6d2da90b5 Remove #[inline(always)] + #[target_feature(enable = "<feature>")] support, reinstating error message and providing a link to the tracking issue for the full rationale. 2026-05-07 08:28:09 +01:00
niacdoial 6839797f18 ImproperCTypes: Use more Unnormalized type wrappers
In order to follow along with the efforts to properly distinguish
already-normalised and unnormalized types, we separate the internal
interfaces of this lint that rely on normalized types from those that
do not. We do that by adding the `Unnormalized` wrapper to some
interfaces.
2026-05-05 23:59:30 +02:00
niacdoial 411a932b38 ImproperCTypes: merge outer_ty information into VisitorState
Another user-transparent change, unifying outer-type information and the
existing VisitorState flags.
2026-05-05 23:59:30 +02:00
mejrs 4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
Jacob Pratt 894bdf298e Rollup merge of #155980 - nnethercote:mv-feature-methods, r=TaKO8Ki
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.

r? @TaKO8Ki
2026-04-30 22:28:33 -04:00
Nicholas Nethercote 339797e8b6 Eliminate rustc_lint_defs' dependency on rustc_ast.
It currently only depends on two things:
- `rustc_ast::AttrId`: this is just a re-export of `rustc_span::AttrId`,
  so we can import the original instead.
- `rustc_ast::AttributeExt`: needed only for the `name` and `id`
  methods. We can instead pass in the `name` and `id` directly.
2026-05-01 10:58:42 +10: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
bors b20956b0f4 Auto merge of #155890 - JonathanBrouwer:rollup-XcHVBe9, r=JonathanBrouwer
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#154510 (Partially stabilize LoongArch target features)
 - rust-lang/rust#155137 (Allow trailing `self` in more contexts)
 - rust-lang/rust#155513 (rustc_public: implement `Pattern` type)
 - rust-lang/rust#155702 (Change `ItemKind::Trait` to a field variant.)
 - rust-lang/rust#154896 (Fix ICE: Scalar layout for non-primitive non-enum type unsafe binder)
 - rust-lang/rust#155675 (Disallow non_exhaustive structs and enums with non_exhaustive variants from implementing `ConstParamTy`)
 - rust-lang/rust#155874 (Avoid misleading closure return type note)
 - rust-lang/rust#155876 (CI: rfl: move job forward to Linux v7.1-rc1)
2026-04-27 21:47:07 +00: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
bors 52b6e2c208 Auto merge of #155760 - GuillaumeGomez:rm-attributelintkind, r=JonathanBrouwer,petrochenkov
Remove `AttributeLintKind`



Part of https://github.com/rust-lang/rust/issues/153099.

The `AttributeLintKind` type is finally gone! \o/

Diff is this big because I moved a file and a lot of `Diagnostic` types. :')

r? @JonathanBrouwer
2026-04-27 17:49:21 +00:00
Guillaume Gomez faecc47eab Update triagebot.toml file to take into account the moved file
Create a new `SharedContext::emit_dyn_lint_with_sess` method to simplify code when `Session` is not needed
Remove crate name from `UnexpectedCfgCargoMacroHelp`
2026-04-27 17:57:55 +02:00
Jonathan Brouwer 76a365523f Rollup merge of #154803 - chenyukang:yukang-fix-154801-cfg-attr-span, r=JonathanBrouwer
Fix ICE from cfg_attr_trace

Fixes rust-lang/rust#154801
Fixes https://github.com/rust-lang/rust/issues/143094

r? @JonathanBrouwer

The root cause is we recovery from parsing attribute error here:
https://github.com/rust-lang/rust/blob/ed6f9af7d47f5a5eda2a4a1925d1e250b51a37f2/compiler/rustc_attr_parsing/src/parser.rs#L550
while the later suggestion code from type checking try to inspect the attr span of the `expr` in the second error, keep the span seems reasonable.
2026-04-25 23:07:49 +02:00
yukang 45b4e3c52b Fix ICE of trying to get span from all attrs 2026-04-25 11:11:23 +08:00
Guillaume Gomez e7b9d94435 Remove unused diagnostic types 2026-04-25 04:20:04 +02:00
Guillaume Gomez b80d0b8894 Remove remaining AttributeLintKind variants 2026-04-25 04:13:16 +02:00
mejrs 9515f52d61 Change ItemKind::Trait to have named fields. 2026-04-24 19:03:16 +02:00