mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 03:03:40 +00:00
Auto merge of #9032 - kyoto7250:issue_9018, r=llogiq
enum_variant_names should ignore when all prefixes are _ close #9018 When Enum prefix is only an underscore, we should not issue warnings. changelog: fix false positive in enum_variant_names
This commit is contained in:
commit
9b150625a9
@ -190,7 +190,7 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
|
|||||||
.map(|e| *e.0)
|
.map(|e| *e.0)
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
let (what, value) = match (pre.is_empty(), post.is_empty()) {
|
let (what, value) = match (have_no_extra_prefix(&pre), post.is_empty()) {
|
||||||
(true, true) => return,
|
(true, true) => return,
|
||||||
(false, _) => ("pre", pre.join("")),
|
(false, _) => ("pre", pre.join("")),
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
@ -212,6 +212,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
fn have_no_extra_prefix(prefixes: &[&str]) -> bool {
|
||||||
|
prefixes.iter().all(|p| p == &"" || p == &"_")
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn to_camel_case(item_name: &str) -> String {
|
fn to_camel_case(item_name: &str) -> String {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
|
@ -158,4 +158,25 @@ enum Phase {
|
|||||||
PostLookup,
|
PostLookup,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue9018 {
|
||||||
|
enum DoLint {
|
||||||
|
_TypeCreate,
|
||||||
|
_TypeRead,
|
||||||
|
_TypeUpdate,
|
||||||
|
_TypeDestroy,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DoLintToo {
|
||||||
|
_CreateType,
|
||||||
|
_UpdateType,
|
||||||
|
_DeleteType,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DoNotLint {
|
||||||
|
_Foo,
|
||||||
|
_Bar,
|
||||||
|
_Baz,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -120,5 +120,30 @@ LL | | }
|
|||||||
|
|
|
|
||||||
= help: remove the postfixes and use full paths to the variants instead of glob imports
|
= help: remove the postfixes and use full paths to the variants instead of glob imports
|
||||||
|
|
||||||
error: aborting due to 12 previous errors
|
error: all variants have the same prefix: `_Type`
|
||||||
|
--> $DIR/enum_variants.rs:162:5
|
||||||
|
|
|
||||||
|
LL | / enum DoLint {
|
||||||
|
LL | | _TypeCreate,
|
||||||
|
LL | | _TypeRead,
|
||||||
|
LL | | _TypeUpdate,
|
||||||
|
LL | | _TypeDestroy,
|
||||||
|
LL | | }
|
||||||
|
| |_____^
|
||||||
|
|
|
||||||
|
= help: remove the prefixes and use full paths to the variants instead of glob imports
|
||||||
|
|
||||||
|
error: all variants have the same postfix: `Type`
|
||||||
|
--> $DIR/enum_variants.rs:169:5
|
||||||
|
|
|
||||||
|
LL | / enum DoLintToo {
|
||||||
|
LL | | _CreateType,
|
||||||
|
LL | | _UpdateType,
|
||||||
|
LL | | _DeleteType,
|
||||||
|
LL | | }
|
||||||
|
| |_____^
|
||||||
|
|
|
||||||
|
= help: remove the postfixes and use full paths to the variants instead of glob imports
|
||||||
|
|
||||||
|
error: aborting due to 14 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user