Commit Graph

6707 Commits

Author SHA1 Message Date
Jason Newcomb
80a263d469 Fix manual_map suggestion when used with unsafe functions and unsafe blocks. 2021-11-12 19:12:17 -05: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
5225225
d4c8cb63a4 Change cast_lossless message for bools only 2021-11-12 17:01:35 +00:00
bors
8b84a760ca Auto merge of #7956 - camsteffen:author, r=llogiq
Author improvements

changelog: none

Various aspects of the author implementation are re-imagined to be much less repetitive. Also fixes some bugs. I hope this makes author more fun to work on for future contributors.

The last commit is pretty heavy but I tried to at least separate some changes so that the test file diffs per commit are simple.
2021-11-11 19:33:06 +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
Cameron Steffen
27a1763eac Make author DRYer 2021-11-11 09:38:00 -06: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
xFrednet
8c45fd88d0
New internal lint to make clippy::version attribute mandatory 2021-11-11 13:03:30 +01: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
Cameron Steffen
72d7b9c097 author: Remove needless refs 2021-11-10 16:37:55 -06:00
Cameron Steffen
a806ce79b6 author: reorder match arm 2021-11-10 16:36:54 -06:00
Cameron Steffen
d0cc201204 author: fix some bugs 2021-11-10 16:36:51 -06:00
Cameron Steffen
ce01346ac1 author: name qpath consistently 2021-11-10 15:40:50 -06:00
xFrednet
94bc0a1c78
Address review feedback 2021-11-10 20:14:02 +01:00
xFrednet
9d9d06d557
Add lint to check for invalid clippy:version attributes 2021-11-10 19:48:31 +01:00
xFrednet
d647696c1f
Added clippy::version attribute to all normal lints
So, some context for this, well, more a story. I'm not used to scripting, I've never really scripted anything, even if it's a valuable skill. I just never really needed it. Now, `@flip1995` correctly suggested using a script for this in `rust-clippy#7813`...

And I decided to write a script using nushell because why not? This was a mistake... I spend way more time on this than I would like to admit. It has definitely been more than 4 hours. It shouldn't take that long, but me being new to scripting and nushell just wasn't a good mixture... Anyway, here is the script that creates another script which adds the versions. Fun...

Just execute this on the `gh-pages` branch and the resulting `replacer.sh` in `clippy_lints` and it should all work.

```nu
mv v0.0.212 rust-1.00.0;
mv beta rust-1.57.0;
mv master rust-1.58.0;

let paths = (open ./rust-1.58.0/lints.json | select id id_span | flatten | select id path);
let versions = (
    ls | where name =~ "rust-" | select name | format {name}/lints.json |
    each { open $it | select id | insert version $it | str substring "5,11" version} |
    group-by id | rotate counter-clockwise id version |
    update version {get version | first 1} | flatten | select id version);
$paths | each { |row|
    let version = ($versions | where id == ($row.id) | format {version})
    let idu = ($row.id | str upcase)
    $"sed -i '0,/($idu),/{s/pub ($idu),/#[clippy::version = "($version)"]\n    pub ($idu),/}' ($row.path)"
} | str collect ";" | str find-replace --all '1.00.0' 'pre 1.29.0' | save "replacer.sh";
```

And this still has some problems, but at this point I just want to be done -.-
2021-11-10 19:48:31 +01:00
xFrednet
63cb41098b
Manually add clippy::version attribute to deprecated lints 2021-11-10 19:48:30 +01:00
xFrednet
8565fc468e
Add clippy version to Clippy's lint list 2021-11-10 19:48:30 +01:00
xFrednet
7c1e62d962
Added clippy::version attribute as lint metadata 2021-11-10 19:48:29 +01:00
dswij
a003ca6853 semicolon_if_nothing_returned now checks if the stmt ends with semicolon 2021-11-10 14:46:00 +08:00
bors
93f13d532f Auto merge of #7951 - mikerite:matches-20211109, r=llogiq
`match_overlapping_arm` refactoring

The main purpose of this pull request is to remove the unneeded and scary `unimplented!()` in the `match_arm_overlapping` code.

The rest is gratuitous refactoring.

changelog: none
2021-11-09 19:28:48 +00:00
bors
f69721f37c Auto merge of #7950 - Serial-ATA:issue-7920, r=llogiq
Fix `explicit_counter_loop` suggestion for non-usize types

changelog: Add a new suggestion for non-usize types in [`explicit_counter_loop`]

closes: #7920
2021-11-09 19:14:24 +00:00
Matthias Krüger
3b6b1ab0ec Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis
Type inference for inline consts

Fixes #78132
Fixes #78174
Fixes #81857
Fixes #89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `````@spastorino````` `````@lcnr`````
r? `````@nikomatsakis`````

`````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-09 19:00:40 +01:00
5225225
6e84f00045 Check MSRV for bool to int from impl 2021-11-09 17:35:35 +00:00
5225225
33822012ec Lint for bool to integer casts in cast_lossless 2021-11-09 17:30:15 +00:00
bors
c94d62b153 Auto merge of #7949 - Serial-ATA:issue-7921, r=flip1995
Fix suggestion for deref expressions in redundant_pattern_matching

changelog: Fix suggestion for deref expressions in [`redundant_pattern_matching`]

closes: #7921
2021-11-09 12:37:49 +00:00
Serial
e54c341d05 Fix suggestion for deref expressions in redundant_pattern_matching 2021-11-09 07:25:09 -05:00
Michael Wright
8b7691551a matches: remove pub from some items
There is no reason for these to be `pub`. They aren't used anywhere
else.
2021-11-09 05:44:02 +02:00
Michael Wright
81fa758356 Improve variable naming 2 2021-11-09 05:44:02 +02:00
Michael Wright
c8f909ee54 Improve variable naming 2021-11-09 05:44:02 +02:00
Michael Wright
f829523340 Simplify range comparison code
Reword the `Kind` type so that the `cmp` function is simpler.
2021-11-09 05:44:02 +02:00
Michael Wright
949b25981c Change Bound to EndBound
Only the end bounds of ranges can actually be included or excluded. This
commit changes the SpannedRange type to reflect that. Update `Kind::value`
to and `Kind::cmp` for this change. `Kind::cmp` gets flipped to check value
first and then the bound details and is much shorter.
2021-11-09 05:44:02 +02:00
Michael Wright
98416d7f6c Remove unimplemented!() case in matches code
This unbounded case never actually happens because `all_ranges(..)` uses
the scrutinee type bounds for open ranges. Switch to our own `Bound`
enum so that we don't have this case.
2021-11-09 05:44:02 +02:00
Serial
680923491a Fix explicit_counter_loop suggestion for non-usize types 2021-11-08 22:21:05 -05: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
Deadbeef
6d23824ef4 Make select_* methods return Vec for TraitEngine 2021-11-08 23:35:23 +08:00
bors
94517d397c Auto merge of #7938 - camsteffen:visitors, r=xFrednet
Introduce `expr_visitor` and `expr_visitor_no_bodies`

changelog: none

A couple utils that satisfy a *lot* of visitor use cases. Factoring in every possible usage would be really big so I just focused on cleaning clippy_utils.
2021-11-08 13:39:58 +00:00
Serial
2c6f03d48b Fix ICE in undocumented_unsafe_blocks 2021-11-07 14:28:30 -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
Gary Guo
0cb9ac2d96 Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
Serial
c96cd359f5 Extend author lint 2021-11-06 03:08:14 -04:00
Cameron Steffen
2c7b7e8c56 Remove if let check for match_ref_pats 2021-11-05 14:50:23 -05:00
Cameron Steffen
5239a90f70 Factor in some expr_visitor usages 2021-11-05 14:39:39 -05:00
Cameron Steffen
1c4dd8d3eb Remove trim_semicolon 2021-11-05 11:39:50 -05:00
bors
445c83f8f3 Auto merge of #7937 - flip1995:rustfmt-skip-artefact, r=Manishearth
Remove rustfmt::skip attribute from register_plugins function

r? `@Manishearth` since you added this in #540 😄

changelog: none
2021-11-05 15:34:46 +00:00
bors
9a60a93cac Auto merge of #7897 - camsteffen:in-macro, r=flip1995
Replace `in_macro` usage with `from_expansion`

changelog: none

Generally replace `in_macro(span)` with `span.from_expansion()`. If we're just trying to avoid expanded code, this seems more appropriate because any kind of expanded code is prone to false positives. One place I did not touch is `macro_use.rs`. I think this lint could use a rewrite so I moved `in_macro` there, the only place it is still used.
2021-11-05 14:42:32 +00:00
bors
85e25923e1 Auto merge of #7909 - mikerite:fix-7816, r=camsteffen
Fix false negative in [`match_overlapping_arms`]

changelog: Fix false negative in [`match_overlapping_arms`]
2021-11-05 14:16:38 +00:00
Cameron Steffen
14d54f0f6e Use Span::from_expansion instead of in_macro 2021-11-05 08:50:17 -05:00
flip1995
93ffc9d233
Remove rustfmt::skip attribute from register_plugins function 2021-11-05 10:54:37 +00:00
flip1995
e674d0a599 Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup 2021-11-04 12:52:36 +00:00
flip1995
1cc21db8c6
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-04 12:03:28 +00:00
Serial
0db8c52291 Add suggestion to missing backticks error 2021-11-02 16:50:47 -04:00
Samuel Tardieu
7f8198acad Advise to put a :: prefix inside the ticks 2021-11-02 17:57:50 +01:00
xFrednet
db9e012927 Update clippy dependencies
* semver = "0.11" -> "1.0"
* cargo_metadata = "0.12" -> "0.14"
2021-11-02 14:19:31 +01:00
bors
18cc4e74f8 Auto merge of #7907 - Alexendoo:non-ascii-restriction, r=flip1995
Move non_ascii_literal to restriction

It feels like the more apt category, since cases where you'd want it enabled would be pretty specific

changelog: Move [`non_ascii_literal`] to `restriction`
2021-11-02 10:36:26 +00:00
bors
9720619432 Auto merge of #7901 - samueltardieu:fix-7893, r=xFrednet,flip1995
Prevent clippy::needless_lifetimes false positive in async function definition

Scan `OpaqueDef` bounds for lifetimes as well. Those `OpaqueDef` instances are generated while desugaring an `async` function definition.

This fixes #7893

changelog: Prevent [`clippy::needless_lifetimes`] false positive in `async` function definition
2021-11-02 10:23:15 +00:00
bors
276e8951f1 Auto merge of #7851 - nbdd0121:master, r=flip1995
Fix manual_assert and match_wild_err_arm for `#![no_std]` and Rust 2021

Rust 2015 `std::panic!` has a wrapping block while `core::panic!` and Rust 2021 `std::panic!` does not. See rust-lang/rust#88919 for details.

Note that the test won't pass until clippy changes in rust-lang/rust#88860 is synced.

---

changelog: Fix [`manual_assert`] and [`match_wild_err_arm`] for `#![no_std]` and Rust 2021.

Fixes #7723
2021-11-02 10:09:47 +00:00
bors
38d80257d0 Auto merge of #7726 - dswij:unseparated-literal-suffix, r=flip1995
Unseparated literal suffix

Closes #7658

Since `literal_suffix` style is opinionated, we should disable by default and only enforce if it's stated as so.

changelog: [`unseparated_literal_suffix`] is renamed to `literal_suffix`, adds a new configuration `literal-suffix-style` to enforce a certain style writing literal_suffix. Possible values for `literal-suffix-style`: `"separated"`, `"unseparated"`
2021-11-02 09:57:12 +00:00
Samuel Tardieu
3f84010688 Examine lifetimes in OpaqueDef bounds as well
Fix #7893.
2021-11-02 10:54:58 +01:00
bors
4e355ebb6e Auto merge of #7819 - rust-lang:avoid-linting-impossible-truncation, r=flip1995
avoid linting `possible_truncation` on bit-reducing operations

---

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

changelog: avoid linting `possible_truncation` on bit-reducing operations
2021-11-02 09:44:27 +00:00
Takayuki Nakata
ec456de2a3 Small fixes for missing backticks in doc 2021-11-02 09:09:22 +09:00
Gary Guo
7e5f99ab58 Fix manual_assert for #![no_std] and Rust 2021 2021-11-01 15:47:33 +00:00
Dharma Saputra Wijaya
1085df58ac Add separated_literal_suffix as an alternative for
`unseparated_literal_suffix`

This commit adds a configuration `literal-suffix-style` to enforce a
specific style for unseparated_literal_suffix. The configuration accepts
two values:
- "separated"
    enforce all literals to be written separately (e.g. `123_i32`)
- "unseparated"
    enforce all literals to be written as unseparated (e.g. `123i32`)

Not specifying a value means that there is no preference on style and
any style should not be warned.
2021-11-01 22:26:13 +08:00
Michael Wright
693df63c7d Ensure match_overlapping_arms warns on first 2021-11-01 06:12:43 +02:00
Michael Wright
c3d45775c4 Fix match_overlapping_arm false negative
Fixes #7816
2021-11-01 06:12:43 +02:00
Alex Macleod
28c225f775 Move non_ascii_literal to restriction 2021-10-31 12:59:53 +00:00
bors
4c70c182c0 Auto merge of #7895 - ahmedkrmn:master, r=Manishearth
Disable "if_not_else" lints from firing on else-ifs

Fixes #7892

1. Convert `['if_not_else']` to `LateLintPass` and use `clippy_utils::is_else_clause` for checking.
2. Update tests.

changelog: [`if_not_else`] now ignores else if statements.
2021-10-29 20:31:51 +00:00
Ahmed Karaman
2f327aaba5
Disable "if_not_else" lints firing on else-ifs
1. Convert IfNotElse to LateLintPass and use clippy_utils::is_else_clause for checking.
2. Handle the case where the span comes from desugaring.
3. Update tests.
2021-10-29 22:07:05 +02:00
Andre Bogus
00ea73e162 avoid linting possible_truncation on bit-reducing operations 2021-10-29 21:59:24 +02:00
bors
dbe167daaa Auto merge of #7890 - Alexendoo:ptr-arg-alias, r=camsteffen
Ignore references to type aliases in ptr_arg

Works using the fact that the hir path will point to a TyAlias, rather than being resolved to the underlying type

Fixes #7699

changelog: [`ptr_arg`] No longer lints references to type aliases
2021-10-29 19:45:26 +00:00
Cameron Steffen
022146d2c3 Rename if_then_panic to manual_assert 2021-10-28 09:41:53 -05:00
Cameron Steffen
d8fcfd7d64 Move if_then_panic to pedantic 2021-10-28 09:38:01 -05:00
bors
7788af9c47 Auto merge of #7891 - giraffate:fix_ice_for_undocumented_unsafe_blocks, r=flip1995
Fix ice in `undocumented_unsafe_blocks`

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

changelog: Fix ice in [`undocumented_unsafe_blocks`]
2021-10-28 13:37:40 +00:00
Takayuki Nakata
35bf041c21 Fix ICE in undocumented_unsafe_blocks 2021-10-28 22:10:59 +09: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
ed71addee7 Auto merge of #7885 - devonhollowood:deprecated-cleanup, r=llogiq
Clean up `tests/ui/deprecated.rs`

Clean up `tests/ui/deprecated.rs`

Along with #7884, this fixes #7057

changelog: none
2021-10-27 18:38:38 +00:00
Alex Macleod
e2c30f05c1 Ignore references to type aliases in ptr_arg
Works using the fact that the hir path will point to a TyAlias, rather
than being resolved to the underlying type
2021-10-27 19:08:42 +01:00
bors
962e21cf15 Auto merge of #7875 - mbStavola:unit-hash, r=xFrednet
Add unit-hash lint

changelog: [`unit_hash`] Add lint for hashing unit values

This will lint for situations where the end user is attempting to hash a unit value (`()`), as the implementation in `std` simply [does nothing][impl]. Closes #7159 .

Example:

```rust
().hash(&mut state);

// Should (probably) be replaced with:
0_u8.hash(&mut state);
```

[impl]: a5f164faad/library/core/src/hash/mod.rs (L656)
2021-10-27 14:37:54 +00:00
Matt Stavola
36d4a4ea82
Add unit-hash lint 2021-10-27 06:32:37 -07:00
bors
444ef3e4d5 Auto merge of #7880 - Alexendoo:newlint-add-pass, r=flip1995
Register the generated lints from `cargo dev new_lint`

How to register a lint was something that took me a couple reads to figure out, this will hopefully make that easier. It appends the created lint to the end of the list when running `cargo dev new_lint`

changelog: none
2021-10-27 07:33:00 +00:00
bors
ba2ac3e263 Auto merge of #7860 - dswij:question-mark-fp, r=giraffate
Fix `question_mark` FP on custom error type

Closes #7859

#7840 aims to ignore `question_mark` when the return type is custom, which is [covered here](df65291edd/tests/ui/question_mark.rs (L144-L149)). But this fails when there is a call in conditional predicate

changelog: [`question_mark`] Fix false positive when there is call in conditional predicate
2021-10-26 23:46:21 +00:00
bors
a48367e21c Auto merge of #7884 - devonhollowood:rename-cleanup, r=xFrednet
Clean up tests/ui/rename.rs

Part one of #7057, cleaning up `tests/ui/rename.rs`. `tests/ui/deprecated.rs` will be updated in a subsequent PR.

changelog: none
2021-10-26 21:16:44 +00:00
xFrednet
dea940259e Remove hidden code lines in Clippy's lint list 2021-10-26 22:33:46 +02:00
Alex Macleod
bd778e216d Register the generated lints from cargo dev new_lint 2021-10-26 19:05:29 +01:00
Devon Hollowood
e48ab448f9 Clean up tests/ui/deprecated.rs
This also removes the uplifted lints from this test suite -- these are now
tested in `tests/ui/rename.rs`
2021-10-26 10:52:35 -07:00
Dharma Saputra Wijaya
fb0fbad5ca Rename variable name in question_mark 2021-10-26 21:22:22 +08:00
dswij
a1a399d168 Fix question_mark FP on calls 2021-10-26 21:21:46 +08:00
bors
075996efd7 Auto merge of #7878 - rust-lang:string-slice, r=giraffate
new lint: string-slice

This is a restriction lint to highlight code that should have tests containing non-ascii characters. See #6623.

changelog: new lint: [`string-slice`]
2021-10-26 08:11:49 +00:00
Devon Hollowood
d0c04b4d78 Clean up tests/ui/rename.rs 2021-10-26 00:53:53 -07:00
Andre Bogus
999b3004c4 new lint: string-slice 2021-10-26 09:05:28 +02:00
bors
cb0132d209 Auto merge of #7865 - Herschel:fix-match-str-case-mismatch, r=xFrednet
Fix `match_str_case_mismatch` on uncased chars

False positives would result because `char::is_lowercase` and friends will return `false` for non-alphabetic chars and alphabetic chars lacking case (such as CJK scripts). Care also has to be taken for handling titlecase characters (`Dz`) and lowercased chars with no uppercase equivalent (`ʁ`).

For example, when verifying lowercase:
 * Check `!any(char::is_ascii_uppercase)` instead of `all(char::is_ascii_lowercase)` for ASCII.
 * Check that `all(|c| c.to_lowercase() == c)` instead of `all(char::is_lowercase)` for non-ASCII

Fixes #7863.

changelog: Fix false positives in [`match_str_case_mismatch`] on uncased characters
2021-10-25 21:34:11 +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
1ad04f4054 Move non_send_fields_in_send_ty to suspicious
Also updated one configuration for nicer formatting
2021-10-25 19:32:17 +02: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
Mike Welsh
e953dff536 Fix match_str_case_mismatch false positives
Properly consider uncased and titlecased characters.
Fixes #7863.
2021-10-23 02:03:15 -07:00
Yuki Okushi
efef16f6ed Rollup merge of #89895 - camsteffen:for-loop-head-span, r=davidtwco
Don't mark for loop iter expression as desugared

We typically don't mark spans of lowered things as desugared. This helps Clippy rightly discern when code is (not) from expansion. This was discovered by ``@flip1995`` at https://github.com/rust-lang/rust-clippy/pull/7789#issuecomment-939289501.
2021-10-22 19:42:45 +09:00