Skip to content

Commit 78860a7

Browse files
authored
Merge pull request #3298 from devonhollowood/pedantic-dogfood-naming
Pedantic dogfood: naming and docs
2 parents 7efd4a5 + 335bc1e commit 78860a7

15 files changed

+55
-44
lines changed

clippy_lints/src/double_comparison.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ declare_clippy_lint! {
4040
"unnecessary double comparisons that can be simplified"
4141
}
4242

43-
pub struct DoubleComparisonPass;
43+
pub struct Pass;
4444

45-
impl LintPass for DoubleComparisonPass {
45+
impl LintPass for Pass {
4646
fn get_lints(&self) -> LintArray {
4747
lint_array!(DOUBLE_COMPARISONS)
4848
}
4949
}
5050

51-
impl<'a, 'tcx> DoubleComparisonPass {
51+
impl<'a, 'tcx> Pass {
52+
#[allow(clippy::similar_names)]
5253
fn check_binop(
5354
&self,
5455
cx: &LateContext<'a, 'tcx>,
@@ -87,7 +88,7 @@ impl<'a, 'tcx> DoubleComparisonPass {
8788
}
8889
}
8990

90-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisonPass {
91+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
9192
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
9293
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.node {
9394
self.check_binop(cx, kind.node, lhs, rhs, expr.span);

clippy_lints/src/enum_clike.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
6363
let variant = &var.node;
6464
if let Some(ref anon_const) = variant.disr_expr {
6565
let param_env = ty::ParamEnv::empty();
66-
let did = cx.tcx.hir.body_owner_def_id(anon_const.body);
67-
let substs = Substs::identity_for_item(cx.tcx.global_tcx(), did);
68-
let instance = ty::Instance::new(did, substs);
69-
let cid = GlobalId {
66+
let def_id = cx.tcx.hir.body_owner_def_id(anon_const.body);
67+
let substs = Substs::identity_for_item(cx.tcx.global_tcx(), def_id);
68+
let instance = ty::Instance::new(def_id, substs);
69+
let c_id = GlobalId {
7070
instance,
7171
promoted: None
7272
};
73-
let constant = cx.tcx.const_eval(param_env.and(cid)).ok();
73+
let constant = cx.tcx.const_eval(param_env.and(c_id)).ok();
7474
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) {
75-
let mut ty = cx.tcx.type_of(did);
75+
let mut ty = cx.tcx.type_of(def_id);
7676
if let ty::Adt(adt, _) = ty.sty {
7777
if adt.is_enum() {
7878
ty = adt.repr.discr_type().to_ty(cx.tcx);

clippy_lints/src/enum_variants.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::syntax::ast::*;
1616
use crate::syntax::source_map::Span;
1717
use crate::syntax::symbol::LocalInternedString;
1818
use crate::utils::{span_help_and_lint, span_lint};
19-
use crate::utils::{camel_case_from, camel_case_until, in_macro};
19+
use crate::utils::{camel_case, in_macro};
2020

2121
/// **What it does:** Detects enumeration variants that are prefixed or suffixed
2222
/// by the same characters.
@@ -184,19 +184,19 @@ fn check_variant(
184184
}
185185
}
186186
let first = var2str(&def.variants[0]);
187-
let mut pre = &first[..camel_case_until(&*first)];
188-
let mut post = &first[camel_case_from(&*first)..];
187+
let mut pre = &first[..camel_case::until(&*first)];
188+
let mut post = &first[camel_case::from(&*first)..];
189189
for var in &def.variants {
190190
let name = var2str(var);
191191

192192
let pre_match = partial_match(pre, &name);
193193
pre = &pre[..pre_match];
194-
let pre_camel = camel_case_until(pre);
194+
let pre_camel = camel_case::until(pre);
195195
pre = &pre[..pre_camel];
196196
while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() {
197197
if next.is_lowercase() {
198198
let last = pre.len() - last.len_utf8();
199-
let last_camel = camel_case_until(&pre[..last]);
199+
let last_camel = camel_case::until(&pre[..last]);
200200
pre = &pre[..last_camel];
201201
} else {
202202
break;
@@ -206,7 +206,7 @@ fn check_variant(
206206
let post_match = partial_rmatch(post, &name);
207207
let post_end = post.len() - post_match;
208208
post = &post[post_end..];
209-
let post_camel = camel_case_from(post);
209+
let post_camel = camel_case::from(post);
210210
post = &post[post_camel..];
211211
}
212212
let (what, value) = match (pre.is_empty(), post.is_empty()) {
@@ -255,6 +255,7 @@ impl EarlyLintPass for EnumVariantNames {
255255
assert!(last.is_some());
256256
}
257257

258+
#[allow(clippy::similar_names)]
258259
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
259260
let item_name = item.ident.as_str();
260261
let item_name_chars = item_name.chars().count();

clippy_lints/src/eq_op.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl LintPass for EqOp {
6363
}
6464

6565
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
66+
#[allow(clippy::similar_names)]
6667
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
6768
if let ExprKind::Binary(op, ref left, ref right) = e.node {
6869
if in_macro(e.span) {

clippy_lints/src/excessive_precision.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl ExcessivePrecision {
108108
}
109109
}
110110

111+
#[allow(clippy::doc_markdown)]
111112
/// Should we exclude the float because it has a `.0` or `.` suffix
112113
/// Ex 1_000_000_000.0
113114
/// Ex 1_000_000_000.

clippy_lints/src/if_let_redundant_pattern_matching.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl LintPass for Pass {
5656
}
5757

5858
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
59+
#[allow(clippy::similar_names)]
5960
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
6061
if let ExprKind::Match(ref op, ref arms, MatchSource::IfLetDesugar { .. }) = expr.node {
6162
if arms[0].pats.len() == 1 {

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
430430
reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
431431
reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
432432
reg.register_late_lint_pass(box types::UnitArg);
433-
reg.register_late_lint_pass(box double_comparison::DoubleComparisonPass);
434-
reg.register_late_lint_pass(box question_mark::QuestionMarkPass);
433+
reg.register_late_lint_pass(box double_comparison::Pass);
434+
reg.register_late_lint_pass(box question_mark::Pass);
435435
reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
436436
reg.register_early_lint_pass(box multiple_crate_versions::Pass);
437437
reg.register_late_lint_pass(box map_unit_fn::Pass);

clippy_lints/src/map_unit_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Op
179179
None
180180
}
181181

182-
/// Builds a name for the let binding variable (var_arg)
182+
/// Builds a name for the let binding variable (`var_arg`)
183183
///
184184
/// `x.field` => `x_field`
185185
/// `y` => `_y`

clippy_lints/src/question_mark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ declare_clippy_lint!{
4545
}
4646

4747
#[derive(Copy, Clone)]
48-
pub struct QuestionMarkPass;
48+
pub struct Pass;
4949

50-
impl LintPass for QuestionMarkPass {
50+
impl LintPass for Pass {
5151
fn get_lints(&self) -> LintArray {
5252
lint_array!(QUESTION_MARK)
5353
}
5454
}
5555

56-
impl QuestionMarkPass {
56+
impl Pass {
5757
/// Check if the given expression on the given context matches the following structure:
5858
///
5959
/// ```ignore
@@ -145,7 +145,7 @@ impl QuestionMarkPass {
145145
}
146146
}
147147

148-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for QuestionMarkPass {
148+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
149149
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
150150
Self::check_is_none_and_early_return_none(cx, expr);
151151
}

clippy_lints/src/transmute.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl LintPass for Transmute {
227227
}
228228

229229
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
230+
#[allow(clippy::similar_names)]
230231
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
231232
if let ExprKind::Call(ref path_expr, ref args) = e.node {
232233
if let ExprKind::Path(ref qpath) = path_expr.node {

clippy_lints/src/utils/camel_case.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/// Return the index of the character after the first camel-case component of
1212
/// `s`.
13-
pub fn camel_case_until(s: &str) -> usize {
13+
pub fn until(s: &str) -> usize {
1414
let mut iter = s.char_indices();
1515
if let Some((_, first)) = iter.next() {
1616
if !first.is_uppercase() {
@@ -43,7 +43,7 @@ pub fn camel_case_until(s: &str) -> usize {
4343
}
4444

4545
/// Return index of the last camel-case component of `s`.
46-
pub fn camel_case_from(s: &str) -> usize {
46+
pub fn from(s: &str) -> usize {
4747
let mut iter = s.char_indices().rev();
4848
if let Some((_, first)) = iter.next() {
4949
if !first.is_lowercase() {
@@ -73,52 +73,52 @@ pub fn camel_case_from(s: &str) -> usize {
7373

7474
#[cfg(test)]
7575
mod test {
76-
use super::{camel_case_from, camel_case_until};
76+
use super::{from, until};
7777

7878
#[test]
7979
fn from_full() {
80-
assert_eq!(camel_case_from("AbcDef"), 0);
81-
assert_eq!(camel_case_from("Abc"), 0);
80+
assert_eq!(from("AbcDef"), 0);
81+
assert_eq!(from("Abc"), 0);
8282
}
8383

8484
#[test]
8585
fn from_partial() {
86-
assert_eq!(camel_case_from("abcDef"), 3);
87-
assert_eq!(camel_case_from("aDbc"), 1);
86+
assert_eq!(from("abcDef"), 3);
87+
assert_eq!(from("aDbc"), 1);
8888
}
8989

9090
#[test]
9191
fn from_not() {
92-
assert_eq!(camel_case_from("AbcDef_"), 7);
93-
assert_eq!(camel_case_from("AbcDD"), 5);
92+
assert_eq!(from("AbcDef_"), 7);
93+
assert_eq!(from("AbcDD"), 5);
9494
}
9595

9696
#[test]
9797
fn from_caps() {
98-
assert_eq!(camel_case_from("ABCD"), 4);
98+
assert_eq!(from("ABCD"), 4);
9999
}
100100

101101
#[test]
102102
fn until_full() {
103-
assert_eq!(camel_case_until("AbcDef"), 6);
104-
assert_eq!(camel_case_until("Abc"), 3);
103+
assert_eq!(until("AbcDef"), 6);
104+
assert_eq!(until("Abc"), 3);
105105
}
106106

107107
#[test]
108108
fn until_not() {
109-
assert_eq!(camel_case_until("abcDef"), 0);
110-
assert_eq!(camel_case_until("aDbc"), 0);
109+
assert_eq!(until("abcDef"), 0);
110+
assert_eq!(until("aDbc"), 0);
111111
}
112112

113113
#[test]
114114
fn until_partial() {
115-
assert_eq!(camel_case_until("AbcDef_"), 6);
116-
assert_eq!(camel_case_until("CallTypeC"), 8);
117-
assert_eq!(camel_case_until("AbcDD"), 3);
115+
assert_eq!(until("AbcDef_"), 6);
116+
assert_eq!(until("CallTypeC"), 8);
117+
assert_eq!(until("AbcDD"), 3);
118118
}
119119

120120
#[test]
121121
fn until_caps() {
122-
assert_eq!(camel_case_until("ABCD"), 0);
122+
assert_eq!(until("ABCD"), 0);
123123
}
124-
}
124+
}

clippy_lints/src/utils/hir_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
7373
&& both(&left.expr, &right.expr, |l, r| self.eq_expr(l, r))
7474
}
7575

76+
#[allow(clippy::similar_names)]
7677
pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
7778
if self.ignore_fn && differing_macro_contexts(left.span, right.span) {
7879
return false;
@@ -208,6 +209,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
208209
}
209210
}
210211

212+
#[allow(clippy::similar_names)]
211213
fn eq_qpath(&mut self, left: &QPath, right: &QPath) -> bool {
212214
match (left, right) {
213215
(&QPath::Resolved(ref lty, ref lpath), &QPath::Resolved(ref rty, ref rpath)) => {
@@ -262,6 +264,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
262264
self.eq_ty_kind(&left.node, &right.node)
263265
}
264266

267+
#[allow(clippy::similar_names)]
265268
pub fn eq_ty_kind(&mut self, left: &TyKind, right: &TyKind) -> bool {
266269
match (left, right) {
267270
(&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),

clippy_lints/src/utils/inspector.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ fn print_decl(cx: &LateContext<'_, '_>, decl: &hir::Decl) {
166166
}
167167
}
168168

169+
#[allow(clippy::similar_names)]
169170
fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
170171
let ind = " ".repeat(indent);
171172
println!("{}+", ind);
@@ -424,6 +425,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) {
424425
}
425426
}
426427

428+
#[allow(clippy::similar_names)]
427429
fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, indent: usize) {
428430
let ind = " ".repeat(indent);
429431
println!("{}+", ind);

clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ use crate::syntax::source_map::{Span, DUMMY_SP};
3333
use crate::syntax::errors::DiagnosticBuilder;
3434
use crate::syntax::symbol::keywords;
3535

36-
mod camel_case;
37-
pub use self::camel_case::{camel_case_from, camel_case_until};
36+
pub mod camel_case;
3837

3938
pub mod comparisons;
4039
pub mod conf;

clippy_lints/src/utils/usage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct MutVarsDelegate {
5454
}
5555

5656
impl<'tcx> MutVarsDelegate {
57+
#[allow(clippy::similar_names)]
5758
fn update(&mut self, cat: &'tcx Categorization<'_>) {
5859
match *cat {
5960
Categorization::Local(id) => {

0 commit comments

Comments
 (0)