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.
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.
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.
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.
Fixesrust-lang/rust#160403
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.
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
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
Fix avoid cycle for self referential return type notation
Fixesrust-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
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
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
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
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
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`).
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.
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.
Fix opaque type ICE in late lints under the next-generation trait solver
fixesrust-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
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
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
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`.
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.