Auto merge of #6475 - matsujika:capitalized_acronyms, r=flip1995

Add new lint `upper_case_acronyms`

Close #1335
I need some reviews on the English sentences because I feel they're messed up. ;)

changelog: Add new lint `upper_case_acronyms`
This commit is contained in:
bors 2021-01-20 10:26:01 +00:00
commit e6665e42a3
22 changed files with 255 additions and 52 deletions

View file

@ -2274,6 +2274,7 @@ Released 2018-09-13
[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings [`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_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 [`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_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 [`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 [`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding

View file

@ -57,9 +57,9 @@ impl CognitiveComplexity {
let expr = &body.value; let expr = &body.value;
let mut helper = CCHelper { cc: 1, returns: 0 }; let mut helper = CcHelper { cc: 1, returns: 0 };
helper.visit_expr(expr); 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_ty = cx.typeck_results().node_type(expr.hir_id);
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::result_type) { let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::result_type) {
returns returns
@ -136,12 +136,12 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
} }
} }
struct CCHelper { struct CcHelper {
cc: u64, cc: u64,
returns: u64, returns: u64,
} }
impl<'tcx> Visitor<'tcx> for CCHelper { impl<'tcx> Visitor<'tcx> for CcHelper {
type Map = Map<'tcx>; type Map = Map<'tcx>;
fn visit_expr(&mut self, e: &'tcx Expr<'_>) { fn visit_expr(&mut self, e: &'tcx Expr<'_>) {

View file

@ -46,8 +46,8 @@ declare_lint_pass!(IntPlusOne => [INT_PLUS_ONE]);
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
enum Side { enum Side {
LHS, Lhs,
RHS, Rhs,
} }
impl IntPlusOne { impl IntPlusOne {
@ -66,11 +66,11 @@ impl IntPlusOne {
match (lhskind.node, &lhslhs.kind, &lhsrhs.kind) { match (lhskind.node, &lhslhs.kind, &lhsrhs.kind) {
// `-1 + x` // `-1 + x`
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => { (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` // `x - 1`
(BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 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, _ => None,
} }
@ -82,10 +82,10 @@ impl IntPlusOne {
match (&rhslhs.kind, &rhsrhs.kind) { match (&rhslhs.kind, &rhsrhs.kind) {
// `y + 1` and `1 + y` // `y + 1` and `1 + y`
(&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => { (&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) => { (_, &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, _ => None,
} }
@ -97,10 +97,10 @@ impl IntPlusOne {
match (&lhslhs.kind, &lhsrhs.kind) { match (&lhslhs.kind, &lhsrhs.kind) {
// `1 + x` and `x + 1` // `1 + x` and `x + 1`
(&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 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) => { (_, &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, _ => None,
} }
@ -110,11 +110,11 @@ impl IntPlusOne {
match (rhskind.node, &rhslhs.kind, &rhsrhs.kind) { match (rhskind.node, &rhslhs.kind, &rhsrhs.kind) {
// `-1 + y` // `-1 + y`
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => { (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` // `y - 1`
(BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 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, _ => None,
} }
@ -138,8 +138,8 @@ impl IntPlusOne {
if let Some(snippet) = snippet_opt(cx, node.span) { if let Some(snippet) = snippet_opt(cx, node.span) {
if let Some(other_side_snippet) = snippet_opt(cx, other_side.span) { if let Some(other_side_snippet) = snippet_opt(cx, other_side.span) {
let rec = match side { let rec = match side {
Side::LHS => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)), Side::Lhs => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)),
Side::RHS => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)), Side::Rhs => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)),
}; };
return rec; return rec;
} }

View file

@ -341,6 +341,7 @@ mod unused_self;
mod unused_unit; mod unused_unit;
mod unwrap; mod unwrap;
mod unwrap_in_result; mod unwrap_in_result;
mod upper_case_acronyms;
mod use_self; mod use_self;
mod useless_conversion; mod useless_conversion;
mod vec; mod vec;
@ -944,6 +945,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&unwrap::PANICKING_UNWRAP, &unwrap::PANICKING_UNWRAP,
&unwrap::UNNECESSARY_UNWRAP, &unwrap::UNNECESSARY_UNWRAP,
&unwrap_in_result::UNWRAP_IN_RESULT, &unwrap_in_result::UNWRAP_IN_RESULT,
&upper_case_acronyms::UPPER_CASE_ACRONYMS,
&use_self::USE_SELF, &use_self::USE_SELF,
&useless_conversion::USELESS_CONVERSION, &useless_conversion::USELESS_CONVERSION,
&vec::USELESS_VEC, &vec::USELESS_VEC,
@ -983,7 +985,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 utils::author::Author);
store.register_late_pass(|| box await_holding_invalid::AwaitHolding); 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; 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(move || box types::Types::new(vec_box_size_threshold));
store.register_late_pass(|| box booleans::NonminimalBool); store.register_late_pass(|| box booleans::NonminimalBool);
@ -1174,6 +1176,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
let enum_variant_name_threshold = conf.enum_variant_name_threshold; 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(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 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 default::Default::default());
store.register_late_pass(|| box unused_self::UnusedSelf); store.register_late_pass(|| box unused_self::UnusedSelf);
store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall); store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall);
@ -1659,6 +1662,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&unused_unit::UNUSED_UNIT), LintId::of(&unused_unit::UNUSED_UNIT),
LintId::of(&unwrap::PANICKING_UNWRAP), LintId::of(&unwrap::PANICKING_UNWRAP),
LintId::of(&unwrap::UNNECESSARY_UNWRAP), LintId::of(&unwrap::UNNECESSARY_UNWRAP),
LintId::of(&upper_case_acronyms::UPPER_CASE_ACRONYMS),
LintId::of(&useless_conversion::USELESS_CONVERSION), LintId::of(&useless_conversion::USELESS_CONVERSION),
LintId::of(&vec::USELESS_VEC), LintId::of(&vec::USELESS_VEC),
LintId::of(&vec_init_then_push::VEC_INIT_THEN_PUSH), LintId::of(&vec_init_then_push::VEC_INIT_THEN_PUSH),
@ -1776,6 +1780,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION), LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME), LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
LintId::of(&unused_unit::UNUSED_UNIT), LintId::of(&unused_unit::UNUSED_UNIT),
LintId::of(&upper_case_acronyms::UPPER_CASE_ACRONYMS),
LintId::of(&write::PRINTLN_EMPTY_STRING), LintId::of(&write::PRINTLN_EMPTY_STRING),
LintId::of(&write::PRINT_LITERAL), LintId::of(&write::PRINT_LITERAL),
LintId::of(&write::PRINT_WITH_NEWLINE), LintId::of(&write::PRINT_WITH_NEWLINE),

View file

@ -18,9 +18,9 @@ declare_clippy_lint! {
"various things that will negatively affect your serde experience" "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<'_>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let ItemKind::Impl(Impl { if let ItemKind::Impl(Impl {
of_trait: Some(ref trait_ref), of_trait: Some(ref trait_ref),

View 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);
}
}

View file

@ -11,7 +11,7 @@ struct S {
f: Vec<Vec<Box<(u32, u32, u32, u32)>>>, 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 { enum E {
Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>), Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>),

View file

@ -21,7 +21,7 @@ LL | f: Vec<Vec<Box<(u32, u32, u32, u32)>>>,
error: very complex type used. Consider factoring parts into `type` definitions error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/complex_types.rs:14:11 --> $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 error: very complex type used. Consider factoring parts into `type` definitions

View file

@ -1,5 +1,6 @@
// originally from rustc ./src/test/ui/regions/issue-78262.rs // 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() // ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig()
#![allow(clippy::upper_case_acronyms)]
trait TT {} trait TT {}

View file

@ -1,13 +1,13 @@
error[E0308]: mismatched types 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 LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
| ^^^^ lifetime mismatch | ^^^^ lifetime mismatch
| |
= note: expected reference `&(dyn TT + 'static)` = note: expected reference `&(dyn TT + 'static)`
found reference `&dyn TT` found reference `&dyn TT`
note: the anonymous lifetime #1 defined on the body at 11:13... note: the anonymous lifetime #1 defined on the body at 12:13...
--> $DIR/ice-6256.rs:11:13 --> $DIR/ice-6256.rs:12:13
| |
LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,6 +1,6 @@
#![feature(non_ascii_idents)] #![feature(non_ascii_idents)]
#![warn(clippy::enum_variant_names, clippy::pub_enum_variant_names)] #![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 { enum FakeCallType {
CALL, CALL,

View file

@ -1,7 +1,13 @@
// run-rustfix // run-rustfix
#![warn(clippy::needless_question_mark)] #![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)] #![feature(custom_inner_attributes)]
struct TO { struct TO {

View file

@ -1,7 +1,13 @@
// run-rustfix // run-rustfix
#![warn(clippy::needless_question_mark)] #![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)] #![feature(custom_inner_attributes)]
struct TO { struct TO {

View file

@ -1,5 +1,5 @@
error: Question mark operator is useless here 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?); LL | return Some(to.magic?);
| ^^^^^^^^^^^^^^^ help: try: `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` = note: `-D clippy::needless-question-mark` implied by `-D warnings`
error: Question mark operator is useless here 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?) LL | return Some(to.magic?)
| ^^^^^^^^^^^^^^^ help: try: `to.magic` | ^^^^^^^^^^^^^^^ help: try: `to.magic`
error: Question mark operator is useless here 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?) LL | Some(to.magic?)
| ^^^^^^^^^^^^^^^ help: try: `to.magic` | ^^^^^^^^^^^^^^^ help: try: `to.magic`
error: Question mark operator is useless here 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?)) LL | to.and_then(|t| Some(t.magic?))
| ^^^^^^^^^^^^^^ help: try: `t.magic` | ^^^^^^^^^^^^^^ help: try: `t.magic`
error: Question mark operator is useless here 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?) LL | Some(t.magic?)
| ^^^^^^^^^^^^^^ help: try: `t.magic` | ^^^^^^^^^^^^^^ help: try: `t.magic`
error: Question mark operator is useless here 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?); LL | return Ok(tr.magic?);
| ^^^^^^^^^^^^^ help: try: `tr.magic` | ^^^^^^^^^^^^^ help: try: `tr.magic`
error: Question mark operator is useless here 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?) LL | return Ok(tr.magic?)
| ^^^^^^^^^^^^^ help: try: `tr.magic` | ^^^^^^^^^^^^^ help: try: `tr.magic`
error: Question mark operator is useless here 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?) LL | Ok(tr.magic?)
| ^^^^^^^^^^^^^ help: try: `tr.magic` | ^^^^^^^^^^^^^ help: try: `tr.magic`
error: Question mark operator is useless here 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?)) LL | tr.and_then(|t| Ok(t.magic?))
| ^^^^^^^^^^^^ help: try: `t.magic` | ^^^^^^^^^^^^ help: try: `t.magic`
error: Question mark operator is useless here 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?) LL | Ok(t.magic?)
| ^^^^^^^^^^^^ help: try: `t.magic` | ^^^^^^^^^^^^ help: try: `t.magic`
error: Question mark operator is useless here 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?); LL | return Ok(t.magic?);
| ^^^^^^^^^^^^ help: try: `t.magic` | ^^^^^^^^^^^^ help: try: `t.magic`
error: Question mark operator is useless here 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 LL | Ok(to.magic?) // should be triggered
| ^^^^^^^^^^^^^ help: try: `to.magic` | ^^^^^^^^^^^^^ help: try: `to.magic`
error: Question mark operator is useless here 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 LL | Some(to.magic?) // should be triggered
| ^^^^^^^^^^^^^^^ help: try: `to.magic` | ^^^^^^^^^^^^^^^ help: try: `to.magic`
error: Question mark operator is useless here 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 LL | Ok(to.magic?) // should be triggered
| ^^^^^^^^^^^^^ help: try: `to.magic` | ^^^^^^^^^^^^^ help: try: `to.magic`

View file

@ -27,7 +27,7 @@ fn buggy_ab_cmp(s1: &S, s2: &S) -> bool {
s1.a < s2.a && s1.a < s2.b s1.a < s2.a && s1.a < s2.b
} }
struct SAOnly { struct SaOnly {
a: i32, 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 // This is superficially similar to `buggy_ab_cmp`, but we should not suggest
// `s2.b` since that is invalid. // `s2.b` since that is invalid.
s1.a < s2.a && s1.a() < s1.b 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 { macro_rules! s1 {
() => { () => {
S { 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 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 // There's two `s1.b`, but we should not suggest `s2.b` since that is invalid
s1.a < s2.a && s1.b < s1.b s1.a < s2.a && s1.b < s1.b
} }

View file

@ -53,10 +53,10 @@ fn transmute_ptr_to_ptr() {
// dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) // dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959)
const _: &() = { const _: &() = {
struct ZST; struct Zst;
let zst = &ZST; let zst = &Zst;
unsafe { std::mem::transmute::<&'static ZST, &'static ()>(zst) } unsafe { std::mem::transmute::<&'static Zst, &'static ()>(zst) }
}; };
fn main() {} fn main() {}

View file

@ -3,7 +3,7 @@
#![feature(or_patterns)] #![feature(or_patterns)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![warn(clippy::unnested_or_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)] #![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
fn main() { fn main() {

View file

@ -3,7 +3,7 @@
#![feature(or_patterns)] #![feature(or_patterns)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![warn(clippy::unnested_or_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)] #![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
fn main() { fn main() {

View 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() {}

View 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

View file

@ -3,7 +3,7 @@
#![warn(clippy::use_self)] #![warn(clippy::use_self)]
#![allow(dead_code)] #![allow(dead_code)]
#![allow(clippy::should_implement_trait)] #![allow(clippy::should_implement_trait, clippy::upper_case_acronyms)]
fn main() {} fn main() {}

View file

@ -3,7 +3,7 @@
#![warn(clippy::use_self)] #![warn(clippy::use_self)]
#![allow(dead_code)] #![allow(dead_code)]
#![allow(clippy::should_implement_trait)] #![allow(clippy::should_implement_trait, clippy::upper_case_acronyms)]
fn main() {} fn main() {}