Commit graph

8357 commits

Author SHA1 Message Date
Guillaume Gomez
8473716f6e Add ui regression test for #12371 2024-02-28 12:48:00 +01:00
Nicholas Nethercote
1ba47ea06c Use LitKind::Err for floats with empty exponents.
This prevents a follow-up type error in a test, which seems fine.
2024-02-28 20:59:27 +11:00
y21
1430623e04 move methods out of impl and remove unused &self param 2024-02-28 00:53:25 +01:00
y21
0671d78283 check for try blocks in LintPass methods 2024-02-27 23:49:07 +01:00
bors
4c1d05cfa1 Auto merge of #12362 - Ethiraric:fix-11935, r=llogiq
[`map_entry`]: Check insert expression for map use

The lint makes sure that the map is not used (borrowed) before the call to `insert`. Since the lint creates a mutable borrow on the map with the `Entry`, it wouldn't be possible to replace such code with `Entry`. However, expressions up to the `insert` call are checked, but not expressions for the arguments of the `insert` call itself. This commit fixes that.

Fixes #11935

----

changelog: [`map_entry`]: Fix false positive when borrowing the map in the `insert` call
2024-02-27 18:53:25 +00:00
Yudai Fukushima
dfedadc179 fix: manual_memcpy wrong suggestion for multi dimensional arrays
chore: rebase master

chore: replace $DIR

fix: check bases does not contain reference to loop index

fix: grammatical mistake

fix: style
2024-02-28 03:48:49 +09:00
Ethiraric
c6cb0e99f3 [unnecessary_cast]: Avoid breaking precedence
If the whole cast expression is a unary expression (`(*x as T)`) or an
addressof expression (`(&x as T)`), then not surrounding the suggestion
into a block risks us changing the precedence of operators if the cast
expression is followed by an operation with higher precedence than the
unary operator (`(*x as T).foo()` would become `*x.foo()`, which changes
what the `*` applies on).
The same is true if the expression encompassing the cast expression is a
unary expression or an addressof expression.

The lint supports the latter case, but missed the former one. This PR
fixes that.

Fixes #11968
2024-02-27 16:27:12 +01:00
Philipp Krones
7be6e2178e Merge commit '10136170fe9ed01e46aeb4f4479175b79eb0e3c7' into clippy-subtree-update 2024-02-27 15:50:17 +01:00
Guillaume Gomez
f30138623b Update ui tests 2024-02-27 15:22:39 +01:00
Guillaume Gomez
28738234ac Add ui test for mixed_attributes_style 2024-02-27 15:22:39 +01:00
Ethiraric
03bb7908b9 [map_entry]: Check insert expression for map use
The lint makes sure that the map is not used (borrowed) before the call
to `insert`. Since the lint creates a mutable borrow on the map with the
`Entry`, it wouldn't be possible to replace such code with `Entry`.
However, expressions up to the `insert` call are checked, but not
expressions for the arguments of the `insert` call itself. This commit
fixes that.

Fixes #11935
2024-02-27 15:20:49 +01:00
Oli Scherer
592fe89997 lower bstr version requirement to 1.6.0 2024-02-27 13:34:01 +00:00
bors
e33cba523a Auto merge of #12126 - teor2345:patch-1, r=llogiq
Fix sign-handling bugs and false negatives in `cast_sign_loss`

**Note: anyone should feel free to move this PR forward, I might not see notifications from reviewers.**

changelog: [`cast_sign_loss`]: Fix sign-handling bugs and false negatives

This PR fixes some arithmetic bugs and false negatives in PR #11883 (and maybe earlier PRs).
Cc `@J-ZhengLi`

I haven't updated the tests yet. I was hoping for some initial feedback before adding tests to cover the cases listed below.

Here are the issues I've attempted to fix:

#### `abs()` can return a negative value in release builds

Example:
```rust
i32::MIN.abs()
```
https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=022d200f9ef6ee72f629c0c9c1af11b8

Docs: https://doc.rust-lang.org/std/primitive.i32.html#method.abs

Other overflows that produce negative values could cause false negatives (and underflows could produce false positives), but they're harder to detect.

#### Values with uncertain signs can be positive or negative

Any number of values with uncertain signs cause the whole expression to have an uncertain sign, because an uncertain sign can be positive or negative.

Example (from UI tests):
```rust
fn main() {
    foo(a: i32, b: i32, c: i32) -> u32 {
        (a * b * c * c) as u32
        //~^ ERROR: casting `i32` to `u32` may lose the sign of the value
    }

    println!("{}", foo(1, -1, 1));
}
```
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=165d2e2676ee8343b1b9fe60db32aadd

#### Handle `expect()` the same way as `unwrap()`

Since we're ignoring `unwrap()` we might as well do the same with `expect()`.

This doesn't seem to have tests but I'm happy to add some like `Some(existing_test).unwrap() as u32`.

#### A negative base to an odd exponent is guaranteed to be negative

An integer `pow()`'s sign is only uncertain when its operants are uncertain. (Ignoring overflow.)

Example:
```rust
((-2_i32).pow(3) * -2) as u32
```

This offsets some of the false positives created by one or more uncertain signs producing an uncertain sign. (Rather than just an odd number of uncertain signs.)

#### Both sides of a multiply or divide should be peeled recursively

I'm not sure why the lhs was peeled recursively, and the rhs was left intact. But the sign of any sequence of multiplies and divides is determined by the signs of its operands. (Ignoring overflow.)

I'm not sure what to use as an example here, because most expressions I want to use are const-evaluable.

But if `p()` is [a non-const function that returns a positive value](https://doc.rust-lang.org/std/primitive.i32.html#method.isqrt), and if the lint handles unary negation, these should all lint:
```rust
fn peel_all(x: i32) {
    (-p(x) * -p(x) * -p(x)) as u32;
    ((-p(x) * -p(x)) * -p(x)) as u32;
    (-p(x) * (-p(x) * -p(x))) as u32;
}
```

#### The right hand side of a Rem doesn't change the sign

Unlike Mul and Div,
> Given remainder = dividend % divisor, the remainder will have the same sign as the dividend.
https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators

I'm not sure what to use as an example here, because most expressions I want to use are const-evaluable.

But if `p()` is [a non-const function that returns a positive value](https://doc.rust-lang.org/std/primitive.i32.html#method.isqrt), and if the lint handles unary negation, only the first six expressions should lint.

The expressions that start with a constant should lint (or not lint) regardless of whether the lint supports `p()` or unary negation, because only the dividend's sign matters.

Example:
```rust
fn rem_lhs(x: i32) {
    (-p(x) % -1) as u32;
    (-p(x) % 1) as u32;
    (-1 % -p(x)) as u32;
    (-1 % p(x)) as u32;
    (-1 % -x) as u32;
    (-1 % x) as u32;
    // These shouldn't lint:
    (p(x) % -1) as u32;
    (p(x) % 1) as u32;
    (1 % -p(x)) as u32;
    (1 % p(x)) as u32;
    (1 % -x) as u32;
    (1 % x) as u32;
}
```

#### There's no need to bail on other expressions

When peeling, any other operators or expressions can be left intact and sent to the constant evaluator.

If these expressions can be evaluated, this offsets some of the false positives created by one or more uncertain signs producing an uncertain sign. If not, they end up marked as having uncertain sign.
2024-02-27 05:38:40 +00:00
bors
fb060815b3 Auto merge of #11136 - y21:enhance_read_line_without_trim, r=dswij
[`read_line_without_trim`]: detect string literal comparison and `.ends_with()` calls

This lint now also realizes that a comparison like `s == "foo"` and calls such as `s.ends_with("foo")` will fail if `s` was initialized by a call to `Stdin::read_line` (because of the trailing newline).

changelog: [`read_line_without_trim`]: detect string literal comparison and `.ends_with()` calls

r? `@giraffate` assigning you because you reviewed #10970 that added this lint, so this is kinda a followup PR ^^
2024-02-27 03:36:12 +00:00
bors
d12b53e481 Auto merge of #12116 - J-ZhengLi:issue12101, r=Alexendoo
fix suggestion error in [`useless_vec`]

fixes: #12101

---

changelog: fix suggestion error in [`useless_vec`]

r+ `@matthiaskrgr` since they opened the issue?
2024-02-26 22:38:24 +00:00
y21
fd85db3636 restructure lint code, update description, more cases 2024-02-26 20:24:46 +01:00
bors
1c5094878b Auto merge of #12342 - lucarlig:empty-docs, r=llogiq
Empty docs

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

changelog: [`empty_doc`]: Detects documentation that is empty.
changelog: Doc comment lints now trigger for struct field and enum variant documentation
2024-02-26 18:03:13 +00:00
Ethiraric
97dc4b22c6 [box_default]: Preserve required path segments
When encountering code such as:
```
Box::new(outer::Inner::default())
```
clippy would suggest replacing with `Box::<Inner>::default()`, dropping
the `outer::` segment. This behavior is incorrect and that commit fixes
it.

What it does is it checks the contents of the `Box::new` and, if it is
of the form `A::B::default`, does a text replacement, inserting `A::B`
in the `Box`'s quickfix generic list.
If the source does not match that pattern (including `Vec::from(..)`
or other `T::new()` calls), we then fallback to the original code.

Fixes #11927
2024-02-26 17:39:00 +01:00
Samuel Tardieu
898ed8825d feat: make const_is_empty lint ignore external constants 2024-02-26 09:54:19 +01:00
Samuel Tardieu
1159e2c00f feat: add more tests for the const_is_empty lint
Suggested by @xFredNet and @matthiaskrgr.
2024-02-26 09:03:46 +01:00
Samuel Tardieu
288497093b feat: extend const_is_empty with many kinds of constants 2024-02-26 08:58:18 +01:00
Samuel Tardieu
89b334d47c chore: update some tests to allow const_is_empty 2024-02-26 08:51:28 +01:00
Samuel Tardieu
dbfbd0e77f feat: add const_is_empty lint 2024-02-26 08:51:28 +01:00
bors
aa2c94e416 Auto merge of #12308 - y21:more_implied_bounds, r=xFrednet
Look for `implied_bounds_in_impls` in more positions

With this, we lint `impl Trait` implied bounds in more positions:
- Type alias impl trait
- Associated type position impl trait
- Argument position impl trait
  - these are not opaque types, but instead are desugared to `where` clauses, so we need extra logic for finding them (`check_generics`), however the rest of the logic is the same

Before this, we'd only lint RPIT `impl Trait`s.
"Hide whitespaces" and reviewing commits individually might make this easier

changelog: [`implied_bounds_in_impls`]: start linting implied bounds in APIT, ATPIT, TAIT
2024-02-25 22:20:37 +00:00
y21
bbfe1c1ec3 lint implied bounds in APIT 2024-02-25 23:12:28 +01:00
y21
ec29b0d6b8 lint implied bounds in *all* opaque impl Trait types 2024-02-25 23:09:59 +01:00
bors
b8fb8907ba Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
Implement RFC 3373: Avoid non-local definitions in functions

This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-25 19:11:06 +00:00
lucarlig
d84d9d32f1 lint on variant and fields as well 2024-02-25 22:33:16 +04:00
lucarlig
f32e92cdc9 add 1 more test and dont trim other code 2024-02-25 21:18:38 +04:00
y21
9a56153c5e [single_call_fn]: merge post-crate visitor into lint pass 2024-02-25 17:13:47 +01:00
bors
c469cb0023 Auto merge of #12336 - not-elm:fix/issue-12243, r=y21
FIX(12243): redundant_guards

Fixed #12243

changelog: Fix[`redundant_guards`]

I have made a correction so that no warning does  appear when y.is_empty() is used within a constant function as follows.

```rust
pub const fn const_fn(x: &str) {
    match x {
        // Shouldn't lint.
        y if y.is_empty() => {},
        _ => {},
    }
}
```
2024-02-25 14:56:07 +00:00
lucarlig
5a50cede29 add single letter test 2024-02-25 18:01:53 +04:00
lucarlig
ee0cbeaa77 ignore empty comment in semicolon_if_nothing_returned 2024-02-25 17:41:41 +04:00
lucarlig
a3fea80a68 bless tests 2024-02-25 17:04:58 +04:00
lucarlig
84219f45a3 working naive with outside check_attrs 2024-02-25 16:11:14 +04:00
not-elm
5a63cd82cb FIX(12243): redundant_guard
A warning is now suppressed when "<str_va> if <str_var>.is_empty" is used in a constant function.

FIX: instead of clippy_util::in_const

FIX: Merged `redundant_guards_const_fn.rs` into `redundant_guards.rs`.
2024-02-25 15:38:18 +09:00
lucarlig
3093b291f6 WIP: empty doc span is still broken 2024-02-25 09:55:58 +04:00
Guillaume Gomez
a1971414ec Update ui tests 2024-02-24 15:02:10 +01:00
Guillaume Gomez
40cff2d99f Add ui test for unnecessary_get_then_check 2024-02-24 15:02:10 +01:00
bors
a2c1d565e5 Auto merge of #12259 - GuillaumeGomez:multiple-bound-locations, r=llogiq
Add new `multiple_bound_locations` lint

Fixes #7181.

r? `@llogiq`

changelog: Add new `multiple_bound_locations` lint
2024-02-24 13:43:34 +00:00
bors
64054693eb Auto merge of #12322 - sanxiyn:expression-with-attribute, r=llogiq
Be careful with expressions with attributes

Fix #9949.

changelog: [`unused_unit`]: skip expressions with attributes
2024-02-24 10:52:55 +00:00
Jason Newcomb
5ab42d8e6a Take lifetime extension into account in ref_as_ptr 2024-02-23 21:33:53 -05:00
Guillaume Gomez
762448bc55 Update ui tests 2024-02-23 17:38:39 +01:00
J-ZhengLi
929f746b5c fix the actual bug 2024-02-24 00:35:48 +08:00
Guillaume Gomez
6955a8ac4e Add ui test for multiple_bound_locations lint 2024-02-23 16:40:21 +01:00
MarcusGrass
f1974593c9
Remove double unused_imports check 2024-02-22 23:12:38 +01:00
MarcusGrass
97a3ac5b86
Allow unused_imports, and unused_import_braces on use 2024-02-22 21:53:04 +01:00
Philipp Krones
8a58b7613d
Update i686 asm test stderr 2024-02-22 16:27:24 +01:00
Philipp Krones
dc0bb69e66
Merge remote-tracking branch 'upstream/master' into rustup 2024-02-22 15:59:29 +01:00
bors
d554bcad79 Auto merge of #12303 - GuillaumeGomez:unneedeed_clippy_cfg_attr, r=flip1995
Add `unnecessary_clippy_cfg` lint

Follow-up of https://github.com/rust-lang/rust-clippy/pull/12292.

r? `@flip1995`

changelog: Add `unnecessary_clippy_cfg` lint
2024-02-22 11:00:52 +00:00
Guillaume Gomez
cf6a14cea1 Add ui test for unneeded_clippy_cfg_attr 2024-02-22 11:55:31 +01:00
Christopher B. Speir
b72996e322 Add check for 'in_external_macro' and 'is_from_proc_macro' inside [infinite_loop] lint. 2024-02-21 16:34:07 -06:00
bors
250fd09405 Auto merge of #12324 - GuillaumeGomez:useless_allocation2, r=y21
Extend `unnecessary_to_owned` to handle `Borrow` trait in map types

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

Alternative to #12315.

r? `@y21`

changelog: Extend `unnecessary_to_owned` to handle `Borrow` trait in map types
2024-02-21 21:38:41 +00:00
Guillaume Gomez
d28146133c Add more ui tests for unnecessary_to_owned 2024-02-21 19:32:08 +01:00
taiga.watanabe
aa8a82ec26 FIX: issue-12279
----
UPDATE: add async block into test.

FIX: no_effect

Fixed asynchronous function parameter names with underscores so that warnings are not displayed when underscores are added to parameter names

ADD: test case
2024-02-21 23:26:29 +09:00
Seo Sanghyeon
cd45d5a81c Be careful with expressions with attributes 2024-02-20 22:18:49 +09:00
bors
ba2139afd6 Auto merge of #121087 - oli-obk:eager_const_failures, r=lcnr
Always evaluate free constants and statics, even if previous errors occurred

work towards https://github.com/rust-lang/rust/issues/79738

We will need to evaluate static items before the `definitions.freeze()` below, as we will start creating new `DefId`s (for nested allocations) within the `eval_static_initializer` query.

But even without that motivation, this is a good change. Hard errors should always be reported and not silenced if other errors happened earlier.
2024-02-20 09:02:34 +00:00
Oli Scherer
d136b05c1b Always evaluate free constants and statics, even if previous errors occurred 2024-02-19 22:11:13 +00:00
teor
6bc7c96bb3 cargo bless 2024-02-20 07:53:04 +10:00
teor
367a403367 Add test coverage for cast_sign_loss changes 2024-02-20 07:52:40 +10:00
teor
f40279ff7d Add some more test cases 2024-02-20 07:52:35 +10:00
teor
e74fe4362a Check for both signed and unsigned constant expressions 2024-02-20 07:51:21 +10:00
teor
47339d01f8 Bless fixed cast_sign_loss false negatives 2024-02-20 07:50:56 +10:00
Santiago Pastorino
16d5a2be3d Remove suspicious auto trait lint 2024-02-19 17:41:48 -03:00
bors
6aa5f1ac6f Auto merge of #12314 - Alexendoo:output-conflict-handling, r=flip1995
Default test output conflict handling to error

https://github.com/oli-obk/ui_test/pull/175 got rid of the `bool` that controlled the default handling so we need to specify it ourselves

r? `@flip1995`

changelog: none
2024-02-19 14:30:35 +00:00
Alex Macleod
f67c3f4bd8 Default test output conflict handling to error 2024-02-19 14:20:11 +00:00
roife
087c7c828d Add check for same guards in match_same_arms 2024-02-19 13:49:32 +00:00
bors
74f611f7fc Auto merge of #12306 - Alexendoo:dir-replacement, r=flip1995
Remove `$DIR` replacement

This won't cause problems because the old `$DIR` replacement was based on the parent of the test path, which for us is relative: 5471e0645a/tests/compile-test.rs (L122)

The new pattern being `"tests/{test_dir}"` is more clearly relative

That's why we have custom filters applied to the toml/cargo tests where absolute paths do appear in the output 5471e0645a/tests/compile-test.rs (L198-L202)

Removing it allows clicking the paths in the terminal

changelog: none

r? `@flip1995`
2024-02-19 09:20:07 +00:00
Victor Song
d1e8a5956f fix: make #[allow] work on field for pub_underscore_fields
Add test for future regression
2024-02-18 05:33:50 -06:00
Urgau
4d93edf346 Allow newly added non_local_definitions lint in clippy 2024-02-17 13:59:45 +01:00
Alex Macleod
1d107ab2be Remove $DIR replacement in test output 2024-02-17 12:34:54 +00:00
bors
5471e0645a Auto merge of #12305 - beetrees:asm-syntax, r=Manishearth
Ensure ASM syntax detect `global_asm!` and `asm!` only on x86 architectures

The ASM syntax lint is only relevant on x86 architectures, so this PR ensures it doesn't trigger on other architectures. This PR also makes the lints check `global_asm!` items as well as `asm!` expressions.

changelog: Check `global_asm!` items in the ASM syntax lints, and fix false positives on non-x86 architectures.
2024-02-17 01:54:24 +00:00
beetrees
9b5e4c6d57
Ensure ASM syntax detect global_asm! and asm! only on x86 architectures 2024-02-17 01:45:39 +00:00
Oli Scherer
c975c5f69e Bump ui_test version 2024-02-16 21:40:43 +01:00
bors
3b36b37258 Auto merge of #12294 - sanxiyn:min_ident_chars-trait-item, r=Jarcho
Check trait items in `min_ident_chars`

Fix #12237.

changelog: [`min_ident_chars`]: check trait items
2024-02-16 16:50:08 +00:00
bors
4fb9e12155 Auto merge of #11641 - Alexendoo:negative-redundant-guards, r=Jarcho
Allow negative literals in `redundant_guards`

changelog: none
2024-02-16 16:41:51 +00:00
bors
32c006ca94 Auto merge of #12292 - GuillaumeGomez:DEPRECATED_CLIPPY_CFG_ATTR, r=flip1995
Add new lint `DEPRECATED_CLIPPY_CFG_ATTR`

As discussed [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Is.20.60--cfg.20feature.3Dcargo-clippy.60.20deprecated.20or.20can.20it.20be.3F).

This lint suggests to replace `feature = "cargo-clippy"` with `clippy`.

r? `@flip1995`

changelog:  Add new lint `DEPRECATED_CLIPPY_CFG_ATTR`
2024-02-16 10:24:15 +00:00
Centri3
f0adfe74b6 lint new_without_default on const fns too 2024-02-16 01:28:44 -06:00
Guillaume Gomez
cd6f03a3e8 Add ui tests for DEPRECATED_CLIPPY_CFG_ATTR 2024-02-15 11:52:53 +01:00
Seo Sanghyeon
2526765fc8 Check trait items 2024-02-15 06:22:15 +09:00
Esteban Küber
ad7914f2e1 Fix msg for verbose suggestions with confusable capitalization
When encountering a verbose/multipart suggestion that has changes
that are only caused by different capitalization of ASCII letters that have
little differenciation, expand the message to highlight that fact (like we
already do for inline suggestions).

The logic to do this was already present, but implemented incorrectly.
2024-02-14 20:15:13 +00:00
Ethiraric
9492de509f [case_sensitive_file_extension_comparisons]: Don't trigger on digits-only extensions 2024-02-14 18:26:56 +01:00
Alex Macleod
b32d7c0631 Allow negative literals in redundant_guards 2024-02-14 13:31:02 +00:00
bors
2c3213f5c5 Auto merge of #12285 - Ethiraric:fix-8573, r=dswij
Ignore imported items in `min_ident_chars`

Suppress the `min_ident_chars` warning for items whose name we cannot control. Do not warn for `use a::b`, but warn for `use a::b as c`, since `c` is a local identifier.

Fixes #12232

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`min_ident_chars`]: Do not warn on non-local identifiers
2024-02-14 04:02:38 +00:00
bors
03113a9f05 Auto merge of #12275 - y21:incompatible_msrv_desugaring, r=Manishearth
[`incompatible_msrv`]: allow expressions that come from desugaring

Fixes #12273

changelog: [`incompatible_msrv`]: don't lint on the `IntoFuture::into_future` call desugared by `.await`
2024-02-13 22:03:15 +00:00
Ethiraric
c1c2c3e60c Ignore imported items in min_ident_chars
Suppress the `min_ident_chars` warning for items whose name we cannot
control. Do not warn for `use a::b`, but warn for `use a::b as c`, since
`c` is a local identifier.

Fixes #12232
2024-02-13 19:14:12 +01:00
bors
3e264ba13a Auto merge of #11881 - y21:issue11880, r=Alexendoo
[`implied_bounds_in_impls`]: avoid linting on overlapping associated tys

Fixes #11880

Before this change, we were simply ignoring associated types (except for suggestion purposes), because of an incorrect assumption (see the comment that I also removed).

For something like
```rs
trait X { type T; }
trait Y: X { type T; }

// Can't constrain `X::T` through `Y`
fn f() -> impl X<T = i32> + Y<T = u32> { ... }
```
We now avoid linting if the implied bound (`X<T = i32>`) "names" associated types that also exists in the implying trait (`trait Y`). Here that would be the case.
But if we only wrote `impl X + Y<T = u32>` then that's ok because `X::T` was never constrained in the first place.

I haven't really thought about how this interacts with GATs, but I think it's fine. Fine as in, it might create false negatives, but hopefully no false positives.

(The diff is slightly annoying because of formatting things. Really the only thing that changed in the if chain is extracting the `implied_by_def_id` which is needed for getting associated types from the trait, and of course actually checking for overlap)

cc `@Jarcho` ? idk if you want to review this or not. I assume you looked into this code a bit to find this bug.

changelog: [`implied_bounds_in_impls`]: avoid linting when associated type from supertrait can't be constrained through the implying trait bound
2024-02-13 17:05:03 +00:00
bors
3e3a09e2bb Auto merge of #12278 - GabrielBFern:master, r=Jarcho
[`mem_replace_with_default`] No longer triggers on unused expression

changelog:[`mem_replace_with_default`]: No longer triggers on unused expression

Change [`mem_replace_with_default`] to not trigger on unused expression because the lint from `#[must_use]` handle this case better.

fixes: #5586
2024-02-13 04:03:43 +00:00
Matthias Krüger
dbccecf375 Rollup merge of #118983 - Urgau:invalid_ref_casting-bigger-layout, r=oli-obk
Warn on references casting to bigger memory layout

This PR extends the [`invalid_reference_casting`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#invalid-reference-casting) lint (*deny-by-default*) which currently lint on `&T -> &mut T` casting to also lint on `&(mut) A -> &(mut) B` where `size_of::<B>() > size_of::<A>()` (bigger memory layout requirement).

The goal is to detect such cases:

```rust
let u8_ref: &u8 = &0u8;
let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) };
//~^ ERROR casting references to a bigger memory layout is undefined behavior

let mat3 = Mat3 { a: Vec3(0i32, 0, 0), b: Vec3(0, 0, 0), c: Vec3(0, 0, 0) };
let mat3 = unsafe { &*(&mat3 as *const _ as *const [[i64; 3]; 3]) };
//~^ ERROR casting references to a bigger memory layout is undefined behavior
```

This is added to help people who write unsafe code, especially when people have matrix struct that they cast to simple array of arrays.

EDIT: One caveat, due to the [`&Header`](https://github.com/rust-lang/unsafe-code-guidelines/issues/256) uncertainty the lint only fires when it can find the underline allocation.

~~I have manually tested all the new expressions that warn against Miri, and they all report immediate UB.~~

r? ``@est31``
2024-02-12 23:18:52 +01:00
bors
7dfa6ced9b Auto merge of #12266 - granddaifuku:fix/ice-12253-index-exceeds-usize, r=Manishearth
fix: ICE when array index exceeds usize

fixes #12253

This PR fixes ICE in `indexing_slicing` as it panics when the index of the array exceeds `usize`.

changelog: none
2024-02-12 19:08:14 +00:00
Urgau
f2064f7165 Avoid UB in clippy transmute_ptr_to_ptr UI test 2024-02-12 19:40:17 +01:00
bors
b0e7640fd7 Auto merge of #12267 - Jarcho:issue_12254, r=Alexendoo
Don't allow derive macros to silence `disallowed_macros`

fixes #12254

The implementation is a bit of a hack, but "works". A derive expanding to another derive won't work properly, but we shouldn't be linting those anyways.

changelog: `disallowed_macros`: Don't allow derive macros to silence their own expansion
2024-02-12 13:19:52 +00:00
Nicholas Nethercote
6fda300087 Tweak delayed bug mentions.
Now that we have both `delayed_bug` and `span_delayed_bug`, it makes
sense to use the generic term "delayed bug" more.
2024-02-12 18:39:20 +11:00
Gabriel Fernandes
83555914ed [mem_replace_with_default] No longer triggers on unused expression 2024-02-11 21:11:13 -03:00
bors
75f57cf4c2 Auto merge of #12248 - GuillaumeGomez:extend-NONMINIMAL_BOOL, r=blyxyas
Extend `NONMINIMAL_BOOL` lint

Fixes #5794.

r? `@blyxyas`

changelog: Extend `NONMINIMAL_BOOL` lint
2024-02-11 23:25:40 +00:00
Guillaume Gomez
5e7c437d41 Extend NONMINIMAL_BOOL to check inverted boolean values 2024-02-11 21:22:33 +01:00
Guillaume Gomez
a18e0a11f7 Extend NONMINIMAL_BOOL lint 2024-02-11 21:22:33 +01:00
y21
92616c0aaa [implied_bounds_in_impls]: avoid linting on overlapping associated types 2024-02-11 20:22:45 +01:00
bors
9b2021235a Auto merge of #12040 - J-ZhengLi:issue12016, r=y21
stop linting [`blocks_in_conditions`] on `match` with weird attr macro case

should fixes: #12016

---

changelog: [`blocks_in_conditions`] - fix FP on `match` with weird attr macro

This might not be the best solution, as the root cause (i think?) is the `span` of block was incorrectly given by the compiler?

I'm open to better solutions
2024-02-11 13:26:18 +00:00
J-ZhengLi
4cc7b7e092 stop linting [blocks_in_conditions] on match on proc macros 2024-02-12 04:16:11 +08:00