Commit Graph

3583 Commits

Author SHA1 Message Date
Chris Denton
4641990929 Remove ensure_sufficient_stack 2026-08-09 19:58:29 +00:00
mejrs
196dd2a174 Fix up lang_items import paths 2026-08-09 15:20:29 +02:00
Jonathan Brouwer
487d6a616c Rollup merge of #160755 - JonathanBrouwer:rustc_lint_diags, r=GuillaumeGomez
Merge `rustc_lint/lints.rs` into `diagnostics.rs`

Renaming diagnostics files to all be diagnostics.rs, per the decision in https://github.com/rust-lang/compiler-team/issues/1003

r? @GuillaumeGomez
2026-08-08 22:16:48 +02:00
Jonathan Brouwer
73d2955bd4 Rollup merge of #160753 - mejrs:remove_rustc_attrs, r=JonathanBrouwer
rustc_lint: remove unused rustc_attrs feature
2026-08-08 16:32:51 +02:00
Jonathan Brouwer
cba529b5fb Rollup merge of #160704 - folkertdev:sort-lint-names, r=JonathanBrouwer
sort lint names in lint pass declarations

When adding a new lint, you'd naturally add the new lint at the bottom, and would have to deal with merge conflicts with all other PRs that also add a lint. Sorting the list should at least mitigate that, and is probably more readable overall.
2026-08-08 16:32:46 +02:00
Jonathan Brouwer
92c6357cae Merge rustc_lint/lints.rs into diagnostics.rs 2026-08-08 15:07:46 +02:00
mejrs
ad476e5455 rustc_lint: remove unused rustc_attrs feature 2026-08-08 14:51:30 +02:00
Folkert de Vries
23442b92c4 sort lint names
When adding a new lint, you'd naturally add the new lint at the bottom, and would have to deal with merge conflicts with all other PRs that also add a lint.
2026-08-07 17:56:19 +02:00
Chayim Refael Friedman
5491ec85e2 Instead of representing trait errors as Vec<Error>, use a special type
This has multiple advantages:

 - Performance. The new type is 1/3 the size of `Vec` (being equivalent in layout to `Option<ThinVec>`) and can be kept in a register.
 - Type safety. We mark the type `#[must_use]`, and thinks requiring errors take `ThinVec`, which requires unwrapping the type and verifying there is indeed an error. We still provide conversions to slices, `ThinVec`, and iteration, because some code needs this and I saw no benefit in changing it, but we deliberately do not provide `Deref<Target = [E]>` or things like that.
2026-08-06 07:18:55 +03:00
Jonathan Brouwer
872bc2ca5e Rollup merge of #154585 - HerrCai0907:fix/no_mangle_generic_items, r=oli-obk
treat no_mangle_generic_items as hard error instead of lint warning

Reference PR:

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

In https://github.com/rust-lang/miri/pull/4929#issuecomment-4150832692, rustc should reject the no_mangled generic function.
This PR treat is as a hard error
2026-08-05 21:55:44 +02:00
Cai Congcong
623d78a6d0 set no_mangle_generic_items deny by default 2026-08-05 13:39:16 +02:00
Jonathan Brouwer
7afe2e112c Rollup merge of #160420 - YingqiDuan:fix-160403-cast-signed-suggestion, r=mu001999
Suggest `cast_signed()` for overflowing signed integer literals

This PR uses `cast_signed()` for same-width conversions and keeps `as` for different-width conversions.

It also updates the affected UI test snapshots.

Fixes rust-lang/rust#160403
2026-08-05 13:36:15 +02:00
Ada Alakbarova
c99698344d rename OutlivesPredicate to OutlivesClause 2026-08-05 11:07:35 +02:00
YingqiDuan
eace512093 Suggest cast_signed for overflowing integer literals
Co-authored-by: Roland Xu <rcu@live.com>
2026-08-05 05:31:06 +00:00
Jacob Pratt
00b2bc4a7a Rollup merge of #157928 - Jarcho:eager_typeck, r=adwinwhite
Eagerly fetch typeck results when linting

The first commit avoids running the lint visitor if all lints were filtered out. In every other case the typeck results are accessed on every body making the delayed load pointless overhead.
2026-07-31 22:25:15 -04:00
Jason Newcomb
102b6fdae9 Remove maybe_typeck_results from LateContext. 2026-07-31 11:15:43 -04:00
Jason Newcomb
0a32236c7b Preemptively fetch the typeck results when linting bodies. 2026-07-31 11:15:43 -04:00
Jonathan Brouwer
c70f022125 Rollup merge of #160159 - Urgau:invalid_ref_casts-unsafe-cell, r=mejrs
More accurately check for interior mutability in `invalid_reference_casting` lint

This PR replaces the `Freeze` trait check in the `invalid_reference_casting` lint by a recursive type check.

The check was not enough to determine if a type has "interior mutability", as `Freeze` is proxy for "has *some* interior mutability", not "fully covered by interior mutability".

As requested in https://github.com/rust-lang/rust/pull/159960#issuecomment-5090709661
2026-07-31 16:02:36 +02:00
Jonathan Brouwer
1488342e5f Rollup merge of #160220 - Jamesbarford:chore/shrink-region-ext-triats, r=lcnr
Refactor: shrink region ext traits

- Removes `RegionUtilitiesExt`.
- Ports, where trivially simple, methods from the extension traits to `rustc_type_ir`.
- Cleans up imported crates where possible.

It seems `EarlyParamRegion` could possibly move to `rust_type_ir`?

r? @lcnr
2026-07-31 16:02:22 +02:00
Urgau
0c2035c605 Add recursive check for UnsafeCell-ness in invalid ref casting lint 2026-07-31 11:01:55 +02:00
James Barford-Evans
543a403a51 Clean up crate imports 2026-07-31 08:35:13 +01:00
Jonathan Brouwer
8384a31552 Rollup merge of #159958 - amirHdev:fix-rtn-cycle, r=oli-obk
Fix avoid cycle for self referential return type notation

Fixes rust-lang/rust#159892 and rust-lang/rust#133613
we had to preserve and restore shadowed parameters in the impl trait overcapture lint and convert the resolved crash regression into a normal UI test which is applied to this patch
2026-07-31 00:06:34 +02:00
Jonathan Brouwer
c02d4ce21f Rollup merge of #138230 - obeis:lint-unnecessary-reference, r=Urgau
Add `raw_borrows_via_references` lint

Close rust-lang/rust#127724
2026-07-31 00:06:28 +02:00
Amirhossein Akhlaghpour
af646403f5 avoid cycle for self referential return type notation 2026-07-30 16:04:24 +00:00
Jacob Pratt
cc89039c4a Rollup merge of #158615 - Albab-Hasan:fix-explicit-outlives-unsized, r=fmease
fix: don't fire `explicit_outlives_requirements` on `?Sized` type params

`explicit_outlives_requirements` uses `tcx.inferred_outlives_of()` to check whether an explicit `T: 'a` bound is structurally implied by struct fields. for a field `r: &'a T`, it is — so the lint fired and suggested removing it.

but RFC 599 object lifetime defaults are computed from *explicit* HIR bounds not inferred ones. removing an explicit `T: 'a` from a `?Sized` type param silently changes every `Struct<dyn Trait>` use from `dyn Trait + 'a` to `dyn Trait + 'static`, breaking callers without any error.

added a guard: before emitting the lint for a type param outlives bound, check whether the param carries any `?Sized` bound (`BoundPolarity::Maybe` in HIR). if so, skip — the bound may be the sole anchor for the object lifetime default.

also suppresses the pre-existing false positive in `edition-lint-infer-outlives.rs` (noted in issue https://github.com/rust-lang/rust/issues/105150) which was an instance of the same bug.

closes https://github.com/rust-lang/rust/issues/134902
2026-07-28 20:09:38 -04:00
Jonathan Brouwer
bca856424e Rollup merge of #158038 - nbdd0121:register_tool, r=mejrs
Split register_tool into register_attribute_tool and register_lint_tool

Tracking issue: rust-lang/rust#66079

This implements the attribute parsing part of RFC 3808. The resolution part is yet to be implemented.

cc @jyn514
2026-07-28 21:07:45 +02:00
Jonathan Brouwer
0a1a25a0b6 Rollup merge of #159990 - nnethercote:predicate-to-clause, r=oli-obk
Many "predicate"-to-"clause" renamings

Lots of names weren't changed to account for the introduction of the `Clause` type as a specialized form of `Predicate`, presumably because it was tedious. This commit converts as many of them as I could find. It's mostly very tedious renamings of types, functions, variables, and queries. The more interesting ones are a couple of files (`predicates_of.rs`, `impossible_predicates.rs`) and a MIR pass (`ImpossiblePredicates`).

r? @oli-obk
2026-07-28 21:07:39 +02:00
Jacob Pratt
6da5b2fcca Rollup merge of #160022 - mejrs:hir_too_globby, r=folkertdev
Refactor rustc_hir re-exports

Probably best reviewed commit by commit.

I've been trying to split up rustc_hir and attributes.. This PR prepares for part of that, by cleaning up import paths and moving around some stuff. (See also https://github.com/rust-lang/rust/pull/159602 https://github.com/rust-lang/rust/pull/159659 and https://github.com/rust-lang/rust/pull/159893 for some previous work)
2026-07-28 01:38:36 -04:00
Jacob Pratt
1b03eec78c Rollup merge of #159960 - Urgau:invalid_ref-safe-interior-mut, r=mejrs
Allow `UnsafeCell` content access without `get` in `invalid_reference_casting` lint

https://github.com/rust-lang/rust/pull/159730 relaxed the rules so that it's no longer necessary to use `UnsafeCell::raw_get` or `UnsafeCell::get` to access the content of an unsafe cell.

As a consequence this means that code this like is no longer invalid:
```rust
use std::cell::UnsafeCell;

unsafe fn get_mut_unchecked<T>(ptr: &UnsafeCell<T>) -> &mut T {
    let t = ptr as *const UnsafeCell<T> as *mut T;
    unsafe { &mut *t }
}
```

Fixes https://github.com/rust-lang/rust/issues/159915
cc @RalfJung
2026-07-28 01:38:30 -04:00
Nicholas Nethercote
ff161b18b5 Many "predicate"-to-"clause" renamings
Lots of names weren't changed to account for the introduction of the
`Clause` type as a specialized form of `Predicate`, presumably because
it was tedious. This commit converts as many of them as I could find.
It's mostly very tedious renamings of types, functions, variables, and
queries. The more interesting ones are a couple of files
(`predicates_of.rs`, `impossible_predicates.rs`) and a MIR pass
(`ImpossiblePredicates`).
2026-07-28 11:48:45 +10:00
Urgau
6b0ea30679 Allow UnsafeCell content access without get in invalid ref casting lint 2026-07-27 21:22:58 +02:00
Gary Guo
75999c498f Split register_tool into register_attribute_tool and register_lint_tool
This splits the functionality to two parts per RFC. The `#![register_tool]`
attribute registers the tool in both ways.

Semantics remain unchanged and will be adjusted in later commit.
2026-07-27 19:06:33 +01:00
mejrs
3301eeabb4 Move canonical symbols into attributes 2026-07-27 19:17:55 +02:00
Gary Guo
747ce1a484 Make AttributeParser::parse_limited accept filters instead of symbol
The existing API is preserved as `parse_limited_sym` as a simple helper.

Similarly, `parse_limited_should_emit` is preserved as
`parse_limited_sym_should_emit`. I've noted that all users targets crate,
so the `target_node_id` and `target` parameters are removed from it.
2026-07-27 17:42:20 +01:00
Jonathan Brouwer
0b2da47987 Rollup merge of #159840 - Gri-ffin:lint-post-borrowck-typing-mode, r=adwinwhite
Fix opaque type ICE in late lints under the next-generation trait solver

fixes rust-lang/rust-clippy#17411

Under the next trait solver, late lints trigger an ICE due to having non-empty opaque storage when dropping `InferCtxt`.

Rather than forcing all current and future late lints to manually use `ignoring_regions`, use `PostBorrowck` in `LateContext`.

cc @adwinwhite
2026-07-27 11:58:11 +02:00
albab-hasan
1d08359d33 don't fire explicit_outlives_requirements on unsized type params
When a type param `T` is not `Sized` (i.e. `is_sized` returns false),
removing an explicit `T: 'r` bound can silently change trait object
lifetime defaults per RFC 599 — `Struct<dyn Trait>` would shift from
`dyn Trait + 'r` to `dyn Trait + 'static`. Suppress the lint in that
case using `Ty::new_param(...).is_sized(tcx, typing_env)`.

Fixes https://github.com/rust-lang/rust/issues/134902
2026-07-27 06:48:55 +06:00
Jonathan Brouwer
6445bf7a74 Rollup merge of #159902 - Urgau:runtime-symbols-for-current-target, r=GuillaumeGomez
Clarify that the expected runtime symbols signature is for the current target only

Some of the signatures expected by our runtime symbols are slightly different from one target to the other one (`i8` vs `u8`), and while the original definition uses type alias, they are not recorded and displayed in the diagnostic.

So, to avoid any ambiguity let's add a small note that the displayed signature is only for the current target.

r? @GuillaumeGomez
2026-07-26 15:47:25 +02:00
Jacob Pratt
b1970509eb Rollup merge of #159179 - hkBst:patch-7, r=davidtwco
enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group

This enables the `unreachable_cfg_select_predicates` lint as part of the `unused` lint group. This was apparently planned to be enabled as part of `cfg_select` stabilization, but got overlooked (as can be seen from comments below).

This lint was merged in https://github.com/rust-lang/rust/pull/149960 which also includes a test for the behavior in `tests/ui/macros/cfg_select.rs`.
2026-07-26 00:21:42 -04:00
Urgau
c49a172c8d Note that the expected runtime signature is for the current target only 2026-07-25 15:41:26 +02:00
Gri-ffin
b2c8b50b1d use PostBorrowck typing mode in LateContext 2026-07-24 14:17:08 +01:00
Urgau
970a68982d Consider () as suspicious only when expecting ! for runtime symbols 2026-07-22 23:43:44 +02:00
khyperia
e895ed8c90 unify the AST repr of type const and const RHS 2026-07-22 09:22:45 +02:00
Jacob Pratt
ae89c41a79 Rollup merge of #159527 - Urgau:runtime-symbols-static-cleanup, r=GuillaumeGomez
Bring runtime symbols statics on par with foreign functions

This PR cleanups the `static` items path when checking the runtime symbols, and brings it on par with the foreign functions check.

It also fixes a bug where static only reported the invalid lint and never the suspicious lint.

Best reviewed commit by commit.
2026-07-21 20:59:25 -04:00
James Barford-Evans
80d18b365d Import extension traits and region 2026-07-21 12:05:14 +01:00
Urgau
778a9dfcc9 Check only foreign statics with #[linkage = "..."] 2026-07-20 22:45:23 +02:00
Urgau
f50b20da76 Merge checking for static and foreign functions 2026-07-20 22:45:23 +02:00
Urgau
7c5c34fafb Remove the static items specific diagnostic for runtime symbols lints 2026-07-20 22:45:23 +02:00
Urgau
002c50aec5 Bring runtime symbols statics on par with foreign functions 2026-07-20 22:45:23 +02:00
Obei Sideg
8b40773296 Add raw_borrows_via_references lint
Signed-off-by: Obei Sideg <obei.sideg@gmail.com>
2026-07-20 20:18:57 +03:00
Urgau
4cc1a3c836 Use #[rustc_canonical_symbol] instead of lang-items 2026-07-19 17:38:56 +02:00