Commit Graph

21932 Commits

Author SHA1 Message Date
Alex Macleod
0972c3b565 Check for MSRV attributes in late passes using the HIR 2025-02-28 18:09:44 +00:00
Timo
2cdb90d961 New lint: manual_midpoint (#13851)
changelog: [`manual_midpoint`]: new lint

Closes #13849
2025-02-28 16:27:34 +00:00
Alejandra González
e1c1ac1592 configuration option to lint incompatible_msrv in test code (#14279)
fixes #14277

changelog: [`incompatible_msrv`]: add config option
[`check-incompatible-msrv-in-tests`] to enable in `#[test]` and
`#[cfg(test)]` code.
2025-02-28 12:41:46 +00:00
Samuel Tardieu
baadee8fd3 New lint: manual_midpoint 2025-02-27 22:12:16 +01:00
Samuel Tardieu
06175f43b3 Add is_float_literal utility 2025-02-27 22:10:57 +01:00
Philipp Krones
715d3f9224 Rustup (#14300)
Out of cycle sync, as it is complicated and confusing to resolve merge
conflicts on the Rust side. This needs review for
eda3e649a41e0e73cb2e3ee6b98cbf8d7c12acae and
4d8766caaf11a14194406b8997243bb626000aae as well as the comment I'll
leave below.

changelog: none
2025-02-27 21:02:32 +00:00
Philipp Krones
b3d35b1af6 Bump nightly version -> 2025-02-27 2025-02-27 21:51:42 +01:00
Philipp Krones
28555d1231 Split must_use_unit test into an unfixable part
With the attribute refactor in rustc, making this case machine applicable is not
easily possible anymore. This splits up the tests properly.
2025-02-27 21:51:42 +01:00
Philipp Krones
53a1ff70e8 Check os_str_display MSRV instead of feature
This feature was stabilized, so the FormatArgs lints should check if the MSRV of
the stabilization is met, rather than checking if the feature is enabled.
2025-02-27 21:51:42 +01:00
Philipp Krones
02e812af4d Merge remote-tracking branch 'upstream/master' into rustup 2025-02-27 21:51:42 +01:00
Catherine Flores
15180d4eb9 macro_use_import: Don't check is attribute comes from expansion (#14317)
It is not possible to write a declarative macro, that produces an
attribute w/o
an item attached to it. This means that the `check_item` will already
insert the
span in the map, if it came from an expansion. So additionally checking
if the
macro came from an expansion doesn't add anything here. So the
`check_attribute` function, and with that the problematic `attr.span()`
call can
be completely removed.

Fixes https://github.com/rust-lang/rust-clippy/issues/14303

r? @y21

cc @jdonszelmann

changelog: Fix ICE in [`macro_use_import`] lint
2025-02-27 19:51:57 +00:00
Philipp Krones
063d6aef0e macro_use_import: Don't check is attribute comes from expansion
It is not possible to write a declarative macro, that produces an attribute w/o
an item attached to it. This means that the `check_item` will already insert the
span in the map, if it came from an expansion. So additionally checking if the
macro came from an expansion doesn't add anything here. So the
`check_attribute` function, and with that the problematic `attr.span()` call can
be completely removed.

Fixes #14303
2025-02-27 20:42:56 +01:00
Alex Macleod
4a9b8c6415 fix: map_entry FP inside closure (#14307)
Closes #11976

changelog: [`map_entry`]: fix FP inside closure
2025-02-27 14:42:00 +00:00
yanglsh
329acde93e fix: map_entry FP inside closure 2025-02-27 21:28:00 +08:00
dswij
527ab050fa fix: Avoid ICE in doc_nested_refdefs check by checking range (#14308)
The `looks_like_refdef` function was assuming the range was valid, this
just adds a check to ensure that is the case. It also works around a
subtraction underflow due to the same invalid range.

changelog: [`doc_nested_refdefs`]: Fix #14287 by avoiding invalid ranges
2025-02-27 10:45:31 +00:00
Fridtjof Stoldt
f50266a423 Split needless_lifetime '_ suggestions into elidable_lifetime_names (#13960)
Fixes https://github.com/rust-lang/rust-clippy/issues/13514

changelog: Added [`elidable_lifetime_names`] to `pedantic` (Split off
from [`needless_lifetime`] for suggestions with `'_`)
[#13960](https://github.com/rust-lang/rust-clippy/pull/13960)

changelog: Enhancement: [`needless_lifetime`] No longer lints for
elidable lifetimes `'_`, use [`elidable_lifetime_names`] to lint these.
[#13960](https://github.com/rust-lang/rust-clippy/pull/13960)
2025-02-27 09:21:50 +00:00
Jake Shadle
e399e152e8 Fix ICE 2025-02-27 10:18:44 +01:00
Manish Goregaokar
52bf26e9ad Remove obsolete TODO (#14304)
changelog: none
2025-02-26 22:49:03 +00:00
Samuel Tardieu
e9561289d6 Remove obsolete TODO 2025-02-26 23:36:31 +01:00
Alejandra González
b583568e72 Add unnecessary_debug_formatting lint (#13893)
Fixes #12674, i.e., adds a lint to flag `Path`s printed with `{:?}`.

Nits are welcome.

changelog: Add `unnecessary_debug_formatting` lint
2025-02-26 15:03:57 +00:00
Alex Macleod
b821f972b6 manual_strip: use existing identifier instead of placeholder (#14188)
When the manually stripped entity receives a name as the first use
through a simple `let` statement, this name can be used in the generated
`if let Some(…)` expression instead of a placeholder.

Fix #14183

changelog: [`manual_strip`]: reuse existing identifier in suggestion
when possible
2025-02-26 14:41:41 +00:00
Samuel Moelius
6af901c51e Add unnecessary_debug_formatting lint
Address review comments

Fix adjacent code

Required now that the lint is pedantic

Add inline formatting tests

Add note re formatting changes

Address `unnecessary_map_or` warnings

Address additional review comments

Typo

Update Clippy version
2025-02-26 14:25:58 +00:00
Bryce Berger
325bfef88d configuration option to lint incompatible_msrv in test code 2025-02-25 19:54:05 -05:00
Alejandra González
162b0e8c4a Add todo! & unimplemented! to format macros list (#14266)
For some reason, the `todo!` and `unimplemented!` macros were not
included in the list of format-supporting macros list. Since they seem
to behave exactly the same as all others like `write!` and `assert!`,
adding them now.

I wonder if we should delete the `FORMAT_MACRO_DIAG_ITEMS`, and instead
tag all macros with the `#[clippy::format_args]`?

changelog: all format-handling lints will now validate `todo!` and
`unimplemented!` macros.
2025-02-24 22:07:35 +00:00
Alejandra González
0fb004dd56 extend obfuscated_if_else to support {then(), then_some()}.unwrap_or_else() (#14165)
These method chains can be expressed concisely with `if`/`else`.

changelog: [`obfuscated_if_else`]: support `then().unwrap_or_else()` and
`then_some().unwrap_or_else()`
2025-02-24 19:27:56 +00:00
Alex Macleod
efcf1f5730 Split needless_lifetime '_ suggestions into elidable_lifetime_names 2025-02-24 14:23:33 +00:00
Jana Dönszelmann
17bda0c0fe simplify must-use lint slightly 2025-02-24 14:31:19 +01:00
Jana Dönszelmann
443b0f5ccf Fix rustdoc and clippy 2025-02-24 14:31:19 +01:00
Jason Newcomb
0fa170621d fix: too_long_first_doc_paragraph suggests wrongly when first line too long (#14276)
Fixes #14274

changelog: [`too_long_first_doc_paragraph`]: fix wrong suggestion when
first line too long
2025-02-24 10:04:01 +00:00
Manish Goregaokar
35d5ee0e41 add MSRV check for repeat_vec_with_capacity (#14126)
changelog: [`repeat_vec_with_capacity`]: add MSRV check
2025-02-23 15:50:44 +00:00
Matthias Krüger
15820ecc2e Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk
Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes

There are a few intertwined problems with `sym fn` operands in both inline and global asm macros.

Specifically, unlike other anon consts, they may evaluate to a type with free regions in them without actually having an item-level type annotation to give them a "proper" type. This is in contrast to named constants, which always have an item-level type annotation, or unnamed constants which are constrained by their position (e.g. a const arg in a turbofish, or a const array length).

Today, we infer the type of the operand by looking at the HIR typeck results; however, those results are region-erased, so during borrowck we ICE since we don't expect to encounter erased regions. We can't just fill this type with something like `'static`, since we may want to use real (free) regions:

```rust
fn foo<'a>() {
  asm!("/* ... */", sym bar::<&'a ()>);
}
```

The first idea may be to represent `sym fn` operands using *inline* consts instead of anon consts. This makes sense, since inline consts can reference regions from the parent body (like the `'a` in the example above). However, this introduces a problem with `global_asm!`, which doesn't *have* a parent body; inline consts *must* be associated with a parent body since they are not a body owner of their own. In #116087, I attempted to fix this by using two separate `sym` operands for global and inline asm. However, this led to a lot of confusion and also some unattractive code duplication.

In this PR, I adjust the lowering of `global_asm!` so that it's lowered in a "fake" HIR body. This body contains a single expression which is `ExprKind::InlineAsm`; we don't *use* this HIR body, but it's used in typeck and borrowck so that we can properly infer and validate the the lifetimes of `sym fn` operands.

I then adjust the lowering of `sym fn` to instead be represented with a HIR expression. This is both because it's no longer necessary to represent this operand as an anon const, since it's *just* a path expression, and also more importantly to sidestep yet another ICE (https://github.com/rust-lang/rust/issues/137179), which has to do with the existing code breaking an invariant of def-id creation and anon consts. Specifically, we are not allowed to synthesize a def-id for an anon const when that anon const contains expressions with def-ids whose parent is *not* that anon const. This is somewhat related to https://github.com/rust-lang/rust/pull/130443#issuecomment-2445678945, which is also a place in the compiler where synthesizing anon consts leads to def-id parenting issue.

As a side-effect, this consolidates the type checking for inline and global asm, so it allows us to simplify `InlineAsmCtxt` a bit. It also allows us to delete a bit of hacky code from anon const `type_of` which was there to detect `sym fn` operands specifically. This also could be generalized to support `const` asm operands with types with lifetimes in them. Since we specifically reject these consts today, I'm not going to change the representation of those consts (but they'd just be turned into inline consts).

r? oli-obk -- mostly b/c you're patient and also understand the breadth of the code that this touches, please reassign if you don't want to review this.

Fixes #111709
Fixes #96304
Fixes #137179
2025-02-23 00:16:19 +01:00
dswij
d92da0fb32 manual_slice_fill: do not initialize from the iterator (#14191)
```rust
let mut tmp = vec![1, 2, 3];
for b in &mut tmp {
    *b = !*b;
}
```

must not suggest the invalid `tmp.fill(!*b)`.

In addition, there is another commit which cleans up two function calls
with no effect.

Fix #14189

changelog: [`manual_slice_fill`]: ensure that the initialization
expression doesn't reference the iterator
2025-02-22 15:28:15 +00:00
Timo
d5488b3b63 useless_asref: add a check for Clone before suggesting the use of .clone() (#14174)
fixes #12357

changelog: [`useless_asref`]: don't suggest to use `.clone()` if the
target type doesn't implement the `Clone` trait
2025-02-22 14:04:57 +00:00
yanglsh
2ad3520d51 fix: too_long_first_doc_paragraph suggests wrongly when first line too long 2025-02-22 19:05:07 +08:00
Michael Goulet
ba8079d0db Make a fake body to store typeck results for global_asm 2025-02-22 00:12:07 +00:00
Michael Goulet
e5dbcc2c16 Make asm a named field 2025-02-22 00:05:09 +00:00
bors
a666d6aa55 Auto merge of #137348 - compiler-errors:span-trim, r=estebank
More sophisticated span trimming for suggestions

Previously #136958 only cared about prefixes or suffixes. Now it detects more cases where a suggestion is "sandwiched" by unchanged code on the left or the right. Would be cool if we could detect several insertions, like `ACE` going to `ABCDE`, extracting `B` and `D`, but that seems unwieldy.

r? `@estebank`
2025-02-21 23:59:08 +00:00
Fridtjof Stoldt
e479a9ff95 add io_other_error lint (#14022)
fixes #12717.

r? @xFrednet

----

changelog: add [`io_other_error`] lint
2025-02-21 21:53:48 +00:00
Andre Bogus
6366cca439 add io_other_error lint 2025-02-21 22:08:31 +01:00
bors
49082f94fc Auto merge of #137397 - matthiaskrgr:rollup-ls2pilo, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #132876 (rustdoc book: acknowledge --document-hidden-items)
 - #136148 (Optionally add type names to `TypeId`s.)
 - #136609 (libcore/net: `IpAddr::as_octets()`)
 - #137336 (Stabilise `os_str_display`)
 - #137350 (Move methods from Map to TyCtxt, part 3.)
 - #137353 (Implement `read_buf` for WASI stdin)
 - #137361 (Refactor `OperandRef::extract_field` to prep for MCP838)
 - #137367 (Do not exempt nonexistent platforms from platform policy)
 - #137374 (Stacker now handles miri using a noop impl itself)
 - #137392 (remove few unused fields)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-21 19:57:50 +00:00
lapla-cogito
6c6ffd27a2 extend obfuscated_if_else to support then().unwrap_or_else() and then_some().unwrap_or_else() 2025-02-22 03:22:23 +09:00
Alejandra González
649cef0e81 rename MANUAL_DIV_CEIL MSRV alias and add missing conf info for manual_div_ceil (#14263)
- The name of an MSRV alias should describe its functionality, and it is
not appropriate for it to be the same as the name of the lint that uses
it.
- Additionally, while `manual_div_ceil` allows setting MSRV, this is not
correctly reflected in the configuration information.

changelog: none
2025-02-21 18:02:30 +00:00
Matthias Krüger
8113d54600 Rollup merge of #137305 - nnethercote:rustc_middle-2, r=lcnr
Tweaks in and around `rustc_middle`

A bunch of tiny improvements I found while working on bigger things.

r? ```@lcnr```
2025-02-21 12:45:25 +01:00
Matthias Krüger
85329db705 Rollup merge of #137299 - nnethercote:simplify-PostOrder-customization, r=compiler-errors
Simplify `Postorder` customization.

`Postorder` has a `C: Customization<'tcx>` parameter, that gives it flexibility about how it computes successors. But in practice, there are only two `impls` of `Customization`, and one is for the unit type.

This commit simplifies things by removing the generic parameter and replacing it with an `Option`.

r? ````@saethlin````
2025-02-21 12:45:24 +01:00
Timo
1250c26613 Represent the capability instead of the lint name in msrv aliases (#14269)
`INTEGER_BITS` better represents the addition of the `BITS` value on the
primitive integer types.

Inspired by #14263

changelog: none
2025-02-21 08:55:45 +00:00
Samuel Tardieu
4ac7a5361b Represent the capability instead of the lint name in msrv aliases
`INTEGER_BITS` better represents the addition of the `BITS` value on the
primitive integer types.
2025-02-21 09:44:18 +01:00
Yuri Astrakhan
373f809c1d Add todo! & unimplemented! to format macros list
For some reason, the `todo!` and `unimplemented!` macros were not included in the list of format-supporting macros list. Since they seem to behave exactly the same as all others like `write!` and `assert!`, adding them now.
2025-02-20 22:59:05 -05:00
Nicholas Nethercote
c2d75cff47 Move methods from Map to TyCtxt, part 3.
Continuing the work from #137162.

Every method gains a `hir_` prefix.
2025-02-21 14:31:09 +11:00
Michael Goulet
a04e819b93 Trim suggestion part before generating highlights 2025-02-21 00:54:01 +00:00
Michael Goulet
fef0ea905a More sophisticated span trimming 2025-02-21 00:41:17 +00:00