Commit Graph

21098 Commits

Author SHA1 Message Date
bors
1998abcdce Auto merge of #13633 - chrysn-pull-requests:doc-valid-ident-coap, r=Centri3
Add 'CoAP' to doc-valid-idents

CoAP is a name of a network protocol common in embedded systems; one would talk in documentation about "a CoAP server" or "a CoAP client" without referring to a specific type.

This PR fixes false positives that arise from that use.

changelog: [`doc_markdown`]: Add CoAP to `doc-valid-idents`.

As this review is identical in structure to https://github.com/rust-lang/rust-clippy/pull/13460, I'm asking for a the same reviewer (if that works):

r? `@Centri3`
2024-10-30 21:58:56 +00:00
Guillaume Gomez
0c29fccf03 Extend large_include_file lint to also work on attributes 2024-10-30 20:41:34 +01:00
Alex Macleod
a7aa8bfde0 Watch tests/compile-test.rs in cargo dev serve 2024-10-30 19:21:25 +00:00
Yuri Astrakhan
323f144fe1 Cleanup code suggestion for into_iter_without_iter
Reorder the suggested code for the `IntoIterator` to match the ordering of the trait declaration:

```rust
impl IntoIterator for ... {
    type Item = ...;
    type IntoIter = ...;
```
2024-10-30 13:10:55 -04:00
Camille GILLOT
d9a0fec48a Remap impl-trait lifetimes on HIR instead of AST lowering. 2024-10-30 16:18:50 +00:00
bors
1bdc08a6bc Auto merge of #13599 - RuairidhWilliamson:proc_macro_attr, r=blyxyas
Fix allow_attributes when expanded from some macros

fixes #13349

The issue here was that the start pattern being matched on the original source code was not specific enough. When using derive macros or in the issue case a `#[repr(C)]` the `#` would match the start pattern meaning that the expanded macro appeared to be unchanged and clippy would lint it.

The change I made was to make the matching more specific by matching `#[ident` at the start. We still need the second string to match just the ident on its own because of things like `#[cfg_attr(panic = "unwind", allow(unused))]`.

I also noticed some typos with start and end, these code paths weren't being reached so this doesn't fix anything.

changelog: FP: [`allow_attributes`]: don't trigger when expanded from some macros
2024-10-30 15:22:47 +00:00
chrysn
bd4aa170ef Add 'CoAP' to doc-valid-idents 2024-10-30 12:57:24 +01:00
Samuel Tardieu
805245161a no_mangle attribute requires unsafe in Rust 2024 2024-10-30 11:31:14 +01:00
Samuel Tardieu
540e116a38 Return iterator must not capture lifetimes in Rust 2024
In Rust 2024, by default lifetimes will be captured which does not
reflect the reality since we return an iterator of `DefId` which do
not capture the input parameters.
2024-10-30 11:22:17 +01:00
Samuel Tardieu
0c1ef98454 Use match ergonomics compatible with editions 2021 and 2024 2024-10-30 11:22:17 +01:00
decryphe
f7ab2c9908 new lint: source_item_ordering 2024-10-30 10:03:16 +01:00
Samuel Tardieu
a3047098b6 Do not use gen as a variable name
`gen` will be a reserved word in Rust 2024.
2024-10-30 09:28:37 +01:00
Matthias Krüger
297f28c308 Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercote
Remove `Engine`

It's just unnecessary plumbing. Removing it results in less code, and simpler code.

r? ``@cjgillot``
2024-10-30 06:40:37 +01:00
Nicholas Nethercote
ae82c756f7 Remove Analysis::into_engine.
This is a standard pattern:
```
MyAnalysis.into_engine(tcx, body).iterate_to_fixpoint()
```
`into_engine` and `iterate_to_fixpoint` are always called in pairs, but
sometimes with a builder-style `pass_name` call between them. But a
builder-style interface is overkill here. This has been bugging me a for
a while.

This commit:
- Merges `Engine::new` and `Engine::iterate_to_fixpoint`. This removes
  the need for `Engine` to have fields, leaving it as a trivial type
  that the next commit will remove.
- Renames `Analysis::into_engine` as `Analysis::iterate_to_fixpoint`,
  gives it an extra argument for the optional pass name, and makes it
  call `Engine::iterate_to_fixpoint` instead of `Engine::new`.

This turns the pattern from above into this:
```
MyAnalysis.iterate_to_fixpoint(tcx, body, None)
```
which is shorter at every call site, and there's less plumbing required
to support it.
2024-10-30 09:41:46 +11:00
bors
15ad8245b2 Auto merge of #13034 - rspencer01:trivial_map_over_range, r=y21
Add new `trivial_map_over_range` lint

This lint checks for code that looks like
```rust
  let something : Vec<_> = (0..100).map(|_| {
    1 + 2 + 3
  }).collect();
```
which is more clear as
```rust
  let something : Vec<_> = std::iter::repeat_with(|| {
    1 + 2 + 3
  }).take(100).collect();
```

That is, a map over a range which does nothing with the parameter passed to it is simply a function (or closure) being called `n` times and could be more semantically expressed using `take`.

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

changelog: new lint: [`trivial_map_over_range`] `restriction`
2024-10-29 22:27:34 +00:00
Robert Spencer
acc3842d43 Add new map_with_unused_argument_over_ranges lint
This lint checks for code that looks like
```rust
  let something : Vec<_> = (0..100).map(|_| {
    1 + 2 + 3
  }).collect();
```
which is more clear as
```rust
  let something : Vec<_> = std::iter::repeat_with(|| {
    1 + 2 + 3
  }).take(100).collect();
```
or
```rust
  let something : Vec<_> =
      std::iter::repeat_n(1 + 2 + 3, 100)
      .collect();
```

That is, a map over a range which does nothing with the parameter
passed to it is simply a function (or closure) being called `n`
times and could be more semantically expressed using `take`.
2024-10-29 21:32:00 +00:00
lcnr
8d190cc411 update tools 2024-10-29 17:01:24 +01:00
bors
35a7095d8c Auto merge of #13499 - samueltardieu:map-all-any-identity, r=xFrednet
New lint `map_all_any_identity`

This lint has been inspired by code encountered in Clippy itself (see the first commit).

changelog: [`map_all_any_identity`]: new lint
2024-10-29 11:31:11 +00:00
Samuel Tardieu
91a1d16a81 Add new lint: map_all_any_identity 2024-10-29 11:59:15 +01:00
Samuel Tardieu
f2f73f9c9c Replace .map(…).any(identity) by .any(…) 2024-10-29 11:55:13 +01:00
bors
625d391107 Auto merge of #13437 - samueltardieu:issue-13434, r=y21
New lint `needless_as_bytes`

changelog: [`needless_as_bytes`]: new lint

Fix #13434
2024-10-29 08:03:05 +00:00
Michael Goulet
353868aa64 Remove region from adjustments 2024-10-29 01:34:06 +00:00
bors
149665afbd Auto merge of #128985 - GrigorenkoPV:instantly-dangling-pointer, r=Urgau
Lint against getting pointers from immediately dropped temporaries

Fixes #123613

## Changes:
1. New lint: `dangling_pointers_from_temporaries`. Is a generalization of `temporary_cstring_as_ptr` for more types and more ways to get a temporary.
2. `temporary_cstring_as_ptr` is removed and marked as renamed to `dangling_pointers_from_temporaries`.
3. `clippy::temporary_cstring_as_ptr` is marked as renamed to `dangling_pointers_from_temporaries`.
4. Fixed a false positive[^fp] for when the pointer is not actually dangling because of lifetime extension for function/method call arguments.
5. `core::cell::Cell` is now `rustc_diagnostic_item = "Cell"`

## Questions:
- [ ]  Instead of manually checking for a list of known methods and diagnostic items, maybe add some sort of annotation to those methods in library and check for the presence of that annotation? https://github.com/rust-lang/rust/pull/128985#issuecomment-2318714312

## Known limitations:

### False negatives[^fn]:

See the comments in `compiler/rustc_lint/src/dangling.rs`

1. Method calls that are not checked for:
   - `temporary_unsafe_cell.get()`
   - `temporary_sync_unsafe_cell.get()`
2. Ways to get a temporary that are not recognized:
   - `owning_temporary.field`
   - `owning_temporary[index]`
3. No checks for ref-to-ptr conversions:
   - `&raw [mut] temporary`
   - `&temporary as *(const|mut) _`
    - `ptr::from_ref(&temporary)` and friends

[^fn]: lint **should** be emitted, but **is not**

[^fp]: lint **should not** be emitted, but **is**
2024-10-29 00:24:07 +00:00
bors
528dcc3025 Auto merge of #13620 - GnomedDev:large-const-array-compute-const, r=Manishearth
Fire large_const_arrays for computed array lengths

changelog: [`large_const_arrays`]: Lint now fires when the length is determined by an expression
2024-10-28 20:15:54 +00:00
GnomedDev
c5df79d9db
Fire large_const_arrays for computed array lengths 2024-10-28 18:35:21 +00:00
bors
d09d85d8ef Auto merge of #13614 - hamirmahal:fix/usage-of-a-deprecated-nodejs-version, r=flip1995
fix: usage of `a deprecated Node.js version`

Fixes #13613

changelog: none
2024-10-28 17:18:11 +00:00
Hamir Mahal
d63322f0f4
fix: usage of a deprecated Node.js version 2024-10-28 09:04:16 -07:00
bors
2e4a11ea77 Auto merge of #13338 - CoCo-Japan-pan:nonminimal_bool_casted, r=Centri3
fix incorrect suggestion for `!(a >= b) as i32 == c`

fixes #12761

The expression `!(a >= b) as i32 == c` got simplified to `a < b as i32 == c`, but this is a syntax error.
The result we want is `(a < b) as i32 == c`.
This is fixed by adding a parenthesis to the suggestion given in `check_simplify_not` when the boolean expression is casted.

changelog: [`nonminimal_bool`]: fix incorrect suggestion for `!(a >= b) as i32 == c`
2024-10-28 13:58:16 +00:00
bors
a529c44eca Auto merge of #13472 - GnomedDev:smaller-msrv, r=Jarcho
Optimise Msrv for common one item case

Currently, `Msrv` is cloned around a lot in order to handle the `#[clippy::msrv]` attribute. This attribute, however, means `RustcVersion` will be heap allocated if there is only one source of an msrv (eg: `rust-version` in `Cargo.toml`).

This PR optimizes for said case, while keeping the external interface the same by swapping the internal representation to `SmallVec<[RustcVersion; 2]>`.

changelog: none
2024-10-28 12:53:06 +00:00
Pavel Grigorenko
f286174690 New lint: dangling_pointers_from_temporaries 2024-10-28 14:16:05 +03:00
Matthias Krüger
303ab513d5 Rollup merge of #131391 - ChaiTRex:isqrt, r=scottmcm,tgross35
Stabilize `isqrt` feature

Stabilizes the `isqrt` feature. FCP is incomplete.

Closes #116226
2024-10-28 12:14:57 +01:00
CoCo-Japan-pan
d30a026a6b check if we need a parenthesis 2024-10-28 18:13:16 +09:00
Samuel Tardieu
f152bcb72e Update the number of lints (over 700 → over 750) 2024-10-28 09:21:07 +01:00
Samuel Tardieu
62c4daf358 New lint needless_as_bytes 2024-10-28 09:19:17 +01:00
bors
73bad368f2 Auto merge of #13548 - wowinter13:unnecessary_filter_map_filter_map_some, r=llogiq
fix: remove unnecessary filter_map usages

fixes https://github.com/rust-lang/rust-clippy/issues/12556

(Fixed version of https://github.com/rust-lang/rust-clippy/pull/12766)

changelog: [unnecessary_filter_map]: filter map improvements
2024-10-27 22:27:49 +00:00
bors
12ca3630fc Auto merge of #13611 - xFrednet:0-giraffate-alumni, r=xFrednet
Unvacation giraffate and remove gh-pages -> xFrednet assignment

changelog: none

r? `@ghost`
2024-10-27 17:31:51 +00:00
xFrednet
f562d478f2
Unvacation giraffate and remove gh-pages -> xFrednet assignment 2024-10-27 18:27:44 +01:00
GnomedDev
d0b15f157c Swap Msrv from Vec to SmallVec 2024-10-27 14:11:20 +00:00
bors
31f6679e78 Auto merge of #13610 - alex-semenyuk:add_test_case, r=xFrednet
Add test case for `missing_errors_doc` at tests with option `check-private-item=true`

Add test case for `missing_errors_doc` at tests with option `check-private-item=true` to proof that rust-lang/rust-clippy#13391 is not an issue anymore

changelog: none

Closes: rust-lang/rust-clippy#13391
2024-10-27 12:46:55 +00:00
bors
c02f3a2822 Auto merge of #13600 - samueltardieu:push-tzuvnutssmrs, r=xFrednet
borrow_deref_ref: do not trigger on `&raw` references

changelog: [`borrow_deref_ref`]: do not trigger on `&raw` references

Fix #13584
2024-10-27 12:37:40 +00:00
Alexey Semenyuk
900db48900 Add test case for missing_errors_doc at tests with option check-private-items = true 2024-10-27 14:53:20 +05:00
bors
a0fab5cab1 Auto merge of #13605 - GnomedDev:read-exact-in-read-exact, r=llogiq
Stop linting unused_io_amount in io traits

Closes #4836

changelog: [`unused_io_amount`] No longer lints inside `io::Read`/`io::Write`, and async variants.
2024-10-27 09:42:03 +00:00
bors
3caff9962b Auto merge of #13571 - Alexendoo:website-code-indent, r=Centri3
Fix indentation of website code snippets

Fixes #13568

Follow up to #13359, I didn't catch that it swapped the `strip_prefix` out for a `trim` but they aren't interchangeable here

changelog: none
2024-10-26 18:48:12 +00:00
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