Commit Graph

504 Commits

Author SHA1 Message Date
hotate29
0b6d1fdea2
refactor ``Sugg::BinOp`` 2021-12-25 00:29:29 +09:00
hotate29
b3b65a1bf6
Add test 2021-12-25 00:29:24 +09:00
Piotr Mikulski
01b7411482 Refactor 2021-12-23 22:00:20 -08:00
Piotr Mikulski
26cc55133e rewrite the PR 2021-12-23 21:41:25 -08:00
lcnr
d5cbae90f9 fix clippy 2021-12-23 11:17:03 +01:00
flip1995
eb47398773
Test clippy_utils in CI
This makes sure that the tests in clippy_utils are run in CI.

When looking into this I discovered that two tests were failing and
multiple doc tests were failing. This fixes those tests and enables a
few more doc tests.
2021-12-20 19:56:06 +01:00
bors
879eccead7 Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr`

This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
2021-12-19 09:31:37 +00:00
bors
af1eea3f0a Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa
Implement let-else type annotations natively

Tracking issue: #87335

Fixes #89688, fixes #89807, edit: fixes  #89960 as well

As explained in https://github.com/rust-lang/rust/issues/89688#issuecomment-940405082, the previous desugaring moved the let-else scrutinee into a dummy variable, which meant if you wanted to refer to it again in the else block, it had moved.

This introduces a new hir type, ~~`hir::LetExpr`~~ `hir::Let`, which takes over all the fields of `hir::ExprKind::Let(...)` and adds an optional type annotation. The `hir::Let` is then treated like a `hir::Local` when type checking a function body, specifically:

* `GatherLocalsVisitor` overrides a new `Visitor::visit_let_expr` and does pretty much exactly what it does for `visit_local`, assigning a local type to the `hir::Let` ~~(they could be deduplicated but they are right next to each other, so at least we know they're the same)~~
* It reuses the code in `check_decl_local` to typecheck the `hir::Let`, simply returning 'bool' for the expression type after doing that.

* ~~`FnCtxt::check_expr_let` passes this local type in to `demand_scrutinee_type`, and then imitates check_decl_local's pattern checking~~
* ~~`demand_scrutinee_type` (the blindest change for me, please give this extra scrutiny) uses this local type instead of of creating a new one~~
    * ~~Just realised the `check_expr_with_needs` was passing NoExpectation further down, need to pass the type there too. And apparently this Expectation API already exists.~~

Some other misc notes:

* ~~Is the clippy code supposed to be autoformatted? I tried not to give huge diffs but maybe some rustfmt changes simply haven't hit it yet.~~
* in `rustc_ast_lowering/src/block.rs`, I noticed some existing `self.alias_attrs()` calls in `LoweringContext::lower_stmts` seem to be copying attributes from the lowered locals/etc to the statements. Is that right? I'm new at this, I don't know.
2021-12-17 22:12:34 +00:00
hotate29
13ad14b22d
update: ``Sugg::not()`` replacing the comparison operator. #7320
When inverting an expression, the output is now like ```foo != 0``` instead of ```!(foo == 0)```, the comparison operator is now replaced.
2021-12-18 00:07:36 +09:00
flip1995
ece0946d7f Merge commit '23d11428de3e973b34a5090a78d62887f821c90e' into clippyup 2021-12-17 13:40:22 +01:00
flip1995
fad9407c5a
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-17 13:22:25 +01:00
Nicholas Nethercote
ecd4919ebb Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Nicholas Nethercote
a89a063ba0 Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Matthias Krüger
55df990a9b Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm
Stabilize `iter::zip`

Hello all!

As the tracking issue (#83574) for `iter::zip` completed the final commenting period without any concerns being raised, I hereby submit this stabilization PR on the issue.

As the pull request that introduced the feature (#82917) states, the `iter::zip` function is a shorter way to zip two iterators. As it's generally a quality-of-life/ergonomic improvement, it has been integrated into the codebase without any trouble, and has been
used in many places across the rust compiler and standard library since March without any issues.

For more details, I would refer to `@cuviper's` original PR, or the [function's documentation](https://doc.rust-lang.org/std/iter/fn.zip.html).
2021-12-15 01:28:08 +01:00
PFPoitras
288afb366a Remove iter::zip feature gate from clippy 2021-12-14 18:50:46 -04:00
Esteban Kuber
d8af82e4bb Fix clippy uses of QPath::LangItem 2021-12-13 17:09:16 +00:00
Samuel E. Moelius III
3807905e08 Handle to_vec on for loop expression #8069 2021-12-13 07:04:57 -05:00
Samuel E. Moelius III
290f74be4e Address review comments
* Share a list of methods with `implicit_clone`
* Ensure no overlap with `redundant_clone`
2021-12-13 06:31:17 -05:00
Samuel E. Moelius III
468c86e4a3 Add unnecessary_to_owned lint 2021-12-13 06:31:17 -05:00
Cormac Relf
17c1ff9faa let-else: use hir::Let in clippy
fix clippy format using `cargo fmt -p clippy_{lints,utils}`
manually revert rustfmt line truncations
rename to hir::Let in clippy
Undo the shadowing of various `expr` variables after renaming `scrutinee`
reduce destructuring of hir::Let to avoid `expr` collisions
cargo fmt -p clippy_{lints,utils}
bless new clippy::author output
2021-12-13 14:02:41 +11:00
bors
53059792e9 Auto merge of #8071 - GuillaumeGomez:method-must-use, r=xFrednet
Add new lint to warn when #[must_use] attribute should be used on a method

This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions).

Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312

I think it would reduce the number of cases of API misuses quite a lot.

What do you think?

---

changelog: Added new [`return_self_not_must_use`] lint
2021-12-08 19:09:25 +00:00
Guillaume Gomez
e93767b395 Apply new lint on clippy source code 2021-12-08 11:16:14 +01:00
Guillaume Gomez
8dfb3ec8a4 Add new lint to warn when #[must_use] attribute should be used on a method 2021-12-08 11:16:14 +01:00
Cameron Steffen
f690ef6f5c Refactors with peel_blocks 2021-12-06 12:33:02 -06:00
Cameron Steffen
284b63a687 Rename remove_blocks to peel_blocks 2021-12-06 12:33:02 -06:00
flip1995
8fea1d94f3 Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup 2021-12-06 12:33:31 +01:00
Yechan Bae
844996b42e Consider NonNull as a pointer type 2021-12-03 19:11:40 -05:00
bors
d5d830a50f Auto merge of #7463 - ThibsG:find_any_7392, r=xFrednet
Fix `any()` not taking reference in `search_is_some` lint

`find` gives reference to the item, but `any` does not, so suggestion is broken in some specific cases.

Fixes: #7392

changelog: [`search_is_some`] Fix suggestion for `any()` not taking item by reference
2021-12-02 17:27:54 +00:00
flip1995
ec57cc1455
Bump Clippy Version -> 0.1.59 2021-12-02 09:32:47 +00:00
bors
908815ce98 Auto merge of #8001 - Jarcho:unprefixed_strlen, r=giraffate
Improve `strlen_on_c_string`

fixes: #7436

changelog: lint `strlen_on_c_string` when used without a fully-qualified path
changelog: suggest removing the surrounding unsafe block for `strlen_on_c_string` when possible
2021-11-29 01:03:48 +00:00
ThibsG
a8e7fed172 Add a note about type annotation on closure param 2021-11-28 10:22:15 +01:00
ThibsG
917fdb11e4 Rewrite comment when handling special case for ProjectionKind::Deref 2021-11-27 20:32:50 +01:00
ThibsG
c5ce7ff6d9 Add Index when checking projs in a call, rename some variables and remove unneeded statements 2021-11-27 19:22:19 +01:00
flip1995
5740230ec7
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-23 11:22:34 +01:00
Cameron Steffen
e58ffb88e6 Fix Clippy with changed for loop desugar 2021-11-21 08:16:09 -06:00
ThibsG
092fe209a6 Move deref closure builder to clippy_utils::sugg module 2021-11-20 15:48:21 +01:00
Jason Newcomb
0d1f1cec44 Remove surrounding unsafe block in strlen_on_c_strings when possible 2021-11-19 21:14:51 -05:00
Jason Newcomb
c443f8fb95 Fix strlen_on_c_strings when not used with a full path 2021-11-19 20:02:49 -05:00
flip1995
731dfde267
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-18 12:22:00 +01:00
Jason Newcomb
2938ffd0d9 Improve heuristics for determining whether eager of lazy evaluation is preferred 2021-11-15 20:54:13 -05:00
bors
f82bf470d0 Auto merge of #7957 - surechen:fix_for_7854, r=giraffate
Support suggestion for #7854

I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.(Fixes #7854)

changelog: Make let_underscore_lock support parking_lot
2021-11-15 00:50:28 +00:00
surechen
634e79c655 Support suggestion for #7854
I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.

changelog: Make let_underscore_lock support parking_lot
2021-11-15 08:36:36 +08:00
bors
4f82dd83df Auto merge of #7948 - 5225225:castlosslessbool, r=llogiq
Lint for bool to integer casts in `cast_lossless`

The lint description says

> Checks for casts between *numerical* types that may be replaced by safe conversion functions.

Which is strictly speaking being violated here, but it seems within the spirit of the lint. I think it is still a useful lint to have, and having a different lint for just this feels excessive. Thoughts?

Fixes #7947

changelog: Lint for bool to integer casts in [`cast_lossless`]
2021-11-12 18:17:18 +00:00
xFrednet
e444cbe5d6
New index_refutable_slice lint
* Finding pattern slices for `avoidable_slice_indexing`
* `avoidable_slice_indexing` analysing slice usage
* Add configuration to `avoidable_slice_indexing`
* Emitting `avoidable_slice_indexing` with suggestions
* Dogfooding and fixing bugs
* Add ui-toml test for `avoidable_slice_indexing`
* Correctly suggest `ref` keywords for `avoidable_slice_indexing`
* Test and document `mut` for `avoid_slice_indexing`
* Handle macros with `avoidable_slice_indexing` lint
* Ignore slices with sub patterns in `avoidable_slice_indexing`
* Update lint description for `avoidable_slice_indexing`
* Move `avoidable_slice_indexing` to nursery
* Added more tests for `avoidable_slice_indexing`
* Update documentation and message for `avoidable_slice_indexing`
* Teach `avoidable_slice_indexing` about `HirId`s and `Visitors`
* Rename lint to `index_refutable_slice` and connected config
2021-11-11 17:34:02 +01:00
bors
3bfe98d372 Auto merge of #7813 - xFrednet:6492-lint-version, r=flip1995
Add Clippy version to Clippy's lint list

Hey, hey, the semester is finally over, and I wanted to get back into hacking on Clippy. It has also been some time since our metadata collection monster has been feed. So, this PR adds a new attribute `clippy::version` to document which version a lint was stabilized. I considered using `git blame` but that would be very hacky and probably not accurate.

I'm also thinking that this attribute can be used to have a `clippy::nightly` lint group which is allow-by-default that delays setting the actual lint group until the defined version is reached. Just something to consider regarding #6623 🙃

This PR only adds the version to 4 lints to keep it reviewable. I'll do a followup PR to add the version to other lints if the implementation is accepted 🙃

![image](https://user-images.githubusercontent.com/17087237/137118859-0aafdfdf-7595-4289-8ba4-33d58eb6991d.png)

Also, mobile approved xD

![image](https://user-images.githubusercontent.com/17087237/137118944-833cf7fb-a4a1-45d6-9af8-32c951822360.png)

---

r? `@flip1995`

cc: #7172

closes: #6492

changelog: [Clippy's lint list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays the version a lint was added. 🎉

---

Example lint declaration after this update:

```rs
declare_clippy_lint! {
    /// [...]
    ///
    /// ### Example
    /// ```rust
    /// // Bad
    /// let x = 3.14;
    /// // Good
    /// let x = std::f32::consts::PI;
    /// ```
    #[clippy::version = "pre 1.29.0"]
    pub APPROX_CONSTANT,
    correctness,
    "the approximate of a known float constant (in `std::fXX::consts`)"
}
```
2021-11-11 12:38:04 +00:00
dswij
2d037aa4a6 Check for no_std and no_core attribute in swap lint
This commit adds a `no_std` and `no_core` check on `swap` lint and additionally suggest `core::mem::swap` whenever possible.
Remove warning if both `std` and `core` is not present.
2021-11-11 12:30:07 +08:00
dswij
847a95b682 Refactor utils on checking attribute
Moved out reusable pieces from `is_automatically_derived` and
`any_parent_is_automatically_derived`.
2021-11-11 10:30:40 +08:00
xFrednet
7c1e62d962
Added clippy::version attribute as lint metadata 2021-11-10 19:48:29 +01:00
5225225
6e84f00045 Check MSRV for bool to int from impl 2021-11-09 17:35:35 +00:00
5225225
96db1d6bea fix dogfood lint on clippy_utils 2021-11-09 17:30:15 +00:00
bors
6536c586fe Auto merge of #90485 - camsteffen:fmt-args-less-bind, r=m-ou-se
Don't destructure args tuple in format_args!

This allows Clippy to parse the HIR more simply since `arg0` is changed to `_args.0`. (cc rust-lang/rust-clippy#7843). From rustc's perspective, I think this is something between a lateral move and a tiny improvement since there are fewer bindings.

r? `@m-ou-se`
2021-11-09 05:33:16 +00:00
bors
830f2205d4 Auto merge of #7944 - Serial-ATA:deprecated-cfg-attr-msrv, r=giraffate
Add MSRV to deprecated_cfg_attr

changelog: Add MSRV to [`deprecated_cfg_attr`]

closes: #7922
2021-11-09 00:58:37 +00:00
Serial
413d255916 Add MSRV to deprecated_cfg_attr 2021-11-08 17:53:50 -05:00
Vadim Petrochenkov
c063203c2b ast: Fix naming conventions in AST structures
TraitKind -> Trait
TyAliasKind -> TyAlias
ImplKind -> Impl
FnKind -> Fn

All `*Kind`s in AST are supposed to be enums.

Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order.

Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.
2021-11-07 21:38:17 +08:00
Cameron Steffen
9a8919d823 Fix Clippy with changed format_args! 2021-11-06 16:03:32 -05:00
Cameron Steffen
5239a90f70 Factor in some expr_visitor usages 2021-11-05 14:39:39 -05:00
Cameron Steffen
73501daa39 Add expr_visitor util 2021-11-05 14:16:56 -05:00
Cameron Steffen
14d54f0f6e Use Span::from_expansion instead of in_macro 2021-11-05 08:50:17 -05:00
flip1995
e674d0a599 Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup 2021-11-04 12:52:36 +00:00
bors
84a4ab7f3f Auto merge of #7928 - xFrednet:rust-90354-deploy-clippy-docs, r=flip1995
Reference `clippy_utils` docs on nightly-rustc and some other documentation updates

The `clippy_utils` crate is now part of the nightly-rustc documentation. See [**very beautiful documentation**](https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/). This PR references them in our documentation and updates some other documentation.

changelog: none
2021-11-04 12:27:50 +00:00
xFrednet
d134dddf70
Improve clippy_utils function docs 2021-11-04 12:42:29 +01:00
lyj
df9f5e4b22
Update diagnostics.rs 2021-11-04 11:57:14 +08:00
bors
2ebd535eae Auto merge of #7906 - smoelius:master, r=camsteffen
Fix #7903

Fixes #7903 (cc: `@Arnavion)`

changelog: none (bug is in same release)

r? `@camsteffen`
2021-11-02 14:06:36 +00:00
Samuel E. Moelius III
5edb02adad Fix #7903 2021-11-01 19:33:27 -04:00
Gary Guo
7e5f99ab58 Fix manual_assert for #![no_std] and Rust 2021 2021-11-01 15:47:33 +00:00
Michael Wright
e8c4046841 Simplify FullInt Ord impl
`cmp_s_u` is a tiny helper function only used by `cmp` and isn't useful on
it's own. Making it a nested function of `cmp` makes that clear and as a
bonus it's easier to call and doesn't require a `#[must_use]` attribute.
2021-10-30 06:22:19 +02:00
Michael Wright
4a86156c66 Simplify FullInt Ord impl (2) 2021-10-30 06:22:19 +02:00
Michael Wright
c6dca68eca Simplify FullInt Ord impl 2021-10-30 06:22:19 +02:00
Michael Wright
c8edd9a16e Remove casts from FullInt impl 2021-10-30 06:22:19 +02:00
Michael Wright
665ff57fde Remove expects from FullInt Partial{Ord,Eq} 2021-10-30 06:22:19 +02:00
bors
89a11564cc Auto merge of #7847 - mikerite:fix-7829, r=flip1995
Fix false positive in `match_overlapping_arm`

Fixes #7829

changelog: Fix false positive in [`match_overlapping_arm`].
2021-10-28 08:59:21 +00:00
bors
3ef1f19d60 Auto merge of #7873 - xFrednet:7869-string-index-ice, r=Manishearth
Update `str` utils to prevent ICEs and FNs

This PR reworks some string handling for lints regarding enum naming. I hope the refactoring will prevent future ICEs and help with new bug free implementations.

It might be better to review this PR by going through the commits, as `clippy_utils::camel_case` was renamed to `clippy_utils::str_utils` and then changed further. GH sadly doesn't really make the changes that obvious 🙃

Not too much more to say. Have a nice day 🌞

---

Fixes: rust-lang/rust-clippy#7869

changelog: ICE Fix: [`enum_variant_names`] #7869
2021-10-25 19:20:05 +00:00
xFrednet
7517ae2fb3 Refactored some string handling to prevent ICEs and FNs 2021-10-24 22:47:39 +02:00
xFrednet
d38fddd899 Refactor camel_case util functions for new StrIndex 2021-10-24 21:13:43 +02:00
Cameron Steffen
20fb7f2916 Update rustfmt 2021-10-24 12:52:38 -05:00
xFrednet
1b91d986ea Rename clippy_utils::camal_case to clippy_utils::str_utils 2021-10-24 17:42:13 +02:00
Dharma Saputra Wijaya
a5a3e6192d Fix typo on utils/lib 2021-10-23 23:42:31 +08:00
flip1995
7631fc5d82 Merge commit '91496c2ac6abf6454c413bb23e8becf6b6dc20ea' into clippyup 2021-10-21 13:11:36 +02:00
flip1995
122233091a
Bump Clippy Version -> 0.1.58 2021-10-21 12:19:32 +02:00
flip1995
085181e29d
Merge remote-tracking branch 'upstream/master' into rustup 2021-10-21 12:18:12 +02:00
Gary Guo
1788cfd95d Remove NullOp::Box 2021-10-20 19:42:35 +01:00
Michael Wright
4679eb3a0d Move const int value code to utils 2021-10-20 06:13:42 +02:00
Yuki Okushi
30cc96efce Rollup merge of #88860 - nbdd0121:panic, r=m-ou-se
Deduplicate panic_fmt

std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2021-10-20 04:35:14 +09:00
Andre Bogus
e88c956e1e avoid eq_op in test code 2021-10-19 21:02:30 +02:00
Gary Guo
ebf4f03f7d Remove begin_panic_fmt from clippy 2021-10-19 15:15:59 +01:00
r00ster91
599d9126a2 Some "parenthesis" and "parentheses" fixes 2021-10-17 12:04:01 +02:00
Samuel E. Moelius III
c9599d79a3 Add format_in_format_args and to_string_in_format_args lints
Fixes #7667 and #7729
2021-10-15 12:44:38 -04:00
Yechan Bae
03fed75c89 Address internal lints 2021-10-09 05:59:53 -04:00
Yechan Bae
de0d2b1500 Add testcases 2021-10-09 05:47:07 -04:00
Yechan Bae
b1aa3064b6 Address PR comments 2021-10-09 05:47:06 -04:00
Yechan Bae
dd9c8d32f2 Extract get_vec_init_kind and share it 2021-10-09 05:43:58 -04:00
Yechan Bae
759200b699 Handle PR feedbacks first round 2021-10-09 05:38:19 -04:00
Yechan Bae
452181c69d Implement uninit_vec lint 2021-10-09 05:38:19 -04:00
bors
a04a7cd9f9 Auto merge of #7779 - rust-lang:test_module, r=flip1995
make test module detection more strict

I started with some small improvements to clippy_utils/src/lib.rs, but then found that our "test" module detection would also catch words containing "test" like e.g. "attestation". So I made this a bit more strict (splitting by `'_'` and checking for `test` or `tests`), adding a test case as I went.

---

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

changelog: none
2021-10-07 09:36:51 +00:00
flip1995
5cf4984872 Merge commit 'b7f3f7f6082679da2da9a0b3faf1b5adef3afd3b' into clippyup 2021-10-07 11:21:30 +02:00
flip1995
9613df9c85
Allow invalid-paths for regex paths 2021-10-07 11:12:02 +02:00
flip1995
1f955158dd
Merge remote-tracking branch 'upstream/master' into rustup 2021-10-07 11:11:23 +02:00
Andre Bogus
86811e9b1b make test module detection more strict 2021-10-07 00:14:06 +02:00
Klim Tsoutsman
8b37928131
Fix typos
I'm not sure whether I should add links to `bool`, `char`, and `str`. `slice` could also be linked to.
2021-10-06 23:32:22 +11:00
dswij
42f2304ce4 Drop exponent suggestion when 0
This commit changes numeric literal formatting to drop exponent when
exponent is 0.
2021-10-06 15:02:38 +08:00
hkalbasi
388a3d0983 Implement equatable if let lint 2021-10-04 22:16:42 +03:30
Cameron Steffen
e165c12932 Make diangostic item names consistent 2021-10-02 19:38:19 -05:00
Manish Goregaokar
6bf5c0b185 Correctly handle signs in exponents in numeric_literal::format() 2021-10-01 17:27:47 -07:00
Manish Goregaokar
6d18c9912f Rollup merge of #88963 - fee1-dead:const-iterator, r=oli-obk
Coerce const FnDefs to implement const Fn traits

You can now pass a FnDef to a function expecting `F` where `F: ~const FnTrait`.

r? ``@oli-obk``

``@rustbot`` label T-compiler F-const_trait_impl
2021-10-01 14:46:48 -07:00
Cameron Steffen
a17359c696 Remove shadow allows 2021-09-30 14:07:58 -05:00
bors
ab99eec15f Auto merge of #7684 - surechen:solve_derivable_impls, r=flip1995
fix for issue #7683

Fixes #7683.

For Repeat  [x; y] (x is the type and y is the times to repeat) . When y > 32, the compiler will report an error:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7148558162685e91056e0550797ea74c

Because 6cdd42f9f8/library/std/src/primitive_docs.rs (L538)
/// Arrays of sizes from 0 to 32 (inclusive) implement [`Default`] trait
/// if the element type allows it. As a stopgap, trait implementations are
/// statically generated up to size 32.

So here to detect this situation.

changelog: [`derivable_impls`]: No longer lints when arrays bigger than 32 elements are involved
2021-09-30 08:19:58 +00:00
surechen
a3d3735515 Arrays of sizes from 0 to 32 (inclusive) implement [Default] trait, edit method is_default_equivalent() to satisfy with this. 2021-09-30 10:41:36 +08:00
flip1995
23d5457e6d Merge commit 'cb7915b00c235e9b5861564f3be78dba330980ee' into clippyup 2021-09-28 18:03:12 +01:00
flip1995
ec38746b4a
Allow internal lint INVALID_PATHS for itertools path
Since clippy_utils doesn't depend on the itertools crate anymore, the
lint can't find the path.
2021-09-28 17:07:51 +01:00
flip1995
707494eca9
Merge remote-tracking branch 'upstream/master' into rustup 2021-09-28 10:52:31 +01:00
Matthias Krüger
c3515c301d bump clippy crates to edition 2021 2021-09-25 22:40:58 +02:00
bors
aef45770f8 Auto merge of #89030 - nbdd0121:box2, r=jonas-schievink
Introduce `Rvalue::ShallowInitBox`

Polished version of #88700.

Implements MCP rust-lang/compiler-team#460, and should allow #43596 to go forward.

In short, creating an empty box is split from a nullary-op `NullOp::Box` into two steps, first a call to `exchange_malloc`, then a `Rvalue::ShallowInitBox` which transmutes `*mut u8` to a shallow-initialized `Box<T>`. This allows the `exchange_malloc` call to unwind. Details can be found in the MCP.

`NullOp::Box` is not yet removed, purely to make reverting easier in case anything goes wrong as the result of this PR. If revert is needed a reversion of "Use Rvalue::ShallowInitBox for box expression" commit followed by a test bless should be sufficient.

Experiments in #88700 showed a very slight compile-time perf regression due to (supposedly) slightly more time spent in LLVM. We could omit unwind edge generation (in non-`oom=panic` case) in box expression MIR construction to restore perf; but I don't think it's necessary since runtime perf isn't affected and perf difference is rather small.
2021-09-25 11:01:13 +00:00
Gary Guo
fc8edf12cd Introduce Rvalue::ShallowInitBox 2021-09-25 01:08:41 +01:00
Labelray
543b638dbe Add new lint if_then_panic 2021-09-24 22:14:20 +08:00
bors
edaeacfbbb Auto merge of #89139 - camsteffen:write-perf, r=Mark-Simulacrum
Use ZST for fmt unsafety

as suggested here - https://github.com/rust-lang/rust/pull/83302#issuecomment-923529151.
2021-09-23 02:10:26 +00:00
Cameron Steffen
4873ebee4c Use ZST for fmt unsafety
This allows the format_args! macro to keep the pre-expansion code out of
the unsafe block without doing gymnastics with nested `match`
expressions. This reduces codegen.
2021-09-21 10:04:44 -05:00
Cameron Steffen
19a3116feb Remove needless hir Map ref 2021-09-18 15:55:34 -05:00
Deadbeef
3e5f80f009 Move is_const_fn to under TyCtxt 2021-09-15 11:27:34 +00:00
David Tolnay
c2783c1dcb
Downgrade many_single_char_names to pedantic 2021-09-14 09:59:06 -07:00
Guillaume Gomez
d37f1091e8 Update permissions path for clippy lint 2021-09-13 21:27:53 +02:00
bors
1add837c91 Auto merge of #88517 - smoelius:without-patch-versions, r=flip1995
Update Clippy dependencies without patch versions

Trial run for https://github.com/rust-lang/rust-clippy/pull/7606
2021-09-13 02:45:18 +00:00
bors
00d45fe5b7 Auto merge of #88839 - nbdd0121:alignof, r=nagisa
Introduce NullOp::AlignOf

This PR introduces `Rvalue::NullaryOp(NullOp::AlignOf, ty)`, which will be lowered from `align_of`, similar to `size_of` lowering to `Rvalue::NullaryOp(NullOp::SizeOf, ty)`.

The changes are originally part of #88700 but since it's not dependent on other changes and could have performance impact on its own, it's separated into its own PR.
2021-09-12 23:49:24 +00:00
Gary Guo
5d93d9d040 Introduce NullOp::AlignOf 2021-09-13 00:08:35 +01:00
Vadim Petrochenkov
9163ac9595 rustc: Remove local variable IDs from Exports
Local variables can never be exported.
2021-09-10 23:41:48 +03:00
Cameron Steffen
ae2a95fadc Eat dogfood 2021-09-09 17:10:59 -05:00
Samuel E. Moelius III
43ed2065cc Update dependencies 2021-09-09 07:47:16 -04:00
bors
261e34d534 Auto merge of #88615 - flip1995:clippyup, r=Manishearth
Update Clippy

r? `@Manishearth`
2021-09-08 23:52:31 +00:00
flip1995
091ed44b50 Merge commit '27afd6ade4bb1123a8bf82001629b69d23d62aff' into clippyup 2021-09-08 16:31:47 +02:00
Cameron Steffen
ffe21e58a0
Remove unused dependencies 2021-09-08 11:13:44 +02:00
flip1995
563a00b2a0
Bump Clippy Version -> 0.1.57 2021-09-08 10:59:04 +02:00
Camille GILLOT
98e8682cb4 Rename rustc_mir to rustc_const_eval. 2021-09-07 20:46:26 +02:00
Michael Wright
a7a5a5d9b0 Add TAU to approx_constant 2021-09-07 05:50:04 +02:00
bors
e5ae3f5491 Auto merge of #7629 - mikerite:fix-7623-2, r=xFrednet
Make `approx_const` MSRV aware

changelog: [`approx_const`]: Add MRSV checks for LOG10_2 and LOG2_10.

Fixes #7623
2021-09-05 13:17:02 +00:00
bors
a8c269ad50 Auto merge of #7570 - HKalbasi:derivable-impls, r=camsteffen
Add the `derivable_impls` lint

Fix #7550

changelog: Add new derivable_impls lint. mem_replace_with_default now covers non constructor cases.
2021-09-04 21:40:04 +00:00
hamidreza kalbasi
8221f9e795 add derivable impls lint 2021-09-05 01:25:59 +04:30
Michael Wright
a23af89447 Make approx_const MSRV aware
Fixes #7623.
2021-09-03 08:34:34 +02:00
Jake Goulding
b4775435e8 Adjust the output of unnecessary_unwrap and provide a suggestion 2021-09-02 20:52:16 -04:00
flip1995
01b17af108
Fix fallout from re-applying patches 2021-09-02 13:04:47 +01:00
Cameron Steffen
c2bb313e7a
Add higher docs and remove some unneeded fields 2021-09-02 12:41:30 +01:00
flip1995
c7c2036cb9
Fix remaining dogfood errors
Except for the missing docs ones
2021-09-02 12:40:52 +01:00
Cameron Steffen
588367b62e
Fix dogfood 2021-09-02 12:39:54 +01:00
Cameron Steffen
5722a7dacd
Fix manual_match with let-expressions 2021-09-02 12:38:59 +01:00
flip1995
61bb96738c
Merge remote-tracking branch 'upstream/master' into rustup2 2021-09-02 12:38:17 +01:00
Cameron Steffen
78bf4acc3a Fix clippy for let-else 2021-08-30 20:18:41 -05:00
bors
fd30241281 Auto merge of #7573 - Jarcho:option_if_let_else, r=giraffate
Fix `option_if_let_else`

fixes: #5822
fixes: #6737
fixes: #7567

The inference from #6137 still exists so I'm not sure if this should be moved from the nursery. Before doing that though I'd almost want to see this split into two lints. One suggesting `map_or` and the other suggesting `map_or_else`.

`map_or_else` tends to have longer expressions for both branches so it doesn't end up much shorter than a match expression in practice. It also seems most people find it harder to read. `map_or` at least has the terseness benefit of being on one line most of the time, especially when the `None` branch is just a literal or path expression.

changelog: `break` and `continue` statments local to the would-be closure are allowed in `option_if_let_else`
changelog: don't lint in const contexts  in `option_if_let_else`
changelog: don't lint when yield expressions are used  in `option_if_let_else`
changelog: don't lint when the captures made by the would-be closure conflict with the other branch  in `option_if_let_else`
changelog: don't lint when a field of a local is used when the type could be pontentially moved from  in `option_if_let_else`
changelog: in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure  in `option_if_let_else`
2021-08-30 13:57:21 +00:00
lcnr
afd892a549 update TypeFlags to deal with missing ct substs 2021-08-26 11:00:30 +02:00
lcnr
b1786f62ed add tcx to fn walk 2021-08-26 11:00:30 +02:00
lcnr
19d1fe21c7 make unevaluated const substs optional 2021-08-26 11:00:30 +02:00
bors
72df99a49b Auto merge of #83302 - camsteffen:write-piece-unchecked, r=dtolnay
Get piece unchecked in `write`

We already use specialized `zip`, but it seems like we can do a little better by not checking `pieces` length at all.

`Arguments` constructors are now unsafe. So the `format_args!` expansion now includes an `unsafe` block.

<details>
<summary>Local Bench Diff</summary>

```text
 name                        before ns/iter  after ns/iter  diff ns/iter   diff %  speedup
 fmt::write_str_macro1       22,967          19,718               -3,249  -14.15%   x 1.16
 fmt::write_str_macro2       35,527          32,654               -2,873   -8.09%   x 1.09
 fmt::write_str_macro_debug  571,953         575,973               4,020    0.70%   x 0.99
 fmt::write_str_ref          9,579           9,459                  -120   -1.25%   x 1.01
 fmt::write_str_value        9,573           9,572                    -1   -0.01%   x 1.00
 fmt::write_u128_max         176             173                      -3   -1.70%   x 1.02
 fmt::write_u128_min         138             134                      -4   -2.90%   x 1.03
 fmt::write_u64_max          139             136                      -3   -2.16%   x 1.02
 fmt::write_u64_min          129             135                       6    4.65%   x 0.96
 fmt::write_vec_macro1       24,401          22,273               -2,128   -8.72%   x 1.10
 fmt::write_vec_macro2       37,096          35,602               -1,494   -4.03%   x 1.04
 fmt::write_vec_macro_debug  588,291         589,575               1,284    0.22%   x 1.00
 fmt::write_vec_ref          9,568           9,732                   164    1.71%   x 0.98
 fmt::write_vec_value        9,516           9,625                   109    1.15%   x 0.99
```
</details>
2021-08-23 22:55:19 +00:00
Mara Bos
4c847c0dbd Rollup merge of #88230 - steffahn:a_an, r=oli-obk
Fix typos “a”→“an”

Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an.

While automation was used to find these, every change was checked manually.

Changes in submodules get separate PRs:
* https://github.com/rust-lang/stdarch/pull/1201
* https://github.com/rust-lang/cargo/pull/9821
* https://github.com/rust-lang/miri/pull/1874
* https://github.com/rust-lang/rls/pull/1746
* https://github.com/rust-analyzer/rust-analyzer/pull/9984
  _folks @ rust-analyzer are fast at merging…_
  * https://github.com/rust-analyzer/rust-analyzer/pull/9985
  * https://github.com/rust-analyzer/rust-analyzer/pull/9987
  * https://github.com/rust-analyzer/rust-analyzer/pull/9989

_For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._

<hr>

This has some overlap with #88226, but neither is a strict superset of the other.

If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23 20:45:49 +02:00