Commit Graph

16564 Commits

Author SHA1 Message Date
Alex Macleod
3259b48568 Migrate format_args.rs to rustc_ast::FormatArgs
No longer lints empty precisions `{:.}` as the spans aren't available
2023-03-28 12:22:22 +00:00
Matthias Krüger
d57abf382b Rollup merge of #108548 - jamen:master, r=compiler-errors
Clarify the 'use a constant in a pattern' error message

```rs
use std::borrow::Cow;

const ERROR_CODE: Cow<'_, str> = Cow::Borrowed("23505");

fn main() {
    let x = Cow::from("23505");

    match x {
        ERROR_CODE => {}
    }
}
```
```
error: to use a constant of type `Cow` in a pattern, `Cow` must be annotated with `#[derive(PartialEq, Eq)]`
 --> src/main.rs:9:9
  |
9 |         ERROR_CODE => {}
  |         ^^^^^^^^^^

error: could not compile `playground` due to previous error
```

It seems helpful to link to StructuralEq in this message. I was a little confused, because `Cow<'_, str>` implements PartialEq and Eq, but they're not derived, which I learned is necessary for structural equality and using constants in patterns (thanks to the Rust community Discord server)

For tests, should I update every occurrence of this message? I see tests where this is still a warning and I'm not sure if I should update those.
2023-03-28 07:01:08 +02:00
Michael Goulet
fc6262fa0c Add (..) syntax for RTN 2023-03-28 01:14:28 +00:00
Guillaume Gomez
538e8bdcc8 Rollup merge of #109354 - Swatinem:rm-closureid, r=compiler-errors
Remove the `NodeId` of `ast::ExprKind::Async`

This is a followup to https://github.com/rust-lang/rust/pull/104833#pullrequestreview-1314537416.

In my original attempt, I was using `LoweringContext::expr`, which was not correct as it creates a fresh `DefId`.
It now uses the correct `DefId` for the wrapping `Expr`, and also makes forwarding `#[track_caller]` attributes more explicit.
2023-03-27 18:56:19 +02:00
Jamen Marz
28b80059ed Add notes to non-structural const in pattern error message 2023-03-27 11:08:11 -04:00
bors
70db22648b Auto merge of #10528 - bluthej:clear-with-drain, r=llogiq
Clear with drain

changelog: [`clear_with_drain`]: Add new lint

Fixes #9339
2023-03-27 11:41:48 +00:00
bluthej
df65d21f4c Include tests where the iterator is used later 2023-03-27 11:11:40 +02:00
bors
5698f43f94 Auto merge of #10552 - Alexendoo:unnecessary-struct-initialization-nursery, r=flip1995
Move unnecessary_struct_initialization to nursery

changelog: none, assuming it makes into the same release as #10489

Mostly because of #10547 but there is also #10548
2023-03-27 09:11:05 +00:00
Micha White
76d13bb7fa
Don't lint functions with "box" in their name 2023-03-26 17:49:57 -04:00
Micha White
a143fb7a11
Avoid breaking exported API 2023-03-26 17:49:57 -04:00
Micha White
1b55c81db5
Lint on trait declarations, not implementations 2023-03-26 17:49:56 -04:00
Micha White
022f76d432
Added the new lint with some docs and tests 2023-03-26 17:49:46 -04:00
Michael Goulet
db4e4afce8 Don't elaborate non-obligations into obligations 2023-03-26 20:33:54 +00:00
bluthej
3966580c9d Add tests with usize::MIN 2023-03-26 19:12:37 +02:00
bluthej
2493be2196 Improve is_range_full implementation
Make this function work with signed integer types by extracting the
underlying type and finding the min and max values.

Change the signature to make it more consistent:
- The range is now given as an `Expr` in order to extract the type
- The container's path is now passed, and only as an `Option` so that
  the function can be called in the general case without a container
2023-03-26 19:12:36 +02:00
bluthej
ee0de538d4 Add some tests 2023-03-26 19:12:36 +02:00
bluthej
1d168b31c3
Merge branch 'rust-lang:master' into clear-with-drain 2023-03-26 19:11:38 +02:00
Alex Macleod
a6f56cbdba Move unnecessary_struct_initialization to nursery 2023-03-26 14:21:58 +00:00
bors
5ed64d4c61 Auto merge of #10496 - J-ZhengLi:issue_10366, r=Alexendoo
fix [`cast_possible_truncation`] offering wrong suggestion for casting float to integer

fixes: #10366

---

changelog: [`cast_possible_truncation`] Fix incorrect suggestions when casting from float types or to `_`
2023-03-25 13:11:46 +00:00
bors
27edc2af06 Auto merge of #10531 - Nilstrieb:linklink, r=giraffate
Add explanation on how to run `cargo-clippy` and `clippy-driver`

I don't know how this would be done on Windows or MacOS, feedback appreciated.

I did find this snippet for MacOS but it seems a little sketchy.

1d1e72308e/.github/workflows/clippy_bors.yml (L98-L102)

changelog: none
2023-03-25 03:30:44 +00:00
bors
f1b9105f87 Auto merge of #10454 - Alexendoo:transmutes-expressible-as-ptr-casts-parens, r=Jarcho
Wrap `transmutes_expressible_as_ptr_casts` suggestions in parentheses

changelog: [`transmutes_expressible_as_ptr_casts`]: Fix suggestion missing wrapping parentheses

Fixes #10449

r? `@Jarcho`

Is this the best way to go about this? `unused_parens` will catch the unnecessary ones but emitting them in the first place isn't ideal
2023-03-25 02:29:54 +00:00
J-ZhengLi
52c4dc65d9 fix [cast_possible_truncation] offering wrong suggestion when casting from float
suggest `try_into` when casting to wildcard type;
fix [`cast_possible_truncation`] suggesting useless parenthesis;

remove suggesting for float to float conversion in [`cast_possible_truncation`]

style nit
2023-03-25 09:26:43 +08:00
bors
ed6c15a64b Auto merge of #10541 - FixedThink:patch-1, r=llogiq
docs fix: unknown field `allowed-locales`

changelog: [`DISALLOWED_SCRIPT_IDENTS`]: Replace the nonexistent `allowed-locales` in the docs with `allowed-scripts`.
2023-03-24 22:33:05 +00:00
Nilstrieb
b782a071ad Add explanation on how to run cargo-clippy and clippy-driver 2023-03-24 16:26:22 +00:00
Alex Macleod
b13f99c7e7 Fix allow attribute, items from macros in items_after_statements 2023-03-24 15:33:14 +00:00
FixedThink
982c81ad28
docs fix: unknown field allowed-locales
changelog: fix: Replace the nonexistent `allowed-locales` in the `DISALLOWED_SCRIPT_IDENTS` docs with `allowed-scripts`.
2023-03-24 16:08:27 +01:00
Philipp Krones
8df896c076 Merge commit 'd5e2a7aca55ed49fc943b7a07a8eba05ab5a0079' into clippyup 2023-03-24 14:26:19 +01:00
bors
00e9372987 Auto merge of #10516 - Alexendoo:split-debuginfo, r=flip1995
Use `split-debuginfo = "unpacked"` for debug builds

On Windows this has no effect as it's unsupported. On macOS the default set by cargo is already unpacked so no effect there either

For Linux it shaves a bit off the rebuild time, for me in the case of a simple `touch` + `cargo build` it goes from 12s to 10s

It saves a good amount of disk space too, on `aarch64-unknown-linux-gnu` it saves 1.2GB for a plain `cargo build`, 3GB when also running `cargo dev` and `cargo test --no-run -F internal`

r? `@flip1995`

changelog: none
2023-03-24 12:53:04 +00:00
bors
d5e2a7aca5 Auto merge of #10539 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`
changelog: none
2023-03-24 12:40:28 +00:00
Philipp Krones
8134414e03
Bump nightly version -> 2023-03-24 2023-03-24 13:36:15 +01:00
Philipp Krones
62cba5d971
Merge remote-tracking branch 'upstream/master' into rustup 2023-03-24 13:36:09 +01:00
Michael Krasnitski
50d92d0b60 Add suggestions to extra_unused_type_parameters 2023-03-23 23:56:31 -04:00
Ben Kimock
f96e38becb Fix clippy 2023-03-23 20:19:45 -04:00
bors
c72c914d21 Auto merge of #10489 - samueltardieu:issue-10476, r=giraffate
New lint: detect unnecessary struct building

Fixes #10476.

Running this lint on the top 500 crates produced one hit (in `rust-lang/rust-bindgen`) and [a PR has been submitted there](https://github.com/rust-lang/rust-bindgen/pull/2440).

changelog: [`unnecessary_struct_initialization`]: new lint
2023-03-24 00:12:02 +00:00
Ben Kimock
765c6b865c A MIR transform that checks pointers are aligned 2023-03-23 18:23:06 -04:00
Samuel "Sam" Tardieu
d7d3dbf060 New lint: detect unnecessary struct building 2023-03-23 20:56:45 +01:00
Alex Macleod
ecc201253e Wrap transmutes_expressible_as_ptr_casts suggestions in parentheses 2023-03-23 18:58:10 +00:00
bors
58eb9964cc Auto merge of #108442 - scottmcm:mir-transmute, r=oli-obk
Add `CastKind::Transmute` to MIR

~~Nothing actually produces it in this commit, so I don't know how to test it, but it also means it shouldn't be possible for it to break anything.~~

Includes lowering `transmute` calls to it, so it's used.

Zulip Conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Good.20first.20isssue/near/321849610>
2023-03-23 18:43:04 +00:00
bors
f34590478b Auto merge of #109517 - matthiaskrgr:rollup-m3orqzd, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #108541 (Suppress `opaque_hidden_inferred_bound` for nested RPITs)
 - #109137 (resolve: Querify most cstore access methods (subset 2))
 - #109380 (add `known-bug` test for unsoundness issue)
 - #109462 (Make alias-eq have a relation direction (and rename it to alias-relate))
 - #109475 (Simpler checked shifts in MIR building)
 - #109504 (Stabilize `arc_into_inner` and `rc_into_inner`.)
 - #109506 (make param bound vars visibly bound vars with -Zverbose)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-23 12:35:05 +00:00
bors
be01b983c4 Auto merge of #10533 - Nilstrieb:cache, r=dswij
Significantly optimize `significant_drop_tightening`

The lint is very slow as it doesn't cache the deeply nested check for the attribute. If we cache it, we can reduce the time spent on checking `rustc_borrowck` from 28s to 9s, which is a nice improvement. In the profile, the time inside `has_sig_drop_attr` goes from 66% to 0.2%, which is a lot more reasonable.

<details>
<summary>Flame graphs</summary>

Before (all the tall `clippy` towers are `has_sig_drop_attr`):
![before](https://user-images.githubusercontent.com/48135649/227037243-bcd93bbe-a4ad-45c3-be25-2b021b12a5c0.svg)

After:
![after](https://user-images.githubusercontent.com/48135649/227040322-8d3f0448-18e3-4923-8187-c72df324a3fa.svg)
</details>

Fixes #10532

changelog: [`significant_drop_tightening`]: significantly optimized
2023-03-23 09:23:07 +00:00
Michael Goulet
b506eb5338 Rename AliasEq -> AliasRelate 2023-03-23 05:56:40 +00:00
Scott McMurray
8bdd54e8c6 Add CastKind::Transmute to MIR
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic.

Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
2023-03-22 15:15:41 -07:00
Nilstrieb
966d5b0e34 Cache has_sig_drop_attr for significant_drop_tightening
The lint is very slow as it doesn't cache the deeply nested check for
the attribute. If we cache it, we can reduce the time spent on checking
`rustc_borrowck` from 28s to 9s, which is a nice improvement. In the
profile, the time inside `has_sig_drop_attr` goes from 66% to 0.2%,
which is a lot more reasonable.

See the PR for nice graphs.
2023-03-22 22:22:16 +01:00
Alex Macleod
a90e5cc9af Use split-debuginfo = "unpacked" for debug builds 2023-03-22 18:42:58 +00:00
bors
1d1e72308e Auto merge of #10527 - samueltardieu:issue-10523, r=dswij
Do not propose to simplify a not expression coming from a macro

Fixes #10523

changelog: FP [`nonminimal_bool`]: do not propose to change code coming from a macro
2023-03-22 15:46:08 +00:00
bluthej
d56c941792
Merge branch 'rust-lang:master' into clear-with-drain 2023-03-22 11:15:23 +01:00
bluthej
e8ec242a61 Finish tests - add rustfix 2023-03-22 11:01:57 +01:00
bluthej
1d0acce984 Add test for partial range 2023-03-22 11:01:57 +01:00
bluthej
c7e3e304d5 Add the lint logic 2023-03-22 11:01:57 +01:00
bluthej
484c82e041 Update lint declaration 2023-03-22 11:01:57 +01:00