]> git.lizzy.rs Git - rust.git/log
rust.git
19 months agoAuto merge of #9796 - smoelius:issue-9771, r=flip1995
bors [Tue, 22 Nov 2022 12:50:08 +0000 (12:50 +0000)]
Auto merge of #9796 - smoelius:issue-9771, r=flip1995

Fix #9771 (`unnecessary_to_owned` false positive)

Fixes #9771

In that issue's example(s), the lint tried to add a `&` to a value, which implicitly changed the type of a field to a reference. The fix is to add the reference to `receiver_ty` (the type of the receiver of the `to_owned`-like method), before passing `receiver_ty` to `can_change_type`. `can_change_type` properly rejects the modified `receiver_ty`.

cc: `@mikerite` just because I think he was the author of `can_change_type`.

changelog: fix `unnecessary_to_owned` false positive which implicitly tried to change the type of a field to a reference

19 months agoAuto merge of #9745 - matttpt:fix-redundant-closure-for-method-calls-suggestion,...
bors [Tue, 22 Nov 2022 09:20:50 +0000 (09:20 +0000)]
Auto merge of #9745 - matttpt:fix-redundant-closure-for-method-calls-suggestion, r=flip1995

Fix `redundant_closure_for_method_calls` suggestion

Fixes #7746. The issue turns out to be more general than raw pointers. The `redundant_closure_for_method_calls` lint produces incorrect suggestions when the method is associated with a type that must be enclosed in angle brackets or must be written with generic arguments substituted. For example:

```rust
fn main() {
    // Clippy's suggestion: [T; N]::as_slice
    // Correct suggestion:  <[u8; 3]>::as_slice
    let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]);
    array_opt.map(|a| a.as_slice());

    // Clippy's suggestion: [T]::len
    // Correct suggestion:  <[u8]>::len
    let slice_opt: Option<&[u8]> = Some(b"slice");
    slice_opt.map(|s| s.len());

    // Clippy's suggestion: *const T::is_null
    // Correct suggestion:  <*const usize>::is_null
    let ptr_opt: Option<*const usize> = Some(&487);
    ptr_opt.map(|p| p.is_null());

    // Clippy's suggestion: dyn TestTrait::method_on_dyn
    // Correct suggestion:  <dyn TestTrait>::method_on_dyn
    let test_struct = TestStruct {};
    let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct);
    dyn_opt.map(|d| d.method_on_dyn());
}

// For the trait object example:
trait TestTrait {}
struct TestStruct {}
impl TestTrait for TestStruct {}

impl dyn TestTrait + '_ {
    fn method_on_dyn(&self) -> bool {
        false
    }
}
```

The issue also affects references and tuples, though I had to patch the standard library with non-trait methods for those types to test that. Just in case, I also included handling for `!`, since it appeared to be possible to call methods on it with angle brackets. I just couldn't verify the resulting suggestion, since dead-code analysis eliminates the code first.

This is my first exposure to Rust compiler internals, so please let me know if I'm taking the wrong approach here!

changelog: [`redundant_closure_for_method_calls`]: add angle brackets and substitute generic arguments in suggestion when needed

19 months agoAuto merge of #9770 - sgued:missnamed-getters, r=llogiq
bors [Mon, 21 Nov 2022 19:51:42 +0000 (19:51 +0000)]
Auto merge of #9770 - sgued:missnamed-getters, r=llogiq

Add new lint  [`misnamed-getters`]

```
changelog: Add new lint  [`misnamed-getters`]
```

Closes #9769

The current lint matches all methods with a body of just one expression under the form `(&mut?)? <expr>.field` where field doesn't match the name of the method but there is a field of the same type in `<expr>` that matches the name. This allows matching nested structs, for example for newtype wrappers. This may cast the net a bit too wide and cause false positives. I'll run [clippy_lint_tester](https://github.com/mikerite/clippy_lint_tester) on the top crates to see how frequently false positives happen.

There also may be room for improvement by checking that the replacement field would work taking into account implementations of `Deref` and `DerefMut` even if the types don't exactly match but I don't know yet how this could be done.

19 months agoAuto merge of #9881 - flip1995:rustup, r=flip1995
bors [Mon, 21 Nov 2022 19:16:14 +0000 (19:16 +0000)]
Auto merge of #9881 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

It took >4 weeks, but I finally got to do the sync đźŽ‰

changelog: none

19 months agoFix custom ICE message test on windows
Philipp Krones [Mon, 21 Nov 2022 19:15:50 +0000 (20:15 +0100)]
Fix custom ICE message test on windows

19 months agopass clippy sysroot env if given r=ozkanonur
ozkanonur [Sat, 19 Nov 2022 23:40:31 +0000 (02:40 +0300)]
pass clippy sysroot env if given r=ozkanonur

Signed-off-by: ozkanonur <work@onurozkan.dev>
19 months agoBump nightly version -> 2022-11-21
Philipp Krones [Mon, 21 Nov 2022 19:02:14 +0000 (20:02 +0100)]
Bump nightly version -> 2022-11-21

19 months agoBump Clippy version -> 0.1.67
Philipp Krones [Mon, 21 Nov 2022 19:02:06 +0000 (20:02 +0100)]
Bump Clippy version -> 0.1.67

19 months agoMerge remote-tracking branch 'upstream/master' into rustup
Philipp Krones [Mon, 21 Nov 2022 18:59:07 +0000 (19:59 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

19 months agoAuto merge of #9873 - smoelius:move-line-span, r=flip1995
bors [Mon, 21 Nov 2022 11:07:32 +0000 (11:07 +0000)]
Auto merge of #9873 - smoelius:move-line-span, r=flip1995

Move `line_span` to source.rs

`line_span` is a non-public function used only in source.rs. It seems like it ought to go in source.rs.

changelog: none

19 months agoAuto merge of #9592 - c410-f3r:arith, r=Jarcho
bors [Sun, 20 Nov 2022 22:51:25 +0000 (22:51 +0000)]
Auto merge of #9592 - c410-f3r:arith, r=Jarcho

[arithmetic-side-effects] Detect overflowing associated constants of integers

Triggers the negation of maximum unsigned integers using associated constants. Rustc already handles `-128i8` but doesn't handle `-i8::MAX`.

At the same time, allows stuff like `-1234`.

changelog: FP: [arithmetic-side-effects] Detect overflowing associated constants of integers

19 months agoAuto merge of #9870 - koka831:unformat-unused-rounding, r=Jarcho
bors [Sun, 20 Nov 2022 22:09:25 +0000 (22:09 +0000)]
Auto merge of #9870 - koka831:unformat-unused-rounding, r=Jarcho

Keep original literal notation in suggestion

While I did some investigation of https://github.com/rust-lang/rust-clippy/issues/9866 (I couldn't reproduce it though) I found that `unused_rounding` formats as follows:

```rust
3.0_f64.round() // => 3.0f64
```

This PR makes them preserve as the original notation.

```rust
3.0_f64.round() // => 3.0_f64
```

changelog: Suggestion Enhancement: [`unused_rounding`]: The suggestion now preserves the original float literal notation

19 months agoFix many false negatives caused by autoderef
Sosthène Guédon [Sun, 20 Nov 2022 16:03:53 +0000 (17:03 +0100)]
Fix many false negatives caused by autoderef

19 months agoImprove diagnostic for cases where autoderef is used
Sosthène Guédon [Sun, 20 Nov 2022 14:34:56 +0000 (15:34 +0100)]
Improve diagnostic for cases where autoderef is used

19 months agoAuto merge of #9879 - Alexendoo:allow, r=Manishearth
bors [Sun, 20 Nov 2022 13:17:02 +0000 (13:17 +0000)]
Auto merge of #9879 - Alexendoo:allow, r=Manishearth

Fix `#[allow]` for `module_name_repetitions` & `single_component_path_imports`

Fixes #7511
Fixes #8768
Fixes #9401

`single_component_path_imports` needed some changes to the lint itself, it now buffers the found single component paths to emit in the equivalent `check_item`

changelog: Fix `#[allow(clippy::module_name_repetitions)]` and `#[allow(clippy::single_component_path_imports)]`

19 months agomisname-getters: Fix documentation
Sosthène Guédon [Sun, 20 Nov 2022 12:46:30 +0000 (13:46 +0100)]
misname-getters: Fix documentation

19 months agoRemove error when fields use autoderef
Sosthène Guédon [Sun, 20 Nov 2022 11:20:16 +0000 (12:20 +0100)]
Remove error when fields use autoderef

19 months agoAdd failing test
Sosthène Guédon [Sat, 12 Nov 2022 21:33:46 +0000 (22:33 +0100)]
Add failing test

19 months agomisnamed_getters: Trigger on unsafe with _unchecked
Sosthène Guédon [Wed, 2 Nov 2022 18:11:27 +0000 (19:11 +0100)]
misnamed_getters: Trigger on unsafe with _unchecked

19 months agoImprove code
Sosthène Guédon [Wed, 2 Nov 2022 18:02:46 +0000 (19:02 +0100)]
Improve code

19 months agoFix typo missnamed -> misnamed
Sosthène Guédon [Wed, 2 Nov 2022 08:01:33 +0000 (09:01 +0100)]
Fix typo missnamed -> misnamed

19 months agoFix internal warnings
Sosthène Guédon [Tue, 1 Nov 2022 20:49:20 +0000 (21:49 +0100)]
Fix internal warnings

19 months agoDocument missname_getters
Sosthène Guédon [Tue, 1 Nov 2022 20:36:18 +0000 (21:36 +0100)]
Document missname_getters

19 months agomissnamed_getters: use all_fields iterator
Sosthène Guédon [Tue, 1 Nov 2022 18:31:47 +0000 (19:31 +0100)]
missnamed_getters: use all_fields iterator

19 months agoFix suggestion to point to the whole method
Sosthène Guédon [Tue, 1 Nov 2022 18:28:06 +0000 (19:28 +0100)]
Fix suggestion to point to the whole method

19 months agomissnamed_getters: Match owned methods
Sosthène Guédon [Tue, 1 Nov 2022 18:07:51 +0000 (19:07 +0100)]
missnamed_getters: Match owned methods

19 months agoAdd missnamed_getters lint
Sosthène Guédon [Tue, 1 Nov 2022 17:39:36 +0000 (18:39 +0100)]
Add missnamed_getters lint

19 months agoFix `#[allow]` for module_name_repetitions & single_component_path_imports
Alex Macleod [Sat, 19 Nov 2022 18:13:17 +0000 (18:13 +0000)]
Fix `#[allow]` for module_name_repetitions & single_component_path_imports

19 months agoAuto merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=compiler-errors
bors [Sun, 20 Nov 2022 07:16:42 +0000 (07:16 +0000)]
Auto merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=compiler-errors

Minimal implementation of implicit deref patterns for Strings

cc `@compiler-errors` `@BoxyUwU` https://github.com/rust-lang/lang-team/issues/88 #87121

~~I forgot to add a feature gate, will do so in a minute~~ Done

19 months agoRollup merge of #104593 - compiler-errors:rpitit-object-safety-spans, r=fee1-dead
Matthias KrĂĽger [Sat, 19 Nov 2022 14:35:23 +0000 (15:35 +0100)]
Rollup merge of #104593 - compiler-errors:rpitit-object-safety-spans, r=fee1-dead

Improve spans for RPITIT object-safety errors

No reason why we can't point at the `impl Trait` that causes the object-safety violation.

Also [drive-by: Add is_async fn to hir::IsAsync](https://github.com/rust-lang/rust/pull/104593/commits/c4165f3a965e258531928180195637455299c6f3), which touches clippy too.

19 months agorefac: grab a snip from receiver
koka [Sat, 19 Nov 2022 12:21:47 +0000 (21:21 +0900)]
refac: grab a snip from receiver

19 months agoRemove unused
Caio [Sat, 19 Nov 2022 11:25:20 +0000 (08:25 -0300)]
Remove unused

19 months ago[arithmetic-side-effects] Detect overflowing associated constants of integers
Caio [Sat, 19 Nov 2022 11:22:27 +0000 (08:22 -0300)]
[arithmetic-side-effects] Detect overflowing associated constants of integers

19 months agoMove `line_span` to source.rs
Samuel Moelius [Fri, 18 Nov 2022 18:18:58 +0000 (18:18 +0000)]
Move `line_span` to source.rs

19 months agoAuto merge of #9800 - Alexendoo:def_path_res_multiple, r=dswij
bors [Sat, 19 Nov 2022 09:05:50 +0000 (09:05 +0000)]
Auto merge of #9800 - Alexendoo:def_path_res_multiple, r=dswij

Return multiple resolutions from `def_path_res`

Changes `def_path_res` to return all the resolutions matching the path rather than the first one (with a namespace hint that covered some cases).  This would fix any issues that come up with multiple versions of the same crate being present as they all have the same crate name

It also adds resolution of `impl _ {}` items for local items, and removes struct field resolution as it didn't seem to be used anywhere

I tested it on a local crate and it worked for the multiple crate issue, but I couldn't come up with a test that worked well with `// aux-build`, maybe `// aux-crate` after https://github.com/rust-lang/rust/pull/103266 could work but I'm not sure on that either

changelog: [`disallowed_methods`], [`disallowed_types`], [`disallowed_macros`]: fix path resolution with multiple versions of the same crate
changelog: [`disallowed_methods`]: Resolve methods in `impl`s in the current crate

19 months agodrive-by: Add is_async fn to hir::IsAsync
Michael Goulet [Sat, 19 Nov 2022 02:22:24 +0000 (02:22 +0000)]
drive-by: Add is_async fn to hir::IsAsync

19 months agoAuto merge of #104573 - matthiaskrgr:rollup-k36ybtp, r=matthiaskrgr
bors [Fri, 18 Nov 2022 20:26:58 +0000 (20:26 +0000)]
Auto merge of #104573 - matthiaskrgr:rollup-k36ybtp, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #101162 (Migrate rustc_resolve to use SessionDiagnostic, part # 1)
 - #103386 (Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting))
 - #103405 (Detect incorrect chaining of if and if let conditions and recover)
 - #103594 (Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets)
 - #104006 (Add variant_name function to `LangItem`)
 - #104494 (Migrate GUI test to use functions)
 - #104516 (rustdoc: clean up sidebar width CSS)
 - #104550 (fix a typo)

Failed merges:

 - #104554 (Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less)

r? `@ghost`
`@rustbot` modify labels: rollup

19 months agoAuto merge of #101562 - nnethercote:shrink-ast-Expr-harder, r=petrochenkov
bors [Fri, 18 Nov 2022 16:56:12 +0000 (16:56 +0000)]
Auto merge of #101562 - nnethercote:shrink-ast-Expr-harder, r=petrochenkov

Shrink `ast::Expr` harder

r? `@ghost`

19 months agoAuto merge of #9871 - koka831:fix/9864, r=xFrednet
bors [Fri, 18 Nov 2022 16:04:18 +0000 (16:04 +0000)]
Auto merge of #9871 - koka831:fix/9864, r=xFrednet

Allow manual swap in const fn

Fix https://github.com/rust-lang/rust-clippy/issues/9864

changelog: Fix [`manual_swap`]: No longer lints in constant code

19 months agoNote about const fn
koka [Fri, 18 Nov 2022 15:28:02 +0000 (00:28 +0900)]
Note about const fn

Since `std::mem::swap` is not stable as a const fn, the suggestion
would not be applicable in that cases

19 months agoAuto merge of #9855 - Alexendoo:needless-borrowed-ref-extra, r=xFrednet
bors [Fri, 18 Nov 2022 14:26:50 +0000 (14:26 +0000)]
Auto merge of #9855 - Alexendoo:needless-borrowed-ref-extra, r=xFrednet

Extend `needless_borrowed_reference` to structs and tuples, ignore _

changelog: [`needless_borrowed_reference`]: Lint struct and tuple patterns, and patterns containing `_`

Now lints patterns like

```rust
&(ref a, ref b)
&Tuple(ref a, ref b)
&Struct { ref a, ref b }

&(ref a, _)
```

19 months agoRollup merge of #104006 - flip1995:lang-items-clippy, r=oli-obk
Matthias KrĂĽger [Fri, 18 Nov 2022 13:13:37 +0000 (14:13 +0100)]
Rollup merge of #104006 - flip1995:lang-items-clippy, r=oli-obk

Add variant_name function to `LangItem`

Clippy has an internal lint that checks for the usage of hardcoded def paths and suggests to replace them with a lang or diagnostic item, if possible. This was implemented with a hack, by getting all the variants of the `LangItem` enum and then index into it with the position of the `LangItem` in the `items` list. This is no longer possible, because the `items` list can't be accessed anymore.

Follow up to #103603

cc `@camsteffen`
r? `@oli-obk`

This is blocking the sync between Clippy and Rust. I'm not sure if this is the best solution here, or if I should add a method `items()` to `LanguageItems` and keep the code in Clippy unchanged.

19 months agoAllow manual swap in const fn
koka [Fri, 18 Nov 2022 12:51:43 +0000 (21:51 +0900)]
Allow manual swap in const fn

19 months agoKeep original literal notation in suggestion
koka [Fri, 18 Nov 2022 12:23:16 +0000 (21:23 +0900)]
Keep original literal notation in suggestion

19 months agoAuto merge of #9863 - smoelius:expect-unwrap-used-typo, r=flip1995
bors [Fri, 18 Nov 2022 11:49:47 +0000 (11:49 +0000)]
Auto merge of #9863 - smoelius:expect-unwrap-used-typo, r=flip1995

Fix typo in `expect_used` and `unwrap_used` warning messages

"\`an Option\`" -> "an \`Option\`" and "\`a Result\`" -> "a \`Result\`".

changelog: fix typo in `expect_used` and `unwrap_used` warning messages

19 months agoAuto merge of #9850 - pheki:fix-7499-missing-ref, r=dswij
bors [Fri, 18 Nov 2022 09:43:51 +0000 (09:43 +0000)]
Auto merge of #9850 - pheki:fix-7499-missing-ref, r=dswij

Preserve `ref` on `infallible_destructuring_match` suggestion

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

changelog: [`infallible_destructuring_match`]: Preserve `ref` on suggestion

19 months agoAuto merge of #9858 - DesmondWillowbrook:never_loop, r=dswij
bors [Fri, 18 Nov 2022 09:31:20 +0000 (09:31 +0000)]
Auto merge of #9858 - DesmondWillowbrook:never_loop, r=dswij

`never_loop`: don't emit AlwaysBreaks if it targets a block

ref: https://github.com/rust-lang/rust-clippy/pull/9837#issuecomment-1312788194

The previous fix (#9837) was too simple and ignored all break commands inside a labelled block, regardless of whether their destination was a labelled block or a loop. This fix tracks all the labelled blocks in scope to ensure that only breaks targeting loops are considered.

changelog: [`never_loop`]: prevent false negatives from `breaks` nested in labelled blocks

19 months agoRm diagnostic item, use lang item
Deadbeef [Tue, 5 Jul 2022 16:56:16 +0000 (16:56 +0000)]
Rm diagnostic item, use lang item

19 months agoRollup merge of #104483 - oli-obk:santa-clauses-make-goals, r=compiler-errors
Matthias KrĂĽger [Thu, 17 Nov 2022 21:33:19 +0000 (22:33 +0100)]
Rollup merge of #104483 - oli-obk:santa-clauses-make-goals, r=compiler-errors

Convert predicates into Predicate in the Obligation constructor

instead of having almost all callers do that.

This reduces a bit of boilerplate, and also paves the way for my work towards https://github.com/rust-lang/compiler-team/issues/531 (as it makes it easier to accept both goals and clauses where right now it only accepts predicates).

19 months agoAdd variant_name function to `LangItem`
Philipp Krones [Sat, 5 Nov 2022 14:08:37 +0000 (15:08 +0100)]
Add variant_name function to `LangItem`

Clippy has an internal lint that checks for the usage of hardcoded def
paths and suggests to replace them with a lang or diagnostic item, if
possible. This was implemented with a hack, by getting all the variants
of the `LangItem` enum and then index into it with the position of the
`LangItem` in the `items` list. This is no longer possible, because the
`items` list can't be accessed anymore.

19 months agoFix typo in `expect_used` and `unwrap_used` warning messages
Samuel Moelius [Thu, 17 Nov 2022 14:57:39 +0000 (14:57 +0000)]
Fix typo in `expect_used` and `unwrap_used` warning messages

19 months agoAuto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead
bors [Thu, 17 Nov 2022 07:42:27 +0000 (07:42 +0000)]
Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead

Record `LocalDefId` in HIR nodes instead of a side table

This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed.

This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.

19 months agoBox `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns.
Nicholas Nethercote [Thu, 8 Sep 2022 00:52:51 +0000 (10:52 +1000)]
Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns.

19 months agoAuto merge of #102944 - nnethercote:ast-Lit-third-time-lucky, r=petrochenkov
bors [Wed, 16 Nov 2022 23:03:14 +0000 (23:03 +0000)]
Auto merge of #102944 - nnethercote:ast-Lit-third-time-lucky, r=petrochenkov

Use `token::Lit` in `ast::ExprKind::Lit`.

Instead of `ast::Lit`.

Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing.

r? `@petrochenkov`

19 months agoAuto merge of #9859 - koka831:no-run-side-effect, r=Manishearth
bors [Wed, 16 Nov 2022 17:32:31 +0000 (17:32 +0000)]
Auto merge of #9859 - koka831:no-run-side-effect, r=Manishearth

Avoid generating files via doctest

When we run `cargo test` in `clippy_lints` directory, it will generate [`foo.txt`](https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/foo.txt) in the directory.
In order to avoid that, this PR adds `no_run` to rustdoc which contains `File::create`.

changelog: none

19 months agoAvoid generating files via doctest
koka [Wed, 16 Nov 2022 15:02:22 +0000 (00:02 +0900)]
Avoid generating files via doctest

When we run `cargo test` in `clippy_lints` directory, it will generate
`foo.txt` in the directory.
In order to avoid that, add `no_run` to rustdoc which contains
`File::create`.

19 months agoConvert predicates into Predicate in the Obligation constructor
Oli Scherer [Wed, 9 Nov 2022 10:49:28 +0000 (10:49 +0000)]
Convert predicates into Predicate in the Obligation constructor

19 months agocleanup and dedupe CTFE and Miri error reporting
Ralf Jung [Tue, 15 Nov 2022 11:06:20 +0000 (12:06 +0100)]
cleanup and dedupe CTFE and Miri error reporting

19 months agofix clippy suggestions
Kartavya Vashishtha [Wed, 16 Nov 2022 07:45:22 +0000 (13:15 +0530)]
fix clippy suggestions

19 months agoupdate tests
Kartavya Vashishtha [Wed, 16 Nov 2022 06:09:09 +0000 (11:39 +0530)]
update tests

19 months agodon't emit AlwaysBreaks if it targets a block
Kartavya Vashishtha [Wed, 16 Nov 2022 05:31:07 +0000 (11:01 +0530)]
don't emit AlwaysBreaks if it targets a block

Introduced an ignored_ids parameter.
Takes O(n^2) time in the worst case.

Can be changed to collect block ids in first phase,
and then filter with binary search in second.

19 months agoUse `token::Lit` in `ast::ExprKind::Lit`.
Nicholas Nethercote [Mon, 10 Oct 2022 02:40:56 +0000 (13:40 +1100)]
Use `token::Lit` in `ast::ExprKind::Lit`.

Instead of `ast::Lit`.

Literal lowering now happens at two different times. Expression literals
are lowered when HIR is crated. Attribute literals are lowered during
parsing.

This commit changes the language very slightly. Some programs that used
to not compile now will compile. This is because some invalid literals
that are removed by `cfg` or attribute macros will no longer trigger
errors. See this comment for more details:
https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773

19 months agoExtend `needless_borrowed_reference` to structs and tuples, ignore _
Alex Macleod [Tue, 15 Nov 2022 18:24:18 +0000 (18:24 +0000)]
Extend `needless_borrowed_reference` to structs and tuples, ignore _

19 months agoAuto merge of #9849 - koka831:fix/9748, r=Manishearth
bors [Tue, 15 Nov 2022 09:13:54 +0000 (09:13 +0000)]
Auto merge of #9849 - koka831:fix/9748, r=Manishearth

Allow return types for closures with lifetime binder

fix https://github.com/rust-lang/rust-clippy/issues/9748

changelog: Fix [`unused_unit`] Allow return types for closures with lifetime binder

19 months agoAuto merge of #9570 - nfejzic:lint-unchecked-duration-subtraction, r=llogiq
bors [Tue, 15 Nov 2022 06:09:10 +0000 (06:09 +0000)]
Auto merge of #9570 - nfejzic:lint-unchecked-duration-subtraction, r=llogiq

feat: lint unchecked subtraction of a 'Duration' from an 'Instant'

Hello all, I tried to tackle the open issue #9371 and this is what I came up with.

I have a difficulty currently - some tests are failing:

```
failures:
    [ui] ui/manual_instant_elapsed.rs
```

The `manual_instant_elapsed` is failing because of `Instant::now() - duration` test, this now gets also picked by `unchecked_duration_subtraction` lint.
What is the correct way to proceed in this case? Simply update the `.stderr` file for `manual_instant_elapsed` lint?

changelog: [`unchecked_duration_subtraction`]: Add lint for unchecked subtraction of a `Duration` from an `Instant`.

fixes #9371

19 months agoKeep `ref` on `infallible_destructuring_match` suggestion
Aphek [Tue, 15 Nov 2022 04:57:56 +0000 (01:57 -0300)]
Keep `ref` on `infallible_destructuring_match` suggestion

19 months agoAllow return types for closures with lifetime binder
koka [Tue, 15 Nov 2022 03:58:17 +0000 (12:58 +0900)]
Allow return types for closures with lifetime binder

19 months agodocs: import Instant and Duration in doctests
Nadir Fejzic [Mon, 14 Nov 2022 21:37:25 +0000 (22:37 +0100)]
docs: import Instant and Duration in doctests

19 months agofix: add extract_msrv_attr call to instan_subtraction lint pass
Nadir Fejzic [Mon, 14 Nov 2022 21:25:56 +0000 (22:25 +0100)]
fix: add extract_msrv_attr call to instan_subtraction lint pass

19 months agodocs: update unchecked duration subtraction lint doc
Nadir Fejzic [Mon, 14 Nov 2022 21:08:11 +0000 (22:08 +0100)]
docs: update unchecked duration subtraction lint doc

19 months agochore: update lint version of MANUAL_INSTAN_ELAPSED to 1.65
Nadir Fejzic [Mon, 14 Nov 2022 21:00:09 +0000 (22:00 +0100)]
chore: update lint version of MANUAL_INSTAN_ELAPSED to 1.65

19 months agoAuto merge of #9848 - lukas-code:vec-box, r=Jarcho
bors [Mon, 14 Nov 2022 15:54:45 +0000 (15:54 +0000)]
Auto merge of #9848 - lukas-code:vec-box, r=Jarcho

Fix `vec-box-size-threshold` off-by-one error

The docs for `vec-box-size-threshold` say "The size of the boxed type in bytes, where boxing in a `Vec` is allowed", but previously a boxed type of exactly that size wasn't allowed in `Vec`.

changelog: [`vec_box`]: Fix off-by-one error for `vec-box-size-threshold` configuration.

19 months agofix `vec-box-size-threshold` off-by-one error
Lukas Markeffsky [Mon, 14 Nov 2022 15:06:21 +0000 (16:06 +0100)]
fix `vec-box-size-threshold` off-by-one error

19 months agoFix clippy and rustdoc
Maybe Waffle [Sun, 13 Nov 2022 22:58:20 +0000 (22:58 +0000)]
Fix clippy and rustdoc

please, please, don't match on `Symbol::as_str`s, every time you do,
somewhere in the world another waffle becomes sad...

19 months agoAuto merge of #9837 - DesmondWillowbrook:never_loop, r=dswij
bors [Sun, 13 Nov 2022 15:44:14 +0000 (15:44 +0000)]
Auto merge of #9837 - DesmondWillowbrook:never_loop, r=dswij

fix never_loop false positive

fixes #9831

changelog: [`never_loop`]: fixed false positive on unconditional break in internal labeled block

19 months agoAuto merge of #9829 - hrxi:pr_or_fun_call, r=llogiq
bors [Sun, 13 Nov 2022 14:29:42 +0000 (14:29 +0000)]
Auto merge of #9829 - hrxi:pr_or_fun_call, r=llogiq

Make it clear that `or_fun_call` can be a false-positive

Also move it to nursery so that the false-positives can be dealt with.

CC #8574

changelog: [`or_fun_call`]: Mention false-positives, move to nursery.

19 months agoAuto merge of #9822 - Veykril:unnecessary-safety-doc, r=Jarcho
bors [Sun, 13 Nov 2022 14:18:04 +0000 (14:18 +0000)]
Auto merge of #9822 - Veykril:unnecessary-safety-doc, r=Jarcho

Add `unnecessary_safety_doc` lint

changelog: [`unnecessary_safety_doc`]: Add `unnecessary_safety_doc` lint

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

This lint does not trigger for private functions, just like `missing_safety_docs`. Reason for that was implementation simplicity and because I figured asking first would make more sense, so if it should trigger for private functions as well let me know and I'll fix that up as well.

19 months agoStore a LocalDefId in hir::Variant & hir::Field.
Camille GILLOT [Sun, 6 Nov 2022 19:46:55 +0000 (19:46 +0000)]
Store a LocalDefId in hir::Variant & hir::Field.

19 months agoAuto merge of #9698 - kraktus:xc_bool, r=xFrednet
bors [Sun, 13 Nov 2022 09:57:36 +0000 (09:57 +0000)]
Auto merge of #9698 - kraktus:xc_bool, r=xFrednet

 [`fn_params_excessive_bools`] Make it possible to allow the lint at the method level

changelog: FP: [`fn_params_excessive_bools`]: `#[allow]` now works on methods

fix https://github.com/rust-lang/rust-clippy/issues/9687

Tested without committing but `#[allow]`ing now works. Also rewrote the lint to be a late lint while at it :)
r? `@xFrednet`

19 months agoMake it clear that `or_fun_call` can be a false-positive
hrxi [Sat, 12 Nov 2022 21:26:09 +0000 (22:26 +0100)]
Make it clear that `or_fun_call` can be a false-positive

Also move it to nursery so that the false-positives can be dealt with.

CC #8574

19 months agoAuto merge of #9835 - koka831:fix/9035, r=Alexendoo
bors [Sat, 12 Nov 2022 21:07:18 +0000 (21:07 +0000)]
Auto merge of #9835 - koka831:fix/9035, r=Alexendoo

Avoid linting unsized mutable reference

fix https://github.com/rust-lang/rust-clippy/issues/9035

changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference

19 months agoAuto merge of #9836 - koka831:patch-9300, r=Alexendoo
bors [Sat, 12 Nov 2022 20:54:39 +0000 (20:54 +0000)]
Auto merge of #9836 - koka831:patch-9300, r=Alexendoo

Fix is_async_fn to check FnKind::Method

This is a follow-up PR of https://github.com/rust-lang/rust-clippy/pull/9828 to support also async methods.

changelog: [`cognitive_complexity`] support async method

r? `@Alexendoo`

19 months agofix never_loop false positive
Kartavya Vashishtha [Sat, 12 Nov 2022 15:06:30 +0000 (20:36 +0530)]
fix never_loop false positive

on unconditional break to internal labeled block

ref #9831

19 months agoFix is_async_fn to check FnKind::Method
koka [Sat, 12 Nov 2022 13:36:20 +0000 (22:36 +0900)]
Fix is_async_fn to check FnKind::Method

19 months agoAuto merge of #9834 - koka831:refac/manual-is-ascii-check, r=xFrednet
bors [Sat, 12 Nov 2022 11:44:22 +0000 (11:44 +0000)]
Auto merge of #9834 - koka831:refac/manual-is-ascii-check, r=xFrednet

refac: remove unnecessary mutability

refactor `manual_is_ascii_check` lint.

* remove unnecessary mutability
* fix typo

changelog: none

r? `@xFrednet`

19 months agoAvoid lint to unsized mutable reference
koka [Sat, 12 Nov 2022 11:31:25 +0000 (20:31 +0900)]
Avoid lint to unsized mutable reference

19 months agofix: use HasPlaceholders
koka [Sat, 12 Nov 2022 10:15:21 +0000 (19:15 +0900)]
fix: use HasPlaceholders
* remove unnecessary mutability
* fix typo

19 months agoIntroduce `ExprKind::IncludedBytes`
clubby789 [Mon, 31 Oct 2022 18:30:09 +0000 (18:30 +0000)]
Introduce `ExprKind::IncludedBytes`

19 months agoAuto merge of #9662 - ebobrow:result-large-err, r=dswij
bors [Fri, 11 Nov 2022 06:58:59 +0000 (06:58 +0000)]
Auto merge of #9662 - ebobrow:result-large-err, r=dswij

`result_large_err` show largest variants in err msg

fixes #9538

changelog: Sugg: [`result_large_err`]: Now show largest enum variants in error message

19 months agoAuto merge of #9830 - hrxi:pr_bool_to_int_with_if, r=Manishearth
bors [Thu, 10 Nov 2022 19:37:05 +0000 (19:37 +0000)]
Auto merge of #9830 - hrxi:pr_bool_to_int_with_if, r=Manishearth

Make `bool_to_int_with_if` a pedantic lint

In all the cases I've observed, it did not make the code clearer. Using bools as integer is frowned upon in some languages, in others it's simply not possible.

You can find comments on the original pull request #8131 that agree with this point of view.

changelog: [`bool_to_int_with_if`]: Change the categorization to pedantic

19 months agoMake `bool_to_int_with_if` a pedantic lint
hrxi [Thu, 10 Nov 2022 18:42:20 +0000 (19:42 +0100)]
Make `bool_to_int_with_if` a pedantic lint

In all the cases I've observed, it did not make the code clearer. Using
bools as integer is frowned upon in some languages, in others it's
simply not possible.

You can find comments on the original pull request #8131 that agree with
this point of view.

19 months agoAuto merge of #9828 - koka831:fix/9300, r=Alexendoo
bors [Thu, 10 Nov 2022 17:40:46 +0000 (17:40 +0000)]
Auto merge of #9828 - koka831:fix/9300, r=Alexendoo

fix: cognitive_complexity for async fn

fix https://github.com/rust-lang/rust-clippy/issues/9300

changelog: [`cognitive_complexity`] support async fn

19 months agofix: cognitive_complexity for async fn
koka [Thu, 10 Nov 2022 15:14:18 +0000 (00:14 +0900)]
fix: cognitive_complexity for async fn

19 months agofix: update lints
Nadir Fejzic [Thu, 10 Nov 2022 14:55:45 +0000 (15:55 +0100)]
fix: update lints

19 months agofix: remove (redundant) semicolon in lint suggestion
Nadir Fejzic [Tue, 8 Nov 2022 14:04:32 +0000 (15:04 +0100)]
fix: remove (redundant) semicolon in lint suggestion

19 months agofix: add rust-fix annotation to unckd. duration subtr. lint test
Nadir Fejzic [Tue, 8 Nov 2022 09:22:58 +0000 (10:22 +0100)]
fix: add rust-fix annotation to unckd. duration subtr. lint test

19 months agostyle: inline variables in `format!`
Nadir Fejzic [Mon, 7 Nov 2022 21:21:32 +0000 (22:21 +0100)]
style: inline variables in `format!`

19 months agotest: update tests for manual_instant_elapsed lint
Nadir Fejzic [Mon, 7 Nov 2022 20:37:04 +0000 (21:37 +0100)]
test: update tests for manual_instant_elapsed lint

19 months agorefactor: improve code re-use in InstantSubtraction lint pass
Nadir Fejzic [Mon, 7 Nov 2022 20:34:24 +0000 (21:34 +0100)]
refactor: improve code re-use in InstantSubtraction lint pass

19 months agodocs: update docs for unchecked duration subtr. lint
Nadir Fejzic [Mon, 7 Nov 2022 19:59:55 +0000 (20:59 +0100)]
docs: update docs for unchecked duration subtr. lint