Commit graph

2712 commits

Author SHA1 Message Date
Oli Scherer
9f5473f7ad Avoid passing around an Expr that is only needed for its HirId and its Span 2025-02-05 11:25:44 +00:00
许杰友 Jieyou Xu (Joe)
def44600d1
Rollup merge of #135964 - ehuss:cenum_impl_drop_cast, r=Nadrieril
Make cenum_impl_drop_cast a hard error

This changes the `cenum_impl_drop_cast` lint to be a hard error. This lint has been deny-by-default and warning in dependencies since https://github.com/rust-lang/rust/pull/97652 about 2.5 years ago.

Closes https://github.com/rust-lang/rust/issues/73333
2025-02-05 19:09:33 +08:00
Matthias Krüger
40c4e05013
Rollup merge of #136242 - samueltardieu:remove-match-def-path, r=flip1995
Remove `LateContext::match_def_path()`

This function was only kept for Clippy use. The last use in Clippy was removed in c9315bc395.
2025-02-04 18:49:35 +01:00
Matthias Krüger
5bc5827636
Rollup merge of #136422 - nnethercote:convert-lint-functions, r=Noratrieb
Convert two `rustc_middle::lint` functions to `Span` methods.

`rustc_middle` is a huge crate and it's always good to move stuff out of it. There are lots of similar methods already on `Span`, so these two functions, `in_external_macro` and `is_from_async_await`, fit right in. The diff is big because `in_external_macro` is used a lot by clippy lints.

r? ``@Noratrieb``
2025-02-02 18:05:24 +01:00
Nicholas Nethercote
06090e89d3 Convert two rustc_middle::lint functions to Span methods.
`rustc_middle` is a huge crate and it's always good to move stuff out of
it. There are lots of similar methods already on `Span`, so these two
functions, `in_external_macro` and `is_from_async_await`, fit right in.
The diff is big because `in_external_macro` is used a lot by clippy
lints.
2025-02-02 13:57:34 +11:00
Zalathar
24cdaa146a Rename tcx.ensure() to tcx.ensure_ok() 2025-02-01 12:38:54 +11:00
Matthias Krüger
308ea7120b
Rollup merge of #135860 - fmease:compiler-mv-obj-save-dyn-compat-ii, r=jieyouxu
Compiler: Finalize dyn compatibility renaming

Update the Reference link to use the new URL fragment from https://github.com/rust-lang/reference/pull/1666 (this change has finally hit stable). Fixes a FIXME.

Follow-up to #130826.
Part of #130852.

~~Blocking it on #133372.~~ (merged)

r? ghost
2025-01-31 12:28:15 +01:00
bors
5a45ab9738 Auto merge of #136038 - compiler-errors:outlives, r=lcnr
Simplify and consolidate the way we handle construct `OutlivesEnvironment` for lexical region resolution

This is best reviewed commit-by-commit. I tried to consolidate the API for lexical region resolution *first*, then change the API when it was finally behind a single surface.

r? lcnr or reassign
2025-01-30 11:40:32 +00:00
Oli Scherer
f47ad71059 Eliminate PatKind::Path 2025-01-29 15:45:13 +00:00
Samuel Tardieu
0bb3d5209e Remove LateContext::match_def_path()
This function was only kept for Clippy use. The last use in Clippy was
removed in c9315bc395.
2025-01-29 12:31:20 +01:00
León Orell Valerian Liehr
28393070ab
Rollup merge of #136164 - celinval:chores-fnkind, r=oli-obk
Refactor FnKind variant to hold &Fn

Pulling the change suggested in #128045 to reduce the impact of changing `Fn` item.

r? `@oli-obk`
2025-01-29 03:12:22 +01:00
Celina G. Val
c22a27130d Refactor FnKind variant to hold &Fn 2025-01-28 11:22:25 -08:00
Michael Goulet
009d68740f Make item self/non-self bound naming less whack 2025-01-28 19:08:50 +00:00
Michael Goulet
48b7e38c06 Move outlives env computation into methods 2025-01-28 18:55:03 +00:00
Michael Goulet
2b8930c71c Consolidate OutlivesEnv construction with resolve_regions 2025-01-28 18:55:03 +00:00
Guillaume Gomez
03fdcffa1e
Rollup merge of #136114 - compiler-errors:more-idents, r=jieyouxu
Use identifiers more in diagnostics code

This should make the diagnostics code slightly more correct when rendering idents in mixed crate edition situations. Kinda a no-op, but a cleanup regardless.

r? oli-obk or reassign
2025-01-27 15:38:30 +01:00
Michael Goulet
c08624d8d2 Remove redundant to_ident_string calls 2025-01-27 01:23:34 +00:00
Michael Goulet
ac1c6c50f4 Use identifiers in diagnostics more often 2025-01-27 01:23:34 +00:00
León Orell Valerian Liehr
57b5d3af62
Compiler: Finalize dyn compatibility renaming 2025-01-26 21:20:31 +01:00
Kalle Wachsmuth
c1dcbebd0b
implement lint double_negations 2025-01-26 12:18:33 +01:00
Kalle Wachsmuth
d810d426a4
unrelated cleanup 2025-01-26 12:15:11 +01:00
Jacob Pratt
dc202df0ed
Rollup merge of #133951 - bjorn3:wasm_c_abi_lint_hard_error, r=workingjubilee
Make the wasm_c_abi future compat warning a hard error

This is the next step in getting rid of the broken C abi for wasm32-unknown-unknown.

The lint was made deny-by-default in https://github.com/rust-lang/rust/pull/129534 3 months ago. This still keeps the `-Zwasm-c-abi` flag set to `legacy` by default. It will be flipped in a future PR.

cc https://github.com/rust-lang/rust/issues/122532
2025-01-25 23:26:58 -05:00
Matthias Krüger
dbe911a64d
Rollup merge of #136016 - Urgau:check-cfg-allow-test-improv, r=jieyouxu
Improve check-cfg expected names diagnostic

This PR improves the check-cfg `allow-same-level` test by ~~normalizing it's output and by~~ adding more context to the test.

It also filters the well known cfgs from the `expected names are` note, as to reduce the size of the diagnostic. Users can still find the full list on the [rustc book](https://doc.rust-lang.org/nightly/rustc/check-cfg.html#well-known-names-and-values), which is reinforced for Cargo users by adding a note in the Cargo check-cfg specific section.

Fixes https://github.com/rust-lang/rust/issues/135995
r? `@jieyouxu`
2025-01-25 23:15:25 +01:00
Matthias Krüger
f01d418139
Rollup merge of #134300 - RalfJung:remove-dead-attrs, r=chenyukang
remove long-deprecated no-op attributes no_start and crate_id

These have emitted a deprecation warning since forever (https://github.com/rust-lang/rust/pull/64471) and they already don't do anything. In fact they [apparently](https://github.com/rust-lang/rust/pull/64471#issuecomment-531517332) have done nothing since pre-1.0, so... do we even need a crater run? Doesn't seem worth it.
2025-01-25 23:15:22 +01:00
Urgau
c5ea75a5df Filter well known names from check-cfg diagnostics 2025-01-25 12:27:33 +01:00
bors
8231e8599e Auto merge of #135272 - BoxyUwU:generic_arg_infer_reliability_2, r=compiler-errors
Forbid usage of `hir` `Infer` const/ty variants in ambiguous contexts

The feature `generic_arg_infer` allows providing `_` as an argument to const generics in order to infer them. This introduces a syntactic ambiguity as to whether generic arguments are type or const arguments. In order to get around this we introduced a fourth `GenericArg` variant, `Infer` used to represent `_` as an argument to generic parameters when we don't know if its a type or a const argument.

This made hir visitors that care about `TyKind::Infer` or `ConstArgKind::Infer` very error prone as checking for `TyKind::Infer`s in  `visit_ty` would find *some* type infer arguments but not *all* of them as they would sometimes be lowered to `GenericArg::Infer` instead.

Additionally the `visit_infer` method would previously only visit `GenericArg::Infer` not *all* infers (e.g. `TyKind::Infer`), this made it very easy to override `visit_infer` and expect it to visit all infers when in reality it would only visit *some* infers.

---

This PR aims to fix those issues by making the `TyKind` and `ConstArgKind` types generic over whether the infer types/consts are represented by `Ty/ConstArgKind::Infer` or out of line (e.g. by a `GenericArg::Infer` or accessible by overiding `visit_infer`). We then make HIR Visitors convert all const args and types to the versions where infer vars are stored out of line and call `visit_infer` in cases where a `Ty`/`Const` would previously have had a `Ty/ConstArgKind::Infer` variant:

API Summary
```rust
enum AmbigArg {}

enum Ty/ConstArgKind<Unambig = ()> {
   ...
   Infer(Unambig),
}

impl Ty/ConstArg {
  fn try_as_ambig_ty/ct(self) -> Option<Ty/ConstArg<AmbigArg>>;
}
impl Ty/ConstArg<AmbigArg> {
  fn as_unambig_ty/ct(self) -> Ty/ConstArg;
}

enum InferKind {
  Ty(Ty),
  Const(ConstArg),
  Ambig(InferArg),
}

trait Visitor {
  ...
  fn visit_ty/const_arg(&mut self, Ty/ConstArg<AmbigArg>) -> Self::Result;
  fn visit_infer(&mut self, id: HirId, sp: Span, kind: InferKind) -> Self::Result;
}

// blanket impl'd, not meant to be overriden
trait VisitorExt {
  fn visit_ty/const_arg_unambig(&mut self, Ty/ConstArg) -> Self::Result;
}

fn walk_unambig_ty/const_arg(&mut V, Ty/ConstArg) -> Self::Result;
fn walk_ty/const_arg(&mut V, Ty/ConstArg<AmbigArg>) -> Self::Result;
```

The end result is that `visit_infer` visits *all* infer args and is also the *only* way to visit an infer arg, `visit_ty` and `visit_const_arg` can now no longer encounter a `Ty/ConstArgKind::Infer`. Representing this in the type system means that it is now very difficult to mess things up, either accessing `TyKind::Infer` "just works" and you won't miss *some* type infers- or it doesn't work and you have to look at `visit_infer` or some `GenericArg::Infer` which forces you to think about the full complexity involved.

Unfortunately there is no lint right now about explicitly matching on uninhabited variants, I can't find the context for why this is the case 🤷‍♀️

I'm not convinced the framing of un/ambig ty/consts is necessarily the right one but I'm not sure what would be better. I somewhat like calling them full/partial types based on the fact that `Ty<Partial>`/`Ty<Full>` directly specifies how many of the type kinds are actually represented compared to `Ty<Ambig>` which which leaves that to the reader to figure out based on the logical consequences of it the type being in an ambiguous position.

---

tool changes have been modified in their own commits for easier reviewing by anyone getting cc'd from subtree changes. I also attempted to split out "bug fixes arising from the refactoring" into their own commit so they arent lumped in with a big general refactor commit

Fixes #112110
2025-01-24 11:12:01 +00:00
Eric Huss
e0bbeb7a00 Make cenum_impl_drop_cast a hard error
This changes the `cenum_impl_drop_cast` lint to be a hard error. This
lint has been deny-by-default and warning in dependencies since
https://github.com/rust-lang/rust/pull/97652 about 2.5 years ago.

Closes https://github.com/rust-lang/rust/issues/73333
2025-01-23 16:45:19 -08:00
bors
22a220a1a8 Auto merge of #132666 - dingxiangfei2009:skip-if-let-rescope-lint, r=compiler-errors
Skip `if-let-rescope` lint unless requested by migration

Tracked by #124085
Related to https://github.com/rust-lang/rust/pull/131984#issuecomment-2448329667

Given that `if-let-rescope` is a lint to be enabled globally by an edition migration, there is no point in extracting the precise lint level on the HIR expression. This mitigates the performance regression discovered by the earlier perf-run.

cc `@Kobzol` `@rylev` `@traviscross` I propose a `rust-timer` run to measure how much performance that we can recover from the mitigation. 🙇
2025-01-23 23:16:06 +00:00
bjorn3
4d1c16c09c Make the wasm_c_abi future compat warning a hard error
This is the next step in getting rid of the broken C abi for
wasm32-unknown-unknown.
2025-01-23 10:22:23 +00:00
Matthias Krüger
9b40bd70de
Rollup merge of #135552 - amy-kwan:amy-kwan/reprc-struct-diagnostic-power-alignment, r=workingjubilee
[AIX] Lint on structs that have a different alignment in AIX's C ABI

This PR adds a linting diagnostic on AIX for repr(C) structs that are required to follow
the power alignment rule. A repr(C) struct needs to follow the power alignment rule if
the struct:
- Has a floating-point data type (greater than 4-bytes) as its first member, or
- The first member of the struct is an aggregate, whose recursively first member is a
   floating-point data type (greater than 4-bytes).

The power alignment rule for eligible structs is currently unimplemented, so a linting
diagnostic is produced when such a struct is encountered.
2025-01-23 09:49:19 +01:00
Boxy
23e28d3641 make hir::Ty/ConstArg methods generic where applicable 2025-01-23 06:01:36 +00:00
Boxy
2bdeff2fb8 visit_x_unambig 2025-01-23 06:01:36 +00:00
Boxy
98d80e22d0 Split hir TyKind and ConstArgKind in two and update hir::Visitor 2025-01-23 06:01:36 +00:00
Boxy
0f10ba60ff Make hir::TyKind::TraitObject use tagged ptr 2025-01-23 06:01:36 +00:00
Matthias Krüger
9206ba535c
Rollup merge of #132983 - Anthony-Eid:dangling-pointers-lint, r=Urgau
Edit dangling pointers

Closes: #132283
2025-01-22 20:37:23 +01:00
Amy Kwan
cd2ecc4b50 [AIX] Lint on structs that have a different alignment in AIX's C ABI 2025-01-22 12:06:16 -05:00
Anthony Eid
12214db74b Update lint tests with new dangling pointers message 2025-01-22 00:00:31 -05:00
Ralf Jung
a99778c839 remove long-deprecated no-op attributes no_start and crate_id 2025-01-21 17:29:06 -07:00
Yotam Ofek
264fa0fc54 Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
Matthias Krüger
8f9ccc5d1b
Rollup merge of #135249 - s-cerevisiae:fix-overflowing-literals-help, r=chenyukang
Fix overflows in the implementation of `overflowing_literals` lint's help

This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases.

1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes #135248)
2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes #131849)

Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
2025-01-16 17:00:46 +01:00
Jacob Pratt
77b7ee1960
Rollup merge of #135441 - compiler-errors:redundant-captures-lint, r=lqd
Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024

I never got sign-off on #127672 for this lint being warn by default in edition 2024, so let's turn downgrade this lint to allow for now.

Should be backported so it ships with the edition.

```@rustbot``` label: +beta-nominated
2025-01-13 20:43:48 -05:00
Michael Goulet
1b068a0dea Make sure to mark IMPL_TRAIT_REDUNDANT_CAPTURES as Allow in edition 2024 2025-01-13 16:41:01 +00:00
Aditya-PS-05
562107760d Update unstable lint docs to include required feature attributes 2025-01-12 19:31:05 +05:30
spore
74e2e8b598 Suggest the smallest fitting type instead
Changes the behavior of the `overflowing_literals` suggestion so that it
always suggest the smallest type regardless of the original type size.
2025-01-12 20:20:39 +08:00
spore
4a85755756 Minor simplification
Apply eta-reduction on map to simplify code and make the style more
consistent
2025-01-11 13:05:15 +08:00
bors
251206c27b Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrum
Master bootstrap update

Part of the release process.

r? `@Mark-Simulacrum`
2025-01-09 13:33:16 +00:00
Matthias Krüger
a1cadeab68
Rollup merge of #135269 - estebank:unneeded-into, r=compiler-errors
Remove some unnecessary `.into()` calls
2025-01-09 09:05:10 +01:00
Matthias Krüger
a9614a5768
Rollup merge of #135212 - Urgau:unreach_pub-upd-descr, r=petrochenkov
Remove outdated information in the `unreachable_pub` lint description

As far as I understand the `unreachable_pub` lint hasn't had false-positives since it started using "effective visibilities". Let's remove that warning from the lint description.

r? `@petrochenkov`
2025-01-09 09:05:05 +01:00
Esteban Küber
eb917ea24d Remove some unnecessary .into() calls 2025-01-08 21:19:28 +00:00
Pietro Albini
2af3ba9a8a
update cfg(bootstrap) 2025-01-08 21:26:39 +01:00