Commit Graph

13641 Commits

Author SHA1 Message Date
Ada Alakbarova 02bc3c94d2 get_diagnostic_name in other places 2025-08-22 15:03:12 +02:00
Philipp Krones 877967959a Rustup (#15531)
Letting rustbot assign a reviewer, so that someone can double check
9de86f40d7.

changelog: none
2025-08-22 12:36:32 +00:00
Philipp Krones 9de86f40d7 Dogfood fixes 2025-08-22 14:26:24 +02:00
Philipp Krones 284b596ac4 Merge remote-tracking branch 'upstream/master' into rustup 2025-08-22 14:25:23 +02:00
Philipp Krones 6d89c55e1a Fixunnecessary_safety_comment does not lint for the first line (#15354)
Closes rust-lang/rust-clippy#14553
Closes rust-lang/rust-clippy#14554

changelog: [`unnecessary_safety_comment`] fix FN for the first line in
file
2025-08-22 08:33:46 +00:00
Ada Alakbarova 27b2c5dd65 renamed_function_params: clean-up a bit
use `iter::zip`

use `Option::filter`

use `Option::is_some_and`

match in two steps
2025-08-22 00:22:33 +02:00
Alex Macleod c18363c0e3 too_many_lines: only highlight the function signature (#15461)
resolves https://github.com/rust-lang/rust-clippy/issues/15430

changelog: [`too_many_lines`]: only highlight the function signature
2025-08-21 15:25:03 +00:00
Alex Macleod 1954d4c0e4 len_zero: clean-up a bit (#15518)
changelog: none
2025-08-21 15:22:11 +00:00
Timo 0039c64e4b ptr_arg: clean-up a bit (#15507)
changelog: none
2025-08-21 14:59:12 +00:00
Alex Macleod 743405d7bf Do not replace match by if if any arm contains a binding (#15352)
changelog: [`match_bool`]: do not replace `match` by `if` if any arm
contains a binding

Fixes rust-lang/rust-clippy#15351
2025-08-21 13:42:44 +00:00
yanglsh f4c6ab0d14 fix: unnecessary_safety_comment does not lint for the first line 2025-08-21 11:30:57 +08:00
Ada Alakbarova f177835f54 fix whatever this is 2025-08-20 20:46:44 +02:00
Ada Alakbarova 6de463c411 make a big let-chain 2025-08-20 20:45:39 +02:00
Ada Alakbarova 5ec13c9428 merge pats 2025-08-20 20:43:27 +02:00
Ada Alakbarova e4d9449dc0 ptr_arg: clean-up a bit
create `Option<Region>` in a separate `filter_map`

reduces nesting a bit

replace a bunch of `and_then`s with a clearer(?) let-chain

`too_many_lines` no more!

use free-standing `zip`

add some comments
2025-08-19 21:05:37 +02:00
Ada Alakbarova 54c52e208a extract duplicate_underscore_argument, and move it into functions
misc: use `str::starts_with`

extract `duplicate_underscore_argument` into a module

move it to `functions`
2025-08-19 19:27:25 +02:00
Nicholas Nethercote c1dfeea919 Prevent impossible combinations in ast::ModKind.
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field.
If the `inline` field is `Inline::Yes` then `had_parse_error` must be
`Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No`
variant. This makes it impossible to create the nonsensical combination
of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
2025-08-19 21:57:31 +10:00
Nick Drozd 64d6f82825 Cut needless mut 2025-08-18 15:16:04 -04:00
Alejandra González 73b5a59c22 Do not suggest to use implicit DerefMut on ManuallyDrop reached through unions (#14387)
This requires making the `deref_addrof` lint a late lint instead of an
early lint to check for types.

changelog: [`deref_addrof`]: do not suggest implicit `DerefMut` on
`ManuallyDrop` union fields

Fix rust-lang/rust-clippy#14386
2025-08-18 15:10:31 +00:00
llogiq feb18ca1ee clean-up collapsible_if a bit (#15503)
changelog: none
2025-08-17 15:44:04 +00:00
Alejandra González 1fd9504619 similar_names stop linting for 3-char names (#15100)
fixes rust-lang/rust-clippy#14869

Added a simple check if both chars are of length 3
If they are, we skip the check for that pair.

This won't handle the 4 v 3 case.
Not sure if this was the intent of the issue.

Also saw we have some hardcoded exemptions for `set, get` and `lhs, rhs`
Tried removing them thinking they would be handled by the new condition.
But we have to keep because they allow for `bla_lhs` v `bla_rhs` to be
skipped

changelog:[`similar_names`]: Stop triggering for 3-character names
2025-08-16 16:58:06 +00:00
Abderahmane Bouziane e41fb7ca52 similar_names stop linting for 3-char names 2025-08-16 12:36:50 -04:00
Ada Alakbarova 8418fb8eb1 shorten expr_block 2025-08-16 15:56:22 +02:00
Ada Alakbarova 42ddaa3a38 inline ctxt; use eq_ctxt 2025-08-16 15:56:22 +02:00
Ada Alakbarova 27784f29a7 use str::ends_with 2025-08-16 15:56:22 +02:00
Ada Alakbarova 43f832d37b use Option::is_some_and 2025-08-16 15:56:21 +02:00
Ada Alakbarova a8b52bacfe clean-up unnecessary_unwrap a bit
replace multiple `if-let`s with `match`

turn the condition into a match guard

allows removing the `else` branch

replace `Vec::append` with `extend`

don't need the second vec after this operation anyway

remove `return`s
2025-08-16 03:03:53 +02:00
Jason Newcomb 9563a5ce46 {borrow,ptr}_as_ptr: don't lint inside proc-macros (#15473)
this could arguably be 2 separate PRs, but both of these were brought up
in the same issue, so..

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

- [x] I'm a bit doubtful about the last commit -- see the message for my
reasoning and do let me know whether it's right.

changelog: [`borrow_as_ptr`]: don't lint inside proc-macros
changelog: [`ptr_as_ptr`]: don't lint inside proc-macros
2025-08-15 13:34:52 +00:00
Ada Alakbarova 9570ed8363 ptr_as_ptr: don't allow in proc-macros
notice that this stops `inline!` from working as well
2025-08-15 14:04:37 +02:00
Stuart Cook 210097ad7e Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov
Change the desugaring of `assert!` for better error output

In the desugaring of `assert!`, we now expand to a `match` expression instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

Now `assert!(val)` desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.
2025-08-15 16:16:29 +10:00
Timo aeaa348b42 unnecessary_operation: add space between stmts in suggestion (#15432)
makes the suggestion a bit more legible

changelog: [`unnecessary_operation`]: add space between stmts in
suggestion
2025-08-14 18:06:06 +00:00
Timo 871df561a0 Fix match_ref_pats FP on match scrutinee of never type (#15474)
Closes rust-lang/rust-clippy#15378

changelog: [`match_ref_pats`] fix FP on match scrutinee of never type
2025-08-14 18:02:36 +00:00
dswij 3e86f05b89 result_large_err: get DefId from AdtDef instead of expecting (#15467)
tiny simplification

changelog: none
2025-08-14 11:06:08 +00:00
Timo ca194053d1 Adjust declare_interior_mutable_const lint's category (#15454)
Per the root readme, `clippy::style` is a category with

> code that should be written in a more idiomatic way

description.

The code this lint guards from may be much worse than badly styled:

```rs
use std::sync::LazyLock;

// `const` instead of `static` causes `dbg!` to be printed 10 times
// instead of one.
const LICENSE_FILE_NAME_REGEX: LazyLock<String> = LazyLock::new(|| {
    dbg!("I am a large regex initialized in a lazy lock!");
    format!("Hello {}", "World".to_string())
});

fn main() {
    for _ in 0..10 {
        let _ = LICENSE_FILE_NAME_REGEX.split(" ");
    }
}
```

In large projects, it's unfortunate but sometimes possible to see style
lints suppressed with

```toml
[workspace.lints.clippy]
style = { level = "allow", priority = -1 }
```

effectively turning off crucial checks for the code like above.

To keep them, promote this lint to `clippy::suspicious`:

> code that is most likely wrong or useless

category that has the same, `warn` default level, thus not failing on
false-positives which lead to
https://github.com/rust-lang/rust-clippy/issues/5863

---

changelog: [`declare_interior_mutable_const`]: promote lint's category
to `clippy::suspicious`
2025-08-14 08:29:55 +00:00
yanglsh 05c2d72abc fix: match_ref_pats FP on match scrutinee of never type 2025-08-14 11:23:31 +08:00
Ada Alakbarova bc0e43c0f2 fix borrow_as_ptr: don't lint in proc-macros 2025-08-13 19:35:31 +02:00
Ada Alakbarova 371b174711 misc: move is_expr_temporary_value check into let-chain
we return `false` outside of the `if` anyway
2025-08-13 19:35:31 +02:00
Guillaume Gomez cf42ac6bf2 Rollup merge of #145153 - joshtriplett:macro-kinds-plural, r=petrochenkov
Handle macros with multiple kinds, and improve errors

(I recommend reviewing this commit-by-commit.)

Switch to a bitflags `MacroKinds` to support macros with more than one kind

Review everything that uses `MacroKind`, and switch anything that could refer to more than one kind to use `MacroKinds`.

Add a new `SyntaxExtensionKind::MacroRules` for `macro_rules!` macros, using the concrete `MacroRulesMacroExpander` type, and have it track which kinds it can handle. Eliminate the separate optional `attr_ext`, now that a `SyntaxExtension` can handle multiple macro kinds.

This also avoids the need to downcast when calling methods on `MacroRulesMacroExpander`, such as `get_unused_rule`.

Integrate macro kind checking into name resolution's `sub_namespace_match`, so that we only find a macro if it's the right type, and eliminate the special-case hack for attributes.

This allows detecting and report macro kind mismatches early, and more precisely, improving various error messages. In particular, this eliminates the case in `failed_to_match_macro` to check for a function-like invocation of a macro with no function-like rules.

Instead, macro kind mismatches now result in an unresolved macro, and we detect this case in `unresolved_macro_suggestions`, which now carefully distinguishes between a kind mismatch and other errors.

This also handles cases of forward-referenced attributes and cyclic attributes.

----

In this PR, I've minimally fixed up `rustdoc` so that it compiles and passes tests. This is just the minimal necessary fixes to handle the switch to `MacroKinds`, and it only works for macros that don't actually have multiple kinds. This will panic (with a `todo!`) if it encounters a macro with multiple kinds.

rustdoc needs further fixes to handle macros with multiple kinds, and to handle attributes and derive macros that aren't proc macros. I'd appreciate some help from a rustdoc expert on that.

----

r? ````````@petrochenkov````````
2025-08-13 18:43:01 +02:00
Ada Alakbarova e6f3cb00a7 move char_lit_as_u8 into the if
allows reusing `cast_from_expr` and `cast_to`
2025-08-13 16:44:32 +02:00
Ada Alakbarova 8725fac6f3 misc: use Ty::is_unit 2025-08-12 19:36:03 +02:00
Ada Alakbarova 7f23aba595 get DefId from AdtDef instead of expecting 2025-08-12 19:28:33 +02:00
Ada Alakbarova af2dd2d3bc fix unnecessary_semicolon: don't lint on stmts with attrs 2025-08-12 19:12:47 +02:00
Esteban Küber 0a522ccfd9 Change the desugaring of assert! for better error output
In the desugaring of `assert!`, we now expand to a `match` expression
instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not
the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

`assert!(val)` now desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.

We make some minor changes to some diagnostics to avoid span overlap on
type mismatch or inverted "expected"/"found" on type errors.

We remove some unnecessary parens from core, alloc and miri.

address review comments
2025-08-12 16:30:48 +00:00
Josh Triplett e7e18a3297 clippy: Update for switch to MacroKinds
This updates two clippy lints which had exceptions for `MacroKind::Bang`
macros to extend those exceptions to any macro, now that a macro_rules
macro can be any kind of macro.
2025-08-12 09:24:45 -07:00
bors a493e276b5 Auto merge of #144678 - jdonszelmann:no-mangle-extern, r=bjorn3
Make no_mangle on foreign items explicit instead of implicit

for a followup PR I'm working on I need some foreign items to mangle. I could add a new attribute: `no_no_mangle` or something silly like that but by explicitly putting `no_mangle` in the codegen fn attrs of foreign items we can default it to `no_mangle` and then easily remove it when we don't want it.

I guess you'd know about this r? `@bjorn3.` Shouldn't be too hard to review :)

Builds on rust-lang/rust#144655 which should merge first.
2025-08-12 16:20:24 +00:00
Ada Alakbarova 49666f64e9 too_many_lines: only highlight the function signature 2025-08-12 16:20:08 +02:00
Stuart Cook 12087f1d09 Rollup merge of #145273 - estebank:not-not, r=samueltardieu
Account for new `assert!` desugaring in `!condition` suggestion

`rustc` in https://github.com/rust-lang/rust/pull/122661 is going to change the desugaring of `assert!` to be

```rust
match condition {
    true => {}
    _ => panic!(),
}
```
which will make the edge-case of `condition` being `impl Not<Output = bool>` while not being `bool` itself no longer a straightforward suggestion, but `!!condition` will coerce the expression to be `bool`, so it can be machine applicable.

Transposing https://github.com/rust-lang/rust-clippy/pull/15453/ to the rustc repo.

r? `````@samueltardieu`````
2025-08-12 20:37:57 +10:00
Jana Dönszelmann 68c1574f5f make no_mangle explicit on foreign items 2025-08-12 12:07:14 +02:00
Ada Alakbarova fe086d7d5a misc: take span as the last parameter
for consistency with the other `check_fn`s
2025-08-12 00:38:19 +02:00
Cameron Steffen 9f98857714 Propagate TraitImplHeader to hir 2025-08-11 17:05:42 -05:00