From 2430e06a60ca23960bb746af30742607ae41bdb0 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 21 Aug 2017 13:32:12 +0200 Subject: [PATCH] Run Dogfood for `use_self` --- CHANGELOG.md | 3 +++ clippy_lints/src/blacklisted_name.rs | 4 ++-- clippy_lints/src/consts.rs | 8 ++++---- clippy_lints/src/cyclomatic_complexity.rs | 2 +- clippy_lints/src/doc.rs | 4 ++-- clippy_lints/src/enum_variants.rs | 4 ++-- clippy_lints/src/functions.rs | 4 ++-- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/lifetimes.rs | 4 ++-- clippy_lints/src/literal_digit_grouping.rs | 14 +++++++------- clippy_lints/src/missing_doc.rs | 8 ++++---- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/types.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 6 +++--- clippy_lints/src/utils/mod.rs | 4 ++-- clippy_lints/src/utils/sugg.rs | 10 ++++++---- 17 files changed, 44 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb1c606d736..6bf262bb72f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.154 +* Fix [`use_self`] triggering inside derives + ## 0.0.153 * Update to *rustc 1.21.0-nightly (8c303ed87 2017-08-20)* * New lint: [`use_self`] diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index e88e4108d3d..e46d8e4855f 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -26,8 +26,8 @@ pub struct BlackListedName { } impl BlackListedName { - pub fn new(blacklist: Vec) -> BlackListedName { - BlackListedName { blacklist: blacklist } + pub fn new(blacklist: Vec) -> Self { + Self { blacklist: blacklist } } } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 2a6fa051d2f..0a76b95931d 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -23,7 +23,7 @@ pub enum FloatWidth { } impl From for FloatWidth { - fn from(ty: FloatTy) -> FloatWidth { + fn from(ty: FloatTy) -> Self { match ty { FloatTy::F32 => FloatWidth::F32, FloatTy::F64 => FloatWidth::F64, @@ -55,7 +55,7 @@ pub enum Constant { } impl PartialEq for Constant { - fn eq(&self, other: &Constant) -> bool { + fn eq(&self, other: &Self) -> bool { match (self, other) { (&Constant::Str(ref ls, ref l_sty), &Constant::Str(ref rs, ref r_sty)) => ls == rs && l_sty == r_sty, (&Constant::Binary(ref l), &Constant::Binary(ref r)) => l == r, @@ -123,7 +123,7 @@ impl Hash for Constant { } impl PartialOrd for Constant { - fn partial_cmp(&self, other: &Constant) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { match (self, other) { (&Constant::Str(ref ls, ref l_sty), &Constant::Str(ref rs, ref r_sty)) => { if l_sty == r_sty { @@ -297,7 +297,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { }; let param_env = self.param_env.and((def_id, substs)); if let Some((def_id, substs)) = lookup_const_by_id(self.tcx, param_env) { - let mut cx = ConstEvalLateContext { + let mut cx = Self { tcx: self.tcx, tables: self.tcx.typeck_tables_of(def_id), needed_resolution: false, diff --git a/clippy_lints/src/cyclomatic_complexity.rs b/clippy_lints/src/cyclomatic_complexity.rs index c7593a195ff..9596e9812ad 100644 --- a/clippy_lints/src/cyclomatic_complexity.rs +++ b/clippy_lints/src/cyclomatic_complexity.rs @@ -31,7 +31,7 @@ pub struct CyclomaticComplexity { impl CyclomaticComplexity { pub fn new(limit: u64) -> Self { - CyclomaticComplexity { limit: LimitStack::new(limit) } + Self { limit: LimitStack::new(limit) } } } diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 3ca71694bbd..c3eba53e035 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -37,7 +37,7 @@ pub struct Doc { impl Doc { pub fn new(valid_idents: Vec) -> Self { - Doc { valid_idents: valid_idents } + Self { valid_idents: valid_idents } } } @@ -62,7 +62,7 @@ struct Parser<'a> { } impl<'a> Parser<'a> { - fn new(parser: pulldown_cmark::Parser<'a>) -> Parser<'a> { + fn new(parser: pulldown_cmark::Parser<'a>) -> Self { Self { parser: parser } } } diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 1227de69db2..eee4e2a7ee1 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -104,8 +104,8 @@ pub struct EnumVariantNames { } impl EnumVariantNames { - pub fn new(threshold: u64) -> EnumVariantNames { - EnumVariantNames { + pub fn new(threshold: u64) -> Self { + Self { modules: Vec::new(), threshold: threshold, } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 9d9bf38c397..70ff96d36d4 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -59,8 +59,8 @@ pub struct Functions { } impl Functions { - pub fn new(threshold: u64) -> Functions { - Functions { threshold: threshold } + pub fn new(threshold: u64) -> Self { + Self { threshold: threshold } } } diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 73a62c97bc8..917e0b77370 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -34,7 +34,7 @@ pub struct LargeEnumVariant { impl LargeEnumVariant { pub fn new(maximum_size_difference_allowed: u64) -> Self { - LargeEnumVariant { maximum_size_difference_allowed: maximum_size_difference_allowed } + Self { maximum_size_difference_allowed: maximum_size_difference_allowed } } } diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 507373fede5..47cc41c472c 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -254,8 +254,8 @@ struct RefVisitor<'a, 'tcx: 'a> { } impl<'v, 't> RefVisitor<'v, 't> { - fn new(cx: &'v LateContext<'v, 't>) -> RefVisitor<'v, 't> { - RefVisitor { + fn new(cx: &'v LateContext<'v, 't>) -> Self { + Self { cx: cx, lts: Vec::new(), abort: false, diff --git a/clippy_lints/src/literal_digit_grouping.rs b/clippy_lints/src/literal_digit_grouping.rs index 0da8ffd0a30..dbb1a7a9b86 100644 --- a/clippy_lints/src/literal_digit_grouping.rs +++ b/clippy_lints/src/literal_digit_grouping.rs @@ -95,7 +95,7 @@ struct DigitInfo<'a> { } impl<'a> DigitInfo<'a> { - pub fn new(lit: &str, float: bool) -> DigitInfo { + pub fn new(lit: &'a str, float: bool) -> Self { // Determine delimiter for radix prefix, if present, and radix. let radix = if lit.starts_with("0x") { Radix::Hexadecimal @@ -120,7 +120,7 @@ impl<'a> DigitInfo<'a> { if !float && (d == 'i' || d == 'u') || float && d == 'f' { let suffix_start = if last_d == '_' { d_idx - 1 } else { d_idx }; let (digits, suffix) = sans_prefix.split_at(suffix_start); - return DigitInfo { + return Self { digits: digits, radix: radix, prefix: prefix, @@ -132,7 +132,7 @@ impl<'a> DigitInfo<'a> { } // No suffix found - DigitInfo { + Self { digits: sans_prefix, radix: radix, prefix: prefix, @@ -257,7 +257,7 @@ impl LiteralDigitGrouping { char::to_digit(firstch, 10).is_some() ], { let digit_info = DigitInfo::new(&src, false); - let _ = LiteralDigitGrouping::do_lint(digit_info.digits).map_err(|warning_type| { + let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| { warning_type.display(&digit_info.grouping_hint(), cx, &lit.span) }); }} @@ -278,14 +278,14 @@ impl LiteralDigitGrouping { // Lint integral and fractional parts separately, and then check consistency of digit // groups if both pass. - let _ = LiteralDigitGrouping::do_lint(parts[0]) + let _ = Self::do_lint(parts[0]) .map(|integral_group_size| { if parts.len() > 1 { // Lint the fractional part of literal just like integral part, but reversed. let fractional_part = &parts[1].chars().rev().collect::(); - let _ = LiteralDigitGrouping::do_lint(fractional_part) + let _ = Self::do_lint(fractional_part) .map(|fractional_group_size| { - let consistent = LiteralDigitGrouping::parts_consistent(integral_group_size, fractional_group_size, parts[0].len(), parts[1].len()); + let consistent = Self::parts_consistent(integral_group_size, fractional_group_size, parts[0].len(), parts[1].len()); if !consistent { WarningType::InconsistentDigitGrouping.display(&digit_info.grouping_hint(), cx, &lit.span); } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index f0c417f4646..21e19a3af84 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -56,14 +56,14 @@ pub struct MissingDoc { } impl ::std::default::Default for MissingDoc { - fn default() -> MissingDoc { - MissingDoc::new() + fn default() -> Self { + Self::new() } } impl MissingDoc { - pub fn new() -> MissingDoc { - MissingDoc { doc_hidden_stack: vec![false] } + pub fn new() -> Self { + Self { doc_hidden_stack: vec![false] } } fn doc_hidden(&self) -> bool { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index e4efaf495a8..b7de586ed80 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -197,7 +197,7 @@ struct MovedVariablesCtxt<'a, 'tcx: 'a> { impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> { fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { - MovedVariablesCtxt { + Self { cx: cx, moved_vars: HashSet::new(), spans_need_deref: HashMap::new(), diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 9d6167cc041..ea3db0e4690 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -730,7 +730,7 @@ pub struct TypeComplexityPass { impl TypeComplexityPass { pub fn new(threshold: u64) -> Self { - TypeComplexityPass { threshold: threshold } + Self { threshold: threshold } } } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 7466ee9080b..a7fdc3d281b 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -147,7 +147,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { impl PrintVisitor { fn new(s: &'static str) -> Self { - PrintVisitor { + Self { ids: HashMap::new(), current: s.to_owned(), } diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 658a07ca146..b4caad0845a 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -23,14 +23,14 @@ pub struct SpanlessEq<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { - SpanlessEq { + Self { cx: cx, ignore_fn: false, } } pub fn ignore_fn(self) -> Self { - SpanlessEq { + Self { cx: self.cx, ignore_fn: true, } @@ -283,7 +283,7 @@ pub struct SpanlessHash<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { - SpanlessHash { + Self { cx: cx, s: DefaultHasher::new(), } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 01788edfc7e..7f8603f0f27 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -670,8 +670,8 @@ impl Drop for LimitStack { } impl LimitStack { - pub fn new(limit: u64) -> LimitStack { - LimitStack { stack: vec![limit] } + pub fn new(limit: u64) -> Self { + Self { stack: vec![limit] } } pub fn limit(&self) -> u64 { *self.stack.last().expect( diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index d46a6526395..6cfbe8c935e 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -1,5 +1,7 @@ //! Contains utility functions to generate suggestions. #![deny(missing_docs_in_private_items)] +// currently ignores lifetimes and generics +#![allow(use_self)] use rustc::hir; use rustc::lint::{EarlyContext, LateContext, LintContext}; @@ -41,7 +43,7 @@ impl<'a> Display for Sugg<'a> { #[allow(wrong_self_convention)] // ok, because of the function `as_ty` method impl<'a> Sugg<'a> { /// Prepare a suggestion from an expression. - pub fn hir_opt(cx: &LateContext, expr: &hir::Expr) -> Option> { + pub fn hir_opt(cx: &LateContext, expr: &hir::Expr) -> Option { snippet_opt(cx, expr.span).map(|snippet| { let snippet = Cow::Owned(snippet); match expr.node { @@ -80,12 +82,12 @@ impl<'a> Sugg<'a> { /// Convenience function around `hir_opt` for suggestions with a default /// text. - pub fn hir(cx: &LateContext, expr: &hir::Expr, default: &'a str) -> Sugg<'a> { + pub fn hir(cx: &LateContext, expr: &hir::Expr, default: &'a str) -> Self { Self::hir_opt(cx, expr).unwrap_or_else(|| Sugg::NonParen(Cow::Borrowed(default))) } /// Prepare a suggestion from an expression. - pub fn ast(cx: &EarlyContext, expr: &ast::Expr, default: &'a str) -> Sugg<'a> { + pub fn ast(cx: &EarlyContext, expr: &ast::Expr, default: &'a str) -> Self { use syntax::ast::RangeLimits; let snippet = snippet(cx, expr.span, default); @@ -218,7 +220,7 @@ struct ParenHelper { impl ParenHelper { /// Build a `ParenHelper`. fn new(paren: bool, wrapped: T) -> Self { - ParenHelper { + Self { paren: paren, wrapped: wrapped, }