mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Add new lint upper_case_acronyms
This commit is contained in:
parent
6c830ff9e4
commit
ab1da8f865
24 changed files with 256 additions and 88 deletions
|
@ -1877,7 +1877,6 @@ Released 2018-09-13
|
|||
[`box_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_vec
|
||||
[`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local
|
||||
[`builtin_type_shadow`]: https://rust-lang.github.io/rust-clippy/master/index.html#builtin_type_shadow
|
||||
[`capitalized_acronyms`]: https://rust-lang.github.io/rust-clippy/master/index.html#capitalized_acronyms
|
||||
[`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata
|
||||
[`case_sensitive_file_extension_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#case_sensitive_file_extension_comparisons
|
||||
[`cast_lossless`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
|
||||
|
@ -2275,6 +2274,7 @@ Released 2018-09-13
|
|||
[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings
|
||||
[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result
|
||||
[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
|
||||
[`upper_case_acronyms`]: https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms
|
||||
[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug
|
||||
[`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self
|
||||
[`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
use rustc_lint::{EarlyLintPass, EarlyContext};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_ast::ast::*;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:**
|
||||
///
|
||||
/// **Why is this bad?**
|
||||
///
|
||||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
///
|
||||
/// ```rust
|
||||
/// // example code where clippy issues a warning
|
||||
/// ```
|
||||
/// Use instead:
|
||||
/// ```rust
|
||||
/// // example code which does not raise clippy warning
|
||||
/// ```
|
||||
pub CAPITALIZED_ACRONYMS,
|
||||
style,
|
||||
"default lint description"
|
||||
}
|
||||
|
||||
declare_lint_pass!(CapitalizedAcronyms => [CAPITALIZED_ACRONYMS]);
|
||||
|
||||
impl EarlyLintPass for CapitalizedAcronyms {}
|
|
@ -57,9 +57,9 @@ impl CognitiveComplexity {
|
|||
|
||||
let expr = &body.value;
|
||||
|
||||
let mut helper = CCHelper { cc: 1, returns: 0 };
|
||||
let mut helper = CcHelper { cc: 1, returns: 0 };
|
||||
helper.visit_expr(expr);
|
||||
let CCHelper { cc, returns } = helper;
|
||||
let CcHelper { cc, returns } = helper;
|
||||
let ret_ty = cx.typeck_results().node_type(expr.hir_id);
|
||||
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::result_type) {
|
||||
returns
|
||||
|
@ -136,12 +136,12 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
|
|||
}
|
||||
}
|
||||
|
||||
struct CCHelper {
|
||||
struct CcHelper {
|
||||
cc: u64,
|
||||
returns: u64,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for CCHelper {
|
||||
impl<'tcx> Visitor<'tcx> for CcHelper {
|
||||
type Map = Map<'tcx>;
|
||||
|
||||
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
||||
|
|
|
@ -46,8 +46,8 @@ declare_lint_pass!(IntPlusOne => [INT_PLUS_ONE]);
|
|||
|
||||
#[derive(Copy, Clone)]
|
||||
enum Side {
|
||||
LHS,
|
||||
RHS,
|
||||
Lhs,
|
||||
Rhs,
|
||||
}
|
||||
|
||||
impl IntPlusOne {
|
||||
|
@ -66,11 +66,11 @@ impl IntPlusOne {
|
|||
match (lhskind.node, &lhslhs.kind, &lhsrhs.kind) {
|
||||
// `-1 + x`
|
||||
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => {
|
||||
Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS)
|
||||
Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::Lhs)
|
||||
},
|
||||
// `x - 1`
|
||||
(BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS)
|
||||
Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::Lhs)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
|
@ -82,10 +82,10 @@ impl IntPlusOne {
|
|||
match (&rhslhs.kind, &rhsrhs.kind) {
|
||||
// `y + 1` and `1 + y`
|
||||
(&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS)
|
||||
Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::Rhs)
|
||||
},
|
||||
(_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS)
|
||||
Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::Rhs)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ impl IntPlusOne {
|
|||
match (&lhslhs.kind, &lhsrhs.kind) {
|
||||
// `1 + x` and `x + 1`
|
||||
(&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::LHS)
|
||||
Self::generate_recommendation(cx, binop, lhsrhs, rhs, Side::Lhs)
|
||||
},
|
||||
(_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS)
|
||||
Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::Lhs)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
|
@ -110,11 +110,11 @@ impl IntPlusOne {
|
|||
match (rhskind.node, &rhslhs.kind, &rhsrhs.kind) {
|
||||
// `-1 + y`
|
||||
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => {
|
||||
Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::RHS)
|
||||
Self::generate_recommendation(cx, binop, rhsrhs, lhs, Side::Rhs)
|
||||
},
|
||||
// `y - 1`
|
||||
(BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS)
|
||||
Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::Rhs)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
|
@ -138,8 +138,8 @@ impl IntPlusOne {
|
|||
if let Some(snippet) = snippet_opt(cx, node.span) {
|
||||
if let Some(other_side_snippet) = snippet_opt(cx, other_side.span) {
|
||||
let rec = match side {
|
||||
Side::LHS => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)),
|
||||
Side::RHS => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)),
|
||||
Side::Lhs => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)),
|
||||
Side::Rhs => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)),
|
||||
};
|
||||
return rec;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#![feature(concat_idents)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(drain_filter)]
|
||||
#![feature(split_inclusive)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(once_cell)]
|
||||
#![feature(or_patterns)]
|
||||
|
@ -169,7 +170,6 @@ mod blacklisted_name;
|
|||
mod blocks_in_if_conditions;
|
||||
mod booleans;
|
||||
mod bytecount;
|
||||
mod capitalized_acronyms;
|
||||
mod cargo_common_metadata;
|
||||
mod case_sensitive_file_extension_comparisons;
|
||||
mod checked_conversions;
|
||||
|
@ -342,6 +342,7 @@ mod unused_self;
|
|||
mod unused_unit;
|
||||
mod unwrap;
|
||||
mod unwrap_in_result;
|
||||
mod upper_case_acronyms;
|
||||
mod use_self;
|
||||
mod useless_conversion;
|
||||
mod vec;
|
||||
|
@ -560,7 +561,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
&booleans::LOGIC_BUG,
|
||||
&booleans::NONMINIMAL_BOOL,
|
||||
&bytecount::NAIVE_BYTECOUNT,
|
||||
&capitalized_acronyms::CAPITALIZED_ACRONYMS,
|
||||
&cargo_common_metadata::CARGO_COMMON_METADATA,
|
||||
&case_sensitive_file_extension_comparisons::CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS,
|
||||
&checked_conversions::CHECKED_CONVERSIONS,
|
||||
|
@ -946,6 +946,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
&unwrap::PANICKING_UNWRAP,
|
||||
&unwrap::UNNECESSARY_UNWRAP,
|
||||
&unwrap_in_result::UNWRAP_IN_RESULT,
|
||||
&upper_case_acronyms::UPPER_CASE_ACRONYMS,
|
||||
&use_self::USE_SELF,
|
||||
&useless_conversion::USELESS_CONVERSION,
|
||||
&vec::USELESS_VEC,
|
||||
|
@ -985,7 +986,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
}
|
||||
store.register_late_pass(|| box utils::author::Author);
|
||||
store.register_late_pass(|| box await_holding_invalid::AwaitHolding);
|
||||
store.register_late_pass(|| box serde_api::SerdeAPI);
|
||||
store.register_late_pass(|| box serde_api::SerdeApi);
|
||||
let vec_box_size_threshold = conf.vec_box_size_threshold;
|
||||
store.register_late_pass(move || box types::Types::new(vec_box_size_threshold));
|
||||
store.register_late_pass(|| box booleans::NonminimalBool);
|
||||
|
@ -1176,6 +1177,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
let enum_variant_name_threshold = conf.enum_variant_name_threshold;
|
||||
store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold));
|
||||
store.register_early_pass(|| box tabs_in_doc_comments::TabsInDocComments);
|
||||
store.register_early_pass(|| box upper_case_acronyms::UpperCaseAcronyms);
|
||||
store.register_late_pass(|| box default::Default::default());
|
||||
store.register_late_pass(|| box unused_self::UnusedSelf);
|
||||
store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall);
|
||||
|
@ -1661,6 +1663,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(&unused_unit::UNUSED_UNIT),
|
||||
LintId::of(&unwrap::PANICKING_UNWRAP),
|
||||
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
|
||||
LintId::of(&upper_case_acronyms::UPPER_CASE_ACRONYMS),
|
||||
LintId::of(&useless_conversion::USELESS_CONVERSION),
|
||||
LintId::of(&vec::USELESS_VEC),
|
||||
LintId::of(&vec_init_then_push::VEC_INIT_THEN_PUSH),
|
||||
|
@ -1778,6 +1781,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
|
||||
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
|
||||
LintId::of(&unused_unit::UNUSED_UNIT),
|
||||
LintId::of(&upper_case_acronyms::UPPER_CASE_ACRONYMS),
|
||||
LintId::of(&write::PRINTLN_EMPTY_STRING),
|
||||
LintId::of(&write::PRINT_LITERAL),
|
||||
LintId::of(&write::PRINT_WITH_NEWLINE),
|
||||
|
|
|
@ -18,9 +18,9 @@ declare_clippy_lint! {
|
|||
"various things that will negatively affect your serde experience"
|
||||
}
|
||||
|
||||
declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]);
|
||||
declare_lint_pass!(SerdeApi => [SERDE_API_MISUSE]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for SerdeAPI {
|
||||
impl<'tcx> LateLintPass<'tcx> for SerdeApi {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
if let ItemKind::Impl(Impl {
|
||||
of_trait: Some(ref trait_ref),
|
||||
|
|
93
clippy_lints/src/upper_case_acronyms.rs
Normal file
93
clippy_lints/src/upper_case_acronyms.rs
Normal file
|
@ -0,0 +1,93 @@
|
|||
use crate::utils::span_lint_and_sugg;
|
||||
use if_chain::if_chain;
|
||||
use itertools::Itertools;
|
||||
use rustc_ast::ast::{Item, ItemKind, Variant};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::symbol::Ident;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for camel case name containing a capitalized acronym.
|
||||
///
|
||||
/// **Why is this bad?** In CamelCase, acronyms count as one word.
|
||||
/// See [naming conventions](https://rust-lang.github.io/api-guidelines/naming.html#casing-conforms-to-rfc-430-c-case)
|
||||
/// for more.
|
||||
///
|
||||
/// **Known problems:** When two acronyms are contiguous, the lint can't tell where
|
||||
/// the first acronym ends and the second starts, so it suggests to lowercase all of
|
||||
/// the letters in the second acronym.
|
||||
///
|
||||
/// **Example:**
|
||||
///
|
||||
/// ```rust
|
||||
/// struct HTTPResponse;
|
||||
/// ```
|
||||
/// Use instead:
|
||||
/// ```rust
|
||||
/// struct HttpResponse;
|
||||
/// ```
|
||||
pub UPPER_CASE_ACRONYMS,
|
||||
style,
|
||||
"capitalized acronyms are against the naming convention"
|
||||
}
|
||||
|
||||
declare_lint_pass!(UpperCaseAcronyms => [UPPER_CASE_ACRONYMS]);
|
||||
|
||||
fn correct_ident(ident: &str) -> String {
|
||||
let ident = ident.chars().rev().collect::<String>();
|
||||
let fragments = ident
|
||||
.split_inclusive(|x: char| !x.is_ascii_lowercase())
|
||||
.rev()
|
||||
.map(|x| x.chars().rev().collect::<String>());
|
||||
|
||||
let mut ident = fragments.clone().next().unwrap();
|
||||
for (ref prev, ref curr) in fragments.tuple_windows() {
|
||||
if [prev, curr]
|
||||
.iter()
|
||||
.all(|s| s.len() == 1 && s.chars().next().unwrap().is_ascii_uppercase())
|
||||
{
|
||||
ident.push_str(&curr.to_ascii_lowercase());
|
||||
} else {
|
||||
ident.push_str(curr);
|
||||
}
|
||||
}
|
||||
ident
|
||||
}
|
||||
|
||||
fn check_ident(cx: &EarlyContext<'_>, ident: &Ident) {
|
||||
let span = ident.span;
|
||||
let ident = &ident.as_str();
|
||||
let corrected = correct_ident(ident);
|
||||
if ident != &corrected {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
UPPER_CASE_ACRONYMS,
|
||||
span,
|
||||
&format!("name `{}` contains a capitalized acronym", ident),
|
||||
"consider making the acronym lowercase, except the initial letter",
|
||||
corrected,
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyLintPass for UpperCaseAcronyms {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, it: &Item) {
|
||||
if_chain! {
|
||||
if !in_external_macro(cx.sess(), it.span);
|
||||
if matches!(
|
||||
it.kind,
|
||||
ItemKind::TyAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..)
|
||||
);
|
||||
then {
|
||||
check_ident(cx, &it.ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &Variant) {
|
||||
check_ident(cx, &v.ident);
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
#![warn(clippy::capitalized_acronyms)]
|
||||
|
||||
fn main() {
|
||||
// test code goes here
|
||||
}
|
|
@ -11,7 +11,7 @@ struct S {
|
|||
f: Vec<Vec<Box<(u32, u32, u32, u32)>>>,
|
||||
}
|
||||
|
||||
struct TS(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
|
||||
struct Ts(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
|
||||
|
||||
enum E {
|
||||
Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>),
|
||||
|
|
|
@ -21,7 +21,7 @@ LL | f: Vec<Vec<Box<(u32, u32, u32, u32)>>>,
|
|||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:14:11
|
||||
|
|
||||
LL | struct TS(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
|
||||
LL | struct Ts(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// originally from rustc ./src/test/ui/regions/issue-78262.rs
|
||||
// ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig()
|
||||
#![allow(clippy::upper_case_acronyms)]
|
||||
|
||||
trait TT {}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/ice-6256.rs:11:28
|
||||
--> $DIR/ice-6256.rs:12:28
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
| ^^^^ lifetime mismatch
|
||||
|
|
||||
= note: expected reference `&(dyn TT + 'static)`
|
||||
found reference `&dyn TT`
|
||||
note: the anonymous lifetime #1 defined on the body at 11:13...
|
||||
--> $DIR/ice-6256.rs:11:13
|
||||
note: the anonymous lifetime #1 defined on the body at 12:13...
|
||||
--> $DIR/ice-6256.rs:12:13
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(non_ascii_idents)]
|
||||
#![warn(clippy::enum_variant_names, clippy::pub_enum_variant_names)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_camel_case_types, clippy::upper_case_acronyms)]
|
||||
|
||||
enum FakeCallType {
|
||||
CALL,
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::needless_question_mark)]
|
||||
#![allow(clippy::needless_return, clippy::unnecessary_unwrap, dead_code, unused_must_use)]
|
||||
#![allow(
|
||||
clippy::needless_return,
|
||||
clippy::unnecessary_unwrap,
|
||||
clippy::upper_case_acronyms,
|
||||
dead_code,
|
||||
unused_must_use
|
||||
)]
|
||||
#![feature(custom_inner_attributes)]
|
||||
|
||||
struct TO {
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::needless_question_mark)]
|
||||
#![allow(clippy::needless_return, clippy::unnecessary_unwrap, dead_code, unused_must_use)]
|
||||
#![allow(
|
||||
clippy::needless_return,
|
||||
clippy::unnecessary_unwrap,
|
||||
clippy::upper_case_acronyms,
|
||||
dead_code,
|
||||
unused_must_use
|
||||
)]
|
||||
#![feature(custom_inner_attributes)]
|
||||
|
||||
struct TO {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:17:12
|
||||
--> $DIR/needless_question_mark.rs:23:12
|
||||
|
|
||||
LL | return Some(to.magic?);
|
||||
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
@ -7,79 +7,79 @@ LL | return Some(to.magic?);
|
|||
= note: `-D clippy::needless-question-mark` implied by `-D warnings`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:25:12
|
||||
--> $DIR/needless_question_mark.rs:31:12
|
||||
|
|
||||
LL | return Some(to.magic?)
|
||||
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:30:5
|
||||
--> $DIR/needless_question_mark.rs:36:5
|
||||
|
|
||||
LL | Some(to.magic?)
|
||||
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:35:21
|
||||
--> $DIR/needless_question_mark.rs:41:21
|
||||
|
|
||||
LL | to.and_then(|t| Some(t.magic?))
|
||||
| ^^^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:44:9
|
||||
--> $DIR/needless_question_mark.rs:50:9
|
||||
|
|
||||
LL | Some(t.magic?)
|
||||
| ^^^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:49:12
|
||||
--> $DIR/needless_question_mark.rs:55:12
|
||||
|
|
||||
LL | return Ok(tr.magic?);
|
||||
| ^^^^^^^^^^^^^ help: try: `tr.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:56:12
|
||||
--> $DIR/needless_question_mark.rs:62:12
|
||||
|
|
||||
LL | return Ok(tr.magic?)
|
||||
| ^^^^^^^^^^^^^ help: try: `tr.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:60:5
|
||||
--> $DIR/needless_question_mark.rs:66:5
|
||||
|
|
||||
LL | Ok(tr.magic?)
|
||||
| ^^^^^^^^^^^^^ help: try: `tr.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:64:21
|
||||
--> $DIR/needless_question_mark.rs:70:21
|
||||
|
|
||||
LL | tr.and_then(|t| Ok(t.magic?))
|
||||
| ^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:72:9
|
||||
--> $DIR/needless_question_mark.rs:78:9
|
||||
|
|
||||
LL | Ok(t.magic?)
|
||||
| ^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:79:16
|
||||
--> $DIR/needless_question_mark.rs:85:16
|
||||
|
|
||||
LL | return Ok(t.magic?);
|
||||
| ^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:132:9
|
||||
--> $DIR/needless_question_mark.rs:138:9
|
||||
|
|
||||
LL | Ok(to.magic?) // should be triggered
|
||||
| ^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:148:9
|
||||
--> $DIR/needless_question_mark.rs:154:9
|
||||
|
|
||||
LL | Some(to.magic?) // should be triggered
|
||||
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:156:9
|
||||
--> $DIR/needless_question_mark.rs:162:9
|
||||
|
|
||||
LL | Ok(to.magic?) // should be triggered
|
||||
| ^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
|
|
@ -27,7 +27,7 @@ fn buggy_ab_cmp(s1: &S, s2: &S) -> bool {
|
|||
s1.a < s2.a && s1.a < s2.b
|
||||
}
|
||||
|
||||
struct SAOnly {
|
||||
struct SaOnly {
|
||||
a: i32,
|
||||
}
|
||||
|
||||
|
@ -37,13 +37,13 @@ impl S {
|
|||
}
|
||||
}
|
||||
|
||||
fn do_not_give_bad_suggestions_for_this_unusual_expr(s1: &S, s2: &SAOnly) -> bool {
|
||||
fn do_not_give_bad_suggestions_for_this_unusual_expr(s1: &S, s2: &SaOnly) -> bool {
|
||||
// This is superficially similar to `buggy_ab_cmp`, but we should not suggest
|
||||
// `s2.b` since that is invalid.
|
||||
s1.a < s2.a && s1.a() < s1.b
|
||||
}
|
||||
|
||||
fn do_not_give_bad_suggestions_for_this_macro_expr(s1: &S, s2: &SAOnly) -> bool {
|
||||
fn do_not_give_bad_suggestions_for_this_macro_expr(s1: &S, s2: &SaOnly) -> bool {
|
||||
macro_rules! s1 {
|
||||
() => {
|
||||
S {
|
||||
|
@ -60,7 +60,7 @@ fn do_not_give_bad_suggestions_for_this_macro_expr(s1: &S, s2: &SAOnly) -> bool
|
|||
s1.a < s2.a && s1!().a < s1.b
|
||||
}
|
||||
|
||||
fn do_not_give_bad_suggestions_for_this_incorrect_expr(s1: &S, s2: &SAOnly) -> bool {
|
||||
fn do_not_give_bad_suggestions_for_this_incorrect_expr(s1: &S, s2: &SaOnly) -> bool {
|
||||
// There's two `s1.b`, but we should not suggest `s2.b` since that is invalid
|
||||
s1.a < s2.a && s1.b < s1.b
|
||||
}
|
||||
|
|
|
@ -53,10 +53,10 @@ fn transmute_ptr_to_ptr() {
|
|||
|
||||
// dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959)
|
||||
const _: &() = {
|
||||
struct ZST;
|
||||
let zst = &ZST;
|
||||
struct Zst;
|
||||
let zst = &Zst;
|
||||
|
||||
unsafe { std::mem::transmute::<&'static ZST, &'static ()>(zst) }
|
||||
unsafe { std::mem::transmute::<&'static Zst, &'static ()>(zst) }
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#![feature(or_patterns)]
|
||||
#![feature(box_patterns)]
|
||||
#![warn(clippy::unnested_or_patterns)]
|
||||
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]
|
||||
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
|
||||
#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#![feature(or_patterns)]
|
||||
#![feature(box_patterns)]
|
||||
#![warn(clippy::unnested_or_patterns)]
|
||||
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]
|
||||
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
|
||||
#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
|
||||
|
||||
fn main() {
|
||||
|
|
21
tests/ui/upper_case_acronyms.rs
Normal file
21
tests/ui/upper_case_acronyms.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
#![warn(clippy::upper_case_acronyms)]
|
||||
|
||||
struct HTTPResponse; // linted
|
||||
|
||||
struct CString; // not linted
|
||||
|
||||
enum Flags {
|
||||
NS, // linted
|
||||
CWR,
|
||||
ECE,
|
||||
URG,
|
||||
ACK,
|
||||
PSH,
|
||||
RST,
|
||||
SYN,
|
||||
FIN,
|
||||
}
|
||||
|
||||
struct GCCLLVMSomething; // linted, beware that lint suggests `GccllvmSomething` instead of `GccLlvmSomething`
|
||||
|
||||
fn main() {}
|
70
tests/ui/upper_case_acronyms.stderr
Normal file
70
tests/ui/upper_case_acronyms.stderr
Normal file
|
@ -0,0 +1,70 @@
|
|||
error: name `HTTPResponse` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:3:8
|
||||
|
|
||||
LL | struct HTTPResponse; // linted
|
||||
| ^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `HttpResponse`
|
||||
|
|
||||
= note: `-D clippy::upper-case-acronyms` implied by `-D warnings`
|
||||
|
||||
error: name `NS` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:8:5
|
||||
|
|
||||
LL | NS, // linted
|
||||
| ^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ns`
|
||||
|
||||
error: name `CWR` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:9:5
|
||||
|
|
||||
LL | CWR,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Cwr`
|
||||
|
||||
error: name `ECE` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:10:5
|
||||
|
|
||||
LL | ECE,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Ece`
|
||||
|
||||
error: name `URG` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:11:5
|
||||
|
|
||||
LL | URG,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Urg`
|
||||
|
||||
error: name `ACK` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:12:5
|
||||
|
|
||||
LL | ACK,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ack`
|
||||
|
||||
error: name `PSH` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:13:5
|
||||
|
|
||||
LL | PSH,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Psh`
|
||||
|
||||
error: name `RST` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:14:5
|
||||
|
|
||||
LL | RST,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Rst`
|
||||
|
||||
error: name `SYN` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:15:5
|
||||
|
|
||||
LL | SYN,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Syn`
|
||||
|
||||
error: name `FIN` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:16:5
|
||||
|
|
||||
LL | FIN,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin`
|
||||
|
||||
error: name `GCCLLVMSomething` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:19:8
|
||||
|
|
||||
LL | struct GCCLLVMSomething; // linted, beware that lint suggests `GccllvmSomething` instead of `GccLlvmSomething`
|
||||
| ^^^^^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `GccllvmSomething`
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#![warn(clippy::use_self)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(clippy::should_implement_trait)]
|
||||
#![allow(clippy::should_implement_trait, clippy::upper_case_acronyms)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#![warn(clippy::use_self)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(clippy::should_implement_trait)]
|
||||
#![allow(clippy::should_implement_trait, clippy::upper_case_acronyms)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue