Commit graph

21155 commits

Author SHA1 Message Date
J-ZhengLi
c4815aeef1 [infinite_loops]: fix suggestion error on async functions/closures 2024-10-26 17:18:02 +00:00
bors
9e36f89701 Auto merge of #125116 - blyxyas:ignore-allowed-lints-final, r=cjgillot
(Big performance change) Do not run lints that cannot emit

Before this change, adding a lint was a difficult matter because it always had some overhead involved. This was because all lints would run, no matter their default level, or if the user had `#![allow]`ed them. This PR changes that. This change would improve both the Rust lint infrastructure and Clippy, but Clippy will see the most benefit, as it has about 900 registered lints (and growing!)

So yeah, with this little patch we filter all lints pre-linting, and remove any lint that is either:
- Manually `#![allow]`ed in the whole crate,
- Allowed in the command line, or
- Not manually enabled with `#[warn]` or similar, and its default level is `Allow`

As some lints **need** to run, this PR also adds **loadbearing lints**. On a lint declaration, you can use the ``@eval_always` = true` marker to label it as loadbearing. A loadbearing lint will never be filtered (it will always run)

Fixes #106983
2024-10-26 16:37:43 +00:00
Matthias Krüger
b75d5110dd Rollup merge of #132168 - fee1-dead-contrib:fxclean, r=compiler-errors
Effects cleanup

- removed extra bits from predicates queries that are no longer needed in the new system
- removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers

r? compiler-errors
2024-10-26 06:29:48 +02:00
Deadbeef
350d1c4aee Effects cleanup
- removed extra bits from predicates queries that are no longer needed in the new system
- removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
2024-10-26 10:19:07 +08:00
GnomedDev
560353c90a
Stop linting unused_io_amount in io traits 2024-10-26 00:39:18 +01:00
bors
8b9376a706 Auto merge of #131349 - RalfJung:const-stability-checks, r=compiler-errors
Const stability checks v2

The const stability system has served us well ever since `const fn` were first stabilized. It's main feature is that it enforces *recursive* validity -- a stable const fn cannot internally make use of unstable const features without an explicit marker in the form of `#[rustc_allow_const_fn_unstable]`. This is done to make sure that we don't accidentally expose unstable const features on stable in a way that would be hard to take back. As part of this, it is enforced that a `#[rustc_const_stable]` can only call `#[rustc_const_stable]` functions. However, some problems have been coming up with increased usage:
- It is baffling that we have to mark private or even unstable functions as `#[rustc_const_stable]` when they are used as helpers in regular stable `const fn`, and often people will rather add `#[rustc_allow_const_fn_unstable]` instead which was not our intention.
- The system has several gaping holes: a private `const fn` without stability attributes whose inherited stability (walking up parent modules) is `#[stable]` is allowed to call *arbitrary* unstable const operations, but can itself be called from stable `const fn`. Similarly, `#[allow_internal_unstable]` on a macro completely bypasses the recursive nature of the check.

Fundamentally, the problem is that we have *three* disjoint categories of functions, and not enough attributes to distinguish them:
1. const-stable functions
2. private/unstable functions that are meant to be callable from const-stable functions
3. functions that can make use of unstable const features

Functions in the first two categories cannot use unstable const features and they can only call functions from the first two categories.

This PR implements the following system:
- `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions.
- `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category.
- `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls.

Also, all the holes mentioned above have been closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to be manually marked `#[rustc_const_stable_indirect]` to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine.

The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability.

Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.

Also see the updated dev-guide at https://github.com/rust-lang/rustc-dev-guide/pull/2098.

I think in the future we may want to tweak this further, so that in the hopefully common case where a public function's const-stability just exactly mirrors its regular stability, we never have to add any attribute. But right now, once the function is stable this requires `#[rustc_const_stable]`.

### Open question

There is one point I could see we might want to do differently, and that is putting `#[rustc_const_unstable]`  functions (but not intrinsics) in category 2 by default, and requiring an extra attribute for `#[rustc_const_not_exposed_on_stable]` or so. This would require a bunch of extra annotations, but would have the advantage that turning a `#[rustc_const_unstable]` into `#[rustc_const_stable]`  will never change the way the function is const-checked. Currently, we often discover in the const stabilization PR that a function needs some other unstable const things, and then we rush to quickly deal with that. In this alternative universe, we'd work towards getting rid of the `rustc_const_not_exposed_on_stable` before stabilization, and once that is done stabilization becomes a trivial matter. `#[rustc_const_stable_indirect]` would then only be used for intrinsics.

I think I like this idea, but might want to do it in a follow-up PR, as it will need a whole bunch of annotations in the standard library. Also, we probably want to convert all const intrinsics to the "new" form (`#[rustc_intrinsic]` instead of an `extern` block) before doing this to avoid having to deal with two different ways of declaring intrinsics.

Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
Part of https://github.com/rust-lang/rust/issues/129815 (but not finished since this is not yet sufficient to safely let us expose `const fn` from hashbrown)
Fixes https://github.com/rust-lang/rust/issues/131073 by making it so that const-stable functions are always stable

try-job: test-various
2024-10-25 23:29:40 +00:00
Ralf Jung
cd2159434b tcx.is_const_fn doesn't work the way it is described, remove it
Then we can rename the _raw functions to drop their suffix, and instead
explicitly use is_stable_const_fn for the few cases where that is really what
you want.
2024-10-25 20:52:39 +02:00
Matthias Krüger
a1ff955721 Rollup merge of #132106 - maxcabrajac:ident_ref, r=petrochenkov
Pass Ident by reference in ast Visitor

`MutVisitor`'s version of `visit_ident` passes around `&Ident`, but `Visitor` copies `Ident`. This PR changes that

r? `@petrochenkov`

related to #128974
2024-10-25 20:33:11 +02:00
Ruairidh Williamson
59ecf4d073
Fix is_from_proc_macro attr 2024-10-25 15:25:17 +01:00
Jakub Beránek
3338611c1b
Switch CI from bors to merge queue 2024-10-25 10:28:45 +02:00
bors
9cf416dc6e Auto merge of #13586 - evanj:evan.jones/long-paragraph-edit, r=xFrednet
docs: Fix too_long_first_doc_paragraph: line -> paragraph

The documentation for too_long_first_doc_paragraph incorrectly says "line" where it should say "paragraph".

Fix a minor typo: doscstring -> docstring.

Also do a few tiny edits to attempt to make the wording slightly shorter and clearer.

changelog: [`too_long_first_doc_paragraph`]: Edit documentation
2024-10-24 19:29:29 +00:00
maxcabrajac
5d681cfe78 Pass Ident by reference in ast Visitor 2024-10-24 11:10:49 -03:00
bors
6bcd0b9b42 Auto merge of #13558 - alex-semenyuk:const_is_empty_fix, r=dswij
Don't trigger `const_is_empty` for inline const assertions

Close #13106

Considered case was described [here](https://github.com/rust-lang/rust-clippy/pull/13114#issuecomment-2266629991)

changelog: [`const_is_empty`]: skip const_is_empty for inline const assertions
2024-10-24 13:55:52 +00:00
Michael Goulet
eb6026a27f Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
bors
c2534dcc49 Auto merge of #13460 - ROMemories:feat/freq-units-allowed-idents, r=Centri3
Add units/unit prefixes of frequency to doc-valid-idents

These units/unit prefixes often come up in the embedded world.

Should this PR also modify the `test_units` test? It seems only concerned with data units currently; should it also test frequency units?

changelog: [`doc_markdown`]: Add MHz, GHz, and THz to `doc-valid-idents`.
2024-10-24 08:50:36 +00:00
Samuel Tardieu
b0412d0dd7 borrow_deref_ref: do not trigger on &raw references 2024-10-24 09:03:15 +02:00
bors
cefa31a524 Auto merge of #13588 - GuillaumeGomez:fix-lint-anchor, r=flip1995
Fix not working lint anchor (generation and filtering)

As spotted by `@flip1995,` the anchor button is currently not working. Problem was the JS that was preventing the web browser from adding the hash at the end of the URL.

For the second bug fixed, the JS was stripping two characters instead of just stripping the `#` at the beginning.

changelog: Fix clippy page lint anchor (generation and filtering)

r? `@flip1995`
2024-10-23 19:12:16 +00:00
Guillaume Gomez
7115404a97 Open lint when clicking on its anchor 2024-10-23 16:58:06 +02:00
Ralf Jung
54f9bc4884 nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
Guillaume Gomez
b33977b852 Fix invalid lint ID filtering 2024-10-22 22:54:29 +02:00
Guillaume Gomez
97d13a8c0a Fix not working lint anchor 2024-10-22 22:50:17 +02:00
Evan Jones
0bcc6f8156
docs: Fix too_long_first_doc_paragraph: line -> paragraph
The documentation for too_long_first_doc_paragraph incorrectly says
"line" where it should say "paragraph".

Fix a minor typo: doscstring -> docstring.

Also do a few tiny edits to attempt to make the wording slightly
shorter and clearer.

changelog: Edit documentation for [`too_long_first_doc_paragraph`]
2024-10-22 16:04:30 -04:00
Michael Goulet
088f07a0a7 Represent TraitBoundModifiers as distinct parts in HIR 2024-10-22 19:48:44 +00:00
bors
78fc7bbfdd Auto merge of #131321 - RalfJung:feature-activation, r=nnethercote
terminology: #[feature] *enables* a feature (instead of "declaring" or "activating" it)

Mostly, we currently call a feature that has a corresponding `#[feature(name)]` attribute in the current crate a "declared" feature. I think that is confusing as it does not align with what "declaring" usually means. Furthermore, we *also* refer to `#[stable]`/`#[unstable]` as *declaring* a feature (e.g. in [these diagnostics](f25e5abea2/compiler/rustc_passes/messages.ftl (L297-L301))), which aligns better with what "declaring" usually means. To make things worse, the functions  `tcx.features().active(...)` and  `tcx.features().declared(...)` both exist and they are doing almost the same thing (testing whether a corresponding `#[feature(name)]`  exists) except that `active` would ICE if the feature is not an unstable lang feature. On top of this, the callback when a feature is activated/declared is called `set_enabled`, and many comments also talk about "enabling" a feature.

So really, our terminology is just a mess.

I would suggest we use "declaring a feature" for saying that something is/was guarded by a feature (e.g. `#[stable]`/`#[unstable]`), and "enabling a feature" for  `#[feature(name)]`. This PR implements that.
2024-10-22 11:02:35 +00:00
Ralf Jung
2fd8222bd4 terminology: #[feature] *enables* a feature (instead of "declaring" or "activating" it) 2024-10-22 07:37:54 +01:00
bors
f03f7c6c9d Auto merge of #129935 - RalfJung:unsupported_calling_conventions, r=compiler-errors
make unsupported_calling_conventions a hard error

This has been a future-compat lint (not shown in dependencies) since Rust 1.55, released 3 years ago. Hopefully that was enough time so this can be made a hard error now. Given that long timeframe, I think it's justified to skip the "show in dependencies" stage. There were [not many crates hitting this](https://github.com/rust-lang/rust/pull/86231#issuecomment-866300943) even when the lint was originally added.

This should get cratered, and I assume then it needs a t-compiler FCP. (t-compiler because this looks entirely like an implementation oversight -- for the vast majority of ABIs, we already have a hard error, but some were initially missed, and we are finally fixing that.)

Fixes https://github.com/rust-lang/rust/pull/87678
2024-10-22 03:24:40 +00:00
blyxyas
3773534f29 Move COGNITIVE_COMPLEXITY to use macro again 2024-10-21 19:27:34 +02:00
bors
5873cb9d17 Auto merge of #13570 - Kijewski:pr-stray-comma, r=xFrednet
docs: remove stray comma

changelog: none

the typo was (seemingly) ignored by browsers, so the change isn't visible to users
2024-10-21 09:11:08 +00:00
bors
8538562429 Auto merge of #13567 - y21:span_debug_assertions, r=flip1995
Add debug assertions for empty replacements and overlapping spans

rustc has debug assertions [^1] [^2] that check that a substitution doesn't have an empty suggestion string and an empty span at the same time, as well as that spans in multipart suggestions don't overlap.
However, since we link to the rustc-dev distributed compiler, these debug assertions are always disabled and so we never actually run them.

This leads to the problem that the debug ICE is not necessarily caught in the PR and only triggered in the rust repo sync, and in one of the last syncs this was a blocker and delayed the sync by several weeks because the fix was not obvious.

So this PR essentially copies the checks over and runs them in clippy debug builds as well, so that we can catch these errors in PRs directly.

-----
As for the second commit, this also *did* cause an ICE in a sync before and was fixed in the sync PR (see https://github.com/rust-lang/rust/pull/120345#issuecomment-1911005554), but it seems like that commit didn't make it back into the clippy repo (cc `@flip1995),` so the fixed code is in the rust repo but not in the clippy repo.

changelog: none

[^1]: https://doc.rust-lang.org/1.82.0/nightly-rustc/src/rustc_errors/diagnostic.rs.html#1019
[^2]: https://doc.rust-lang.org/1.82.0/nightly-rustc/src/rustc_errors/diagnostic.rs.html#932
2024-10-21 08:26:32 +00:00
bors
1d0dad5eb3 Auto merge of #131988 - matthiaskrgr:rollup-tx173wn, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #126588 (Added more scenarios where comma to be removed in the function arg)
 - #131728 (bootstrap: extract builder cargo to its own module)
 - #131968 (Rip out old effects var handling code from traits)
 - #131981 (Remove the `BoundConstness::NotConst` variant)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-21 06:13:34 +00:00
bors
d00ab2e955 Auto merge of #13569 - alex-semenyuk:fix_version, r=blyxyas
Fix version for `ref_option`

Close #13566
As mentioned at #13566 `ref_option` [was merged](https://github.com/rust-lang/rust-clippy/pull/13336) after 1.82.0 so it wasn't include in this version

changelog: none
2024-10-20 22:20:55 +00:00
y21
b3bf128e54 don't lint nested items that don't have generated documentation in missing_docs_in_private_items 2024-10-20 23:42:28 +02:00
y21
2f71ce6651 don't lint unnamed constants in missing_docs_in_private_items 2024-10-20 22:14:02 +02:00
Alex Macleod
2666ed6c5b Fix indentation of website code snippets 2024-10-20 19:02:40 +00:00
y21
65eb1ec0fb remove the semicolon for builtin macro call statements in statement_outside_block
The expansion of `asm!()` and `line!()` is not marked as from an expansion, in which case `SourceMap::stmt_span` returns the input span unchanged. So instead of using `stmt_span`, use `mac_call_stmt_semi_span` directly
2024-10-20 19:00:55 +02:00
Michael Goulet
d8b2f9364d Rip out old effects var handling code from traits 2024-10-20 13:40:22 +00:00
Ralf Jung
aab0eee4ef make unsupported_calling_conventions a hard error 2024-10-20 15:22:21 +02:00
René Kijewski
2a5de352a1 docs: remove stray comma 2024-10-20 14:47:01 +02:00
alexey semenyuk
64c4cf1cba
Fix version for ref_option 2024-10-20 14:43:32 +05:00
Michael Goulet
69b088626c Fix tests 2024-10-19 18:07:35 +00:00
y21
4de65a113f fix empty suggestion ICE in from_over_into 2024-10-19 19:24:09 +02:00
y21
38cf3f3234 add debug assertions for overlapping spans and empty replacements 2024-10-19 19:23:56 +02:00
blyxyas
e518d66dc0 Apply review comments + use shallow_lint_levels_on 2024-10-19 16:20:52 +02:00
blyxyas
e427a4e694 Remove module passes filtering 2024-10-19 16:20:51 +02:00
blyxyas
8f8aa46a87 Follow review comments (optimize the filtering) 2024-10-19 16:20:33 +02:00
blyxyas
698363122e Do not run lints that cannot emit
Before this change, adding a lint was a difficult matter
because it always had some overhead involved. This was
because all lints would run, no matter their default level,
or if the user had #![allow]ed them. This PR changes that
2024-10-19 16:19:44 +02:00
bors
5678531c6d Auto merge of #13564 - GnomedDev:fix-manualbits-in-macro, r=blyxyas
Stop linting manual_bits in any macro invoke

Closes #13563.

changelog: [`manual_bits`] No longer lints in macro-generated code
2024-10-19 14:09:28 +00:00
bors
f2f0175eb2 Auto merge of #13543 - GnomedDev:symbol-comparisons, r=y21
Add internal lint to check for slow symbol comparisons

See the conversation on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Checking.20a.20Symbol.20is.20equal.20to.20a.20string.20literal).

changelog: none
2024-10-18 23:20:38 +00:00
GnomedDev
a739cc3abe
Stop linting manual_bits in any macro invoke 2024-10-18 21:41:05 +01:00
bors
6a795887c4 Auto merge of #13539 - GuillaumeGomez:allow-no-js, r=Alexendoo
Allow to go through clippy lints page without javascript

Fixes #13536.

This is the follow-up of https://github.com/rust-lang/rust-clippy/pull/13269.

This PR makes it possible to expand/collapse lints (individually) without JS. To achieve this result, there are two ways:
1. Use `details` and `summary` tags. Problem with this approach is that the web browser search may open the `details` tags automatically if content matching it is inside. From a previous discussion with `@Alexendoo,` it seems to not be a desired behaviour.
2. Use a little trick where you use a `label` and a checkbox where the checkbox is in fact hidden. Then it's just a matter of CSS.

r? `@Alexendoo`

changelog: Allow to go through clippy lints page without JS
2024-10-18 19:24:16 +00:00