Add a new lint for unused self
This commit is contained in:
parent
8fae2dd3c1
commit
664522badd
@ -1236,6 +1236,7 @@ Released 2018-09-13
|
||||
[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect
|
||||
[`unused_io_amount`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount
|
||||
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
|
||||
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
|
||||
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
|
||||
[`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
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
|
||||
|
||||
[There are 324 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
|
||||
[There are 325 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
|
||||
|
||||
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
|
||||
|
||||
|
@ -39,7 +39,7 @@ declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
|
||||
|
||||
impl<'a, 'tcx> DoubleComparisons {
|
||||
#[allow(clippy::similar_names)]
|
||||
fn check_binop(self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
|
||||
fn check_binop(cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
|
||||
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) {
|
||||
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
|
||||
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
|
||||
@ -89,7 +89,7 @@ impl<'a, 'tcx> DoubleComparisons {
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisons {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind {
|
||||
self.check_binop(cx, kind.node, lhs, rhs, expr.span);
|
||||
Self::check_binop(cx, kind.node, lhs, rhs, expr.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,20 +32,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
|
||||
let map = cx.tcx.hir();
|
||||
// only check top level `use` statements
|
||||
for item in &m.item_ids {
|
||||
self.lint_item(cx, map.expect_item(item.id));
|
||||
lint_item(cx, map.expect_item(item.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EnumGlobUse {
|
||||
fn lint_item(self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||
if item.vis.node.is_pub() {
|
||||
return; // re-exports are fine
|
||||
}
|
||||
if let ItemKind::Use(ref path, UseKind::Glob) = item.kind {
|
||||
if let Res::Def(DefKind::Enum, _) = path.res {
|
||||
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
|
||||
}
|
||||
fn lint_item(cx: &LateContext<'_, '_>, item: &Item) {
|
||||
if item.vis.node.is_pub() {
|
||||
return; // re-exports are fine
|
||||
}
|
||||
if let ItemKind::Use(ref path, UseKind::Glob) = item.kind {
|
||||
if let Res::Def(DefKind::Enum, _) = path.res {
|
||||
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
|
||||
if let ty::Float(fty) = ty.kind;
|
||||
if let hir::ExprKind::Lit(ref lit) = expr.kind;
|
||||
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
|
||||
if let Some(sugg) = self.check(sym, fty);
|
||||
if let Some(sugg) = Self::check(sym, fty);
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
|
||||
impl ExcessivePrecision {
|
||||
// None if nothing to lint, Some(suggestion) if lint necessary
|
||||
#[must_use]
|
||||
fn check(self, sym: Symbol, fty: FloatTy) -> Option<String> {
|
||||
fn check(sym: Symbol, fty: FloatTy) -> Option<String> {
|
||||
let max = max_digits(fty);
|
||||
let sym_str = sym.as_str();
|
||||
if dot_zero_exclusion(&sym_str) {
|
||||
|
@ -222,7 +222,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
||||
}
|
||||
}
|
||||
|
||||
self.check_raw_ptr(cx, unsafety, decl, body, hir_id);
|
||||
Self::check_raw_ptr(cx, unsafety, decl, body, hir_id);
|
||||
self.check_line_number(cx, span, body);
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
||||
}
|
||||
if let hir::TraitMethod::Provided(eid) = *eid {
|
||||
let body = cx.tcx.hir().body(eid);
|
||||
self.check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id);
|
||||
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id);
|
||||
|
||||
if attr.is_none() && cx.access_levels.is_exported(item.hir_id) {
|
||||
check_must_use_candidate(
|
||||
@ -368,7 +368,6 @@ impl<'a, 'tcx> Functions {
|
||||
}
|
||||
|
||||
fn check_raw_ptr(
|
||||
self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
unsafety: hir::Unsafety,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
|
@ -53,25 +53,25 @@ enum Side {
|
||||
|
||||
impl IntPlusOne {
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
fn check_lit(self, lit: &Lit, target_value: i128) -> bool {
|
||||
fn check_lit(lit: &Lit, target_value: i128) -> bool {
|
||||
if let LitKind::Int(value, ..) = lit.kind {
|
||||
return value == (target_value as u128);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn check_binop(self, cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option<String> {
|
||||
fn check_binop(cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option<String> {
|
||||
match (binop, &lhs.kind, &rhs.kind) {
|
||||
// case where `x - 1 >= ...` or `-1 + x >= ...`
|
||||
(BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => {
|
||||
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)
|
||||
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => {
|
||||
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)
|
||||
(BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
@ -82,11 +82,11 @@ 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)
|
||||
(&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => {
|
||||
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)
|
||||
(_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
@ -97,11 +97,11 @@ 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)
|
||||
(&ExprKind::Lit(ref lit), _) if Self::check_lit(lit, 1) => {
|
||||
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)
|
||||
(_, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, lhslhs, rhs, Side::LHS)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
@ -110,12 +110,12 @@ impl IntPlusOne {
|
||||
(BinOpKind::Le, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) => {
|
||||
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)
|
||||
(BinOpKind::Add, &ExprKind::Lit(ref lit), _) if Self::check_lit(lit, -1) => {
|
||||
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)
|
||||
(BinOpKind::Sub, _, &ExprKind::Lit(ref lit)) if Self::check_lit(lit, 1) => {
|
||||
Self::generate_recommendation(cx, binop, rhslhs, lhs, Side::RHS)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
@ -125,7 +125,6 @@ impl IntPlusOne {
|
||||
}
|
||||
|
||||
fn generate_recommendation(
|
||||
self,
|
||||
cx: &EarlyContext<'_>,
|
||||
binop: BinOpKind,
|
||||
node: &Expr,
|
||||
@ -149,7 +148,7 @@ impl IntPlusOne {
|
||||
None
|
||||
}
|
||||
|
||||
fn emit_warning(self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) {
|
||||
fn emit_warning(cx: &EarlyContext<'_>, block: &Expr, recommendation: String) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
INT_PLUS_ONE,
|
||||
@ -170,8 +169,8 @@ impl IntPlusOne {
|
||||
impl EarlyLintPass for IntPlusOne {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = item.kind {
|
||||
if let Some(ref rec) = self.check_binop(cx, kind.node, lhs, rhs) {
|
||||
self.emit_warning(cx, item, rec.clone());
|
||||
if let Some(ref rec) = Self::check_binop(cx, kind.node, lhs, rhs) {
|
||||
Self::emit_warning(cx, item, rec.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -277,6 +277,7 @@ pub mod unicode;
|
||||
pub mod unsafe_removed_from_name;
|
||||
pub mod unused_io_amount;
|
||||
pub mod unused_label;
|
||||
pub mod unused_self;
|
||||
pub mod unwrap;
|
||||
pub mod use_self;
|
||||
pub mod vec;
|
||||
@ -606,6 +607,7 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry<'_>, conf: &Con
|
||||
reg.register_late_lint_pass(box trait_bounds::TraitBounds);
|
||||
reg.register_late_lint_pass(box comparison_chain::ComparisonChain);
|
||||
reg.register_late_lint_pass(box mul_add::MulAddCheck);
|
||||
reg.register_late_lint_pass(box unused_self::UnusedSelf);
|
||||
|
||||
reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
|
||||
arithmetic::FLOAT_ARITHMETIC,
|
||||
@ -926,6 +928,7 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry<'_>, conf: &Con
|
||||
unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
|
||||
unused_io_amount::UNUSED_IO_AMOUNT,
|
||||
unused_label::UNUSED_LABEL,
|
||||
unused_self::UNUSED_SELF,
|
||||
unwrap::PANICKING_UNWRAP,
|
||||
unwrap::UNNECESSARY_UNWRAP,
|
||||
vec::USELESS_VEC,
|
||||
@ -1104,6 +1107,7 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry<'_>, conf: &Con
|
||||
types::UNNECESSARY_CAST,
|
||||
types::VEC_BOX,
|
||||
unused_label::UNUSED_LABEL,
|
||||
unused_self::UNUSED_SELF,
|
||||
unwrap::UNNECESSARY_UNWRAP,
|
||||
zero_div_zero::ZERO_DIVIDED_BY_ZERO,
|
||||
]);
|
||||
|
@ -350,13 +350,13 @@ impl EarlyLintPass for LiteralDigitGrouping {
|
||||
}
|
||||
|
||||
if let ExprKind::Lit(ref lit) = expr.kind {
|
||||
self.check_lit(cx, lit)
|
||||
Self::check_lit(cx, lit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LiteralDigitGrouping {
|
||||
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
let in_macro = in_macro(lit.span);
|
||||
match lit.kind {
|
||||
LitKind::Int(..) => {
|
||||
|
@ -437,7 +437,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
||||
);
|
||||
}
|
||||
},
|
||||
ExprKind::Lit(ref lit) => self.check_lit(cx, lit),
|
||||
ExprKind::Lit(ref lit) => Self::check_lit(cx, lit),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@ -469,7 +469,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
||||
}
|
||||
|
||||
impl MiscEarlyLints {
|
||||
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
// We test if first character in snippet is a number, because the snippet could be an expansion
|
||||
// from a built-in macro like `line!()` or a proc-macro like `#[wasm_bindgen]`.
|
||||
// Note that this check also covers special case that `line!()` is eagerly expanded by compiler.
|
||||
|
@ -117,7 +117,7 @@ impl Return {
|
||||
ast::ExprKind::Ret(ref inner) => {
|
||||
// allow `#[cfg(a)] return a; #[cfg(b)] return b;`
|
||||
if !expr.attrs.iter().any(attr_is_cfg) {
|
||||
self.emit_return_lint(
|
||||
Self::emit_return_lint(
|
||||
cx,
|
||||
span.expect("`else return` is not possible"),
|
||||
inner.as_ref().map(|i| i.span),
|
||||
@ -146,13 +146,7 @@ impl Return {
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_return_lint(
|
||||
&mut self,
|
||||
cx: &EarlyContext<'_>,
|
||||
ret_span: Span,
|
||||
inner_span: Option<Span>,
|
||||
replacement: RetReplacement,
|
||||
) {
|
||||
fn emit_return_lint(cx: &EarlyContext<'_>, ret_span: Span, inner_span: Option<Span>, replacement: RetReplacement) {
|
||||
match inner_span {
|
||||
Some(inner_span) => {
|
||||
if in_external_macro(cx.sess(), inner_span) || inner_span.from_expansion() {
|
||||
@ -191,7 +185,7 @@ impl Return {
|
||||
}
|
||||
|
||||
// Check for "let x = EXPR; x"
|
||||
fn check_let_return(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
fn check_let_return(cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
let mut it = block.stmts.iter();
|
||||
|
||||
// we need both a let-binding stmt and an expr
|
||||
@ -275,7 +269,7 @@ impl EarlyLintPass for Return {
|
||||
}
|
||||
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
self.check_let_return(cx, block);
|
||||
Self::check_let_return(cx, block);
|
||||
if_chain! {
|
||||
if let Some(ref stmt) = block.stmts.last();
|
||||
if let ast::StmtKind::Expr(ref expr) = stmt.kind;
|
||||
|
@ -244,7 +244,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
|
||||
|
||||
// Check that take is applied to `repeat(0)`
|
||||
if let Some(ref repeat_expr) = take_args.get(0);
|
||||
if self.is_repeat_zero(repeat_expr);
|
||||
if Self::is_repeat_zero(repeat_expr);
|
||||
|
||||
// Check that len expression is equals to `with_capacity` expression
|
||||
if let Some(ref len_arg) = take_args.get(1);
|
||||
@ -259,7 +259,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
/// Returns `true` if given expression is `repeat(0)`
|
||||
fn is_repeat_zero(&self, expr: &Expr) -> bool {
|
||||
fn is_repeat_zero(expr: &Expr) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref fn_expr, ref repeat_args) = expr.kind;
|
||||
if let ExprKind::Path(ref qpath_repeat) = fn_expr.kind;
|
||||
|
104
clippy_lints/src/unused_self.rs
Normal file
104
clippy_lints/src/unused_self.rs
Normal file
@ -0,0 +1,104 @@
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::def::Res;
|
||||
use rustc::hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
|
||||
use rustc::hir::{AssocItemKind, HirId, ImplItemKind, ImplItemRef, Item, ItemKind, Path};
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
|
||||
use crate::utils::span_help_and_lint;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks methods that contain a `self` argument but don't use it
|
||||
///
|
||||
/// **Why is this bad?** It may be clearer to define the method as a static function instead
|
||||
/// of an instance method if it doesn't require `self`.
|
||||
///
|
||||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust,ignore
|
||||
/// struct A;
|
||||
/// impl A {
|
||||
/// fn method(&self) {}
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Could be written:
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// struct A;
|
||||
/// impl A {
|
||||
/// fn method() {}
|
||||
/// }
|
||||
/// ```
|
||||
pub UNUSED_SELF,
|
||||
complexity,
|
||||
"methods that contain a `self` argument but don't use it"
|
||||
}
|
||||
|
||||
declare_lint_pass!(UnusedSelf => [UNUSED_SELF]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &Item) {
|
||||
if item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
if let ItemKind::Impl(_, _, _, _, None, _, ref impl_item_refs) = item.kind {
|
||||
for impl_item_ref in impl_item_refs {
|
||||
if_chain! {
|
||||
if let ImplItemRef {
|
||||
kind: AssocItemKind::Method { has_self: true },
|
||||
..
|
||||
} = impl_item_ref;
|
||||
let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
|
||||
if let ImplItemKind::Method(_, body_id) = &impl_item.kind;
|
||||
then {
|
||||
// println!("Visiting method: {:?}", impl_item);
|
||||
let body = cx.tcx.hir().body(*body_id);
|
||||
let self_param = &body.params[0];
|
||||
let self_hir_id = self_param.pat.hir_id;
|
||||
let visitor = &mut UnusedSelfVisitor {
|
||||
cx,
|
||||
uses_self: false,
|
||||
self_hir_id: &self_hir_id,
|
||||
};
|
||||
visitor.visit_body(body);
|
||||
if !visitor.uses_self {
|
||||
// println!("LINTING SPAN: {:?}", &self_param.span);
|
||||
span_help_and_lint(
|
||||
cx,
|
||||
UNUSED_SELF,
|
||||
self_param.span,
|
||||
"unused `self` argument",
|
||||
"consider refactoring to a static method or function",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
struct UnusedSelfVisitor<'a, 'tcx> {
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
uses_self: bool,
|
||||
self_hir_id: &'a HirId,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for UnusedSelfVisitor<'a, 'tcx> {
|
||||
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
|
||||
if self.uses_self {
|
||||
// This function already uses `self`
|
||||
return;
|
||||
}
|
||||
if let Res::Local(hir_id) = &path.res {
|
||||
self.uses_self = self.self_hir_id == hir_id
|
||||
}
|
||||
walk_path(self, path);
|
||||
}
|
||||
|
||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||
NestedVisitorMap::All(&self.cx.tcx.hir())
|
||||
}
|
||||
}
|
@ -169,13 +169,13 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
|
||||
fn eq_generic_arg(&mut self, left: &GenericArg, right: &GenericArg) -> bool {
|
||||
match (left, right) {
|
||||
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => self.eq_lifetime(l_lt, r_lt),
|
||||
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt),
|
||||
(GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn eq_lifetime(&mut self, left: &Lifetime, right: &Lifetime) -> bool {
|
||||
fn eq_lifetime(left: &Lifetime, right: &Lifetime) -> bool {
|
||||
left.name == right.name
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ pub use lint::Lint;
|
||||
pub use lint::LINT_LEVELS;
|
||||
|
||||
// begin lint list, do not remove this comment, it’s used in `update_lints`
|
||||
pub const ALL_LINTS: [Lint; 324] = [
|
||||
pub const ALL_LINTS: [Lint; 325] = [
|
||||
Lint {
|
||||
name: "absurd_extreme_comparisons",
|
||||
group: "correctness",
|
||||
@ -2086,6 +2086,13 @@ pub const ALL_LINTS: [Lint; 324] = [
|
||||
deprecation: None,
|
||||
module: "unused_label",
|
||||
},
|
||||
Lint {
|
||||
name: "unused_self",
|
||||
group: "complexity",
|
||||
desc: "methods that contain a `self` argument but don\'t use it",
|
||||
deprecation: None,
|
||||
module: "unused_self",
|
||||
},
|
||||
Lint {
|
||||
name: "unused_unit",
|
||||
group: "style",
|
||||
|
@ -1,4 +1,5 @@
|
||||
#![warn(clippy::nonminimal_bool, clippy::logic_bug)]
|
||||
#![allow(clippy::unused_self)]
|
||||
|
||||
#[allow(unused, clippy::many_single_char_names)]
|
||||
fn main() {
|
||||
|
@ -1,18 +1,18 @@
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:10:13
|
||||
--> $DIR/booleans.rs:11:13
|
||||
|
|
||||
LL | let _ = a && b || a;
|
||||
| ^^^^^^^^^^^ help: it would look like the following: `a`
|
||||
|
|
||||
= note: `-D clippy::logic-bug` implied by `-D warnings`
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:10:18
|
||||
--> $DIR/booleans.rs:11:18
|
||||
|
|
||||
LL | let _ = a && b || a;
|
||||
| ^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:12:13
|
||||
--> $DIR/booleans.rs:13:13
|
||||
|
|
||||
LL | let _ = !true;
|
||||
| ^^^^^ help: try: `false`
|
||||
@ -20,55 +20,55 @@ LL | let _ = !true;
|
||||
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:13:13
|
||||
--> $DIR/booleans.rs:14:13
|
||||
|
|
||||
LL | let _ = !false;
|
||||
| ^^^^^^ help: try: `true`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:14:13
|
||||
--> $DIR/booleans.rs:15:13
|
||||
|
|
||||
LL | let _ = !!a;
|
||||
| ^^^ help: try: `a`
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:15:13
|
||||
--> $DIR/booleans.rs:16:13
|
||||
|
|
||||
LL | let _ = false && a;
|
||||
| ^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:15:22
|
||||
--> $DIR/booleans.rs:16:22
|
||||
|
|
||||
LL | let _ = false && a;
|
||||
| ^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:16:13
|
||||
--> $DIR/booleans.rs:17:13
|
||||
|
|
||||
LL | let _ = false || a;
|
||||
| ^^^^^^^^^^ help: try: `a`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:21:13
|
||||
--> $DIR/booleans.rs:22:13
|
||||
|
|
||||
LL | let _ = !(!a && b);
|
||||
| ^^^^^^^^^^ help: try: `!b || a`
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:31:13
|
||||
--> $DIR/booleans.rs:32:13
|
||||
|
|
||||
LL | let _ = a == b && a != b;
|
||||
| ^^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:31:13
|
||||
--> $DIR/booleans.rs:32:13
|
||||
|
|
||||
LL | let _ = a == b && a != b;
|
||||
| ^^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:32:13
|
||||
--> $DIR/booleans.rs:33:13
|
||||
|
|
||||
LL | let _ = a == b && c == 5 && a == b;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -80,7 +80,7 @@ LL | let _ = !(c != 5 || a != b);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:33:13
|
||||
--> $DIR/booleans.rs:34:13
|
||||
|
|
||||
LL | let _ = a == b && c == 5 && b == a;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -92,31 +92,31 @@ LL | let _ = !(c != 5 || a != b);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:34:13
|
||||
--> $DIR/booleans.rs:35:13
|
||||
|
|
||||
LL | let _ = a < b && a >= b;
|
||||
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:34:13
|
||||
--> $DIR/booleans.rs:35:13
|
||||
|
|
||||
LL | let _ = a < b && a >= b;
|
||||
| ^^^^^
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:35:13
|
||||
--> $DIR/booleans.rs:36:13
|
||||
|
|
||||
LL | let _ = a > b && a <= b;
|
||||
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:35:13
|
||||
--> $DIR/booleans.rs:36:13
|
||||
|
|
||||
LL | let _ = a > b && a <= b;
|
||||
| ^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:37:13
|
||||
--> $DIR/booleans.rs:38:13
|
||||
|
|
||||
LL | let _ = a != b || !(a != b || c == d);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -128,73 +128,73 @@ LL | let _ = !(a == b && c == d);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:45:13
|
||||
--> $DIR/booleans.rs:46:13
|
||||
|
|
||||
LL | let _ = !a.is_some();
|
||||
| ^^^^^^^^^^^^ help: try: `a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:47:13
|
||||
--> $DIR/booleans.rs:48:13
|
||||
|
|
||||
LL | let _ = !a.is_none();
|
||||
| ^^^^^^^^^^^^ help: try: `a.is_some()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:49:13
|
||||
--> $DIR/booleans.rs:50:13
|
||||
|
|
||||
LL | let _ = !b.is_err();
|
||||
| ^^^^^^^^^^^ help: try: `b.is_ok()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:51:13
|
||||
--> $DIR/booleans.rs:52:13
|
||||
|
|
||||
LL | let _ = !b.is_ok();
|
||||
| ^^^^^^^^^^ help: try: `b.is_err()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:53:13
|
||||
--> $DIR/booleans.rs:54:13
|
||||
|
|
||||
LL | let _ = !(a.is_some() && !c);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `c || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:54:26
|
||||
--> $DIR/booleans.rs:55:26
|
||||
|
|
||||
LL | let _ = !(!c ^ c) || !a.is_some();
|
||||
| ^^^^^^^^^^^^ help: try: `a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:55:25
|
||||
--> $DIR/booleans.rs:56:25
|
||||
|
|
||||
LL | let _ = (!c ^ c) || !a.is_some();
|
||||
| ^^^^^^^^^^^^ help: try: `a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:56:23
|
||||
--> $DIR/booleans.rs:57:23
|
||||
|
|
||||
LL | let _ = !c ^ c || !a.is_some();
|
||||
| ^^^^^^^^^^^^ help: try: `a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:128:8
|
||||
--> $DIR/booleans.rs:129:8
|
||||
|
|
||||
LL | if !res.is_ok() {}
|
||||
| ^^^^^^^^^^^^ help: try: `res.is_err()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:129:8
|
||||
--> $DIR/booleans.rs:130:8
|
||||
|
|
||||
LL | if !res.is_err() {}
|
||||
| ^^^^^^^^^^^^^ help: try: `res.is_ok()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:132:8
|
||||
--> $DIR/booleans.rs:133:8
|
||||
|
|
||||
LL | if !res.is_some() {}
|
||||
| ^^^^^^^^^^^^^^ help: try: `res.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:133:8
|
||||
--> $DIR/booleans.rs:134:8
|
||||
|
|
||||
LL | if !res.is_none() {}
|
||||
| ^^^^^^^^^^^^^^ help: try: `res.is_some()`
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![warn(clippy::all)]
|
||||
#![allow(unused, clippy::needless_pass_by_value, clippy::vec_box)]
|
||||
#![allow(unused, clippy::needless_pass_by_value, clippy::vec_box, clippy::unused_self)]
|
||||
#![feature(associated_type_defaults)]
|
||||
|
||||
type Alias = Vec<Vec<Box<(u32, u32, u32, u32)>>>; // no warning here
|
||||
|
@ -22,6 +22,7 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
|
||||
pub struct A;
|
||||
|
||||
#[allow(clippy::unused_self)]
|
||||
impl A {
|
||||
pub fn as_ref(self) -> &'static str {
|
||||
"A"
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
|
||||
--> $DIR/def_id_nocore.rs:26:19
|
||||
--> $DIR/def_id_nocore.rs:27:19
|
||||
|
|
||||
LL | pub fn as_ref(self) -> &'static str {
|
||||
| ^^^^
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![feature(never_type)]
|
||||
#![warn(clippy::diverging_sub_expression)]
|
||||
#![allow(clippy::match_same_arms, clippy::logic_bug)]
|
||||
#![allow(clippy::match_same_arms, clippy::logic_bug, clippy::unused_self)]
|
||||
|
||||
#[allow(clippy::empty_loop)]
|
||||
fn diverge() -> ! {
|
||||
|
@ -7,7 +7,8 @@
|
||||
clippy::many_single_char_names,
|
||||
clippy::needless_pass_by_value,
|
||||
clippy::option_map_unit_fn,
|
||||
clippy::trivially_copy_pass_by_ref
|
||||
clippy::trivially_copy_pass_by_ref,
|
||||
clippy::unused_self
|
||||
)]
|
||||
#![warn(
|
||||
clippy::redundant_closure,
|
||||
|
@ -7,7 +7,8 @@
|
||||
clippy::many_single_char_names,
|
||||
clippy::needless_pass_by_value,
|
||||
clippy::option_map_unit_fn,
|
||||
clippy::trivially_copy_pass_by_ref
|
||||
clippy::trivially_copy_pass_by_ref,
|
||||
clippy::unused_self
|
||||
)]
|
||||
#![warn(
|
||||
clippy::redundant_closure,
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:21:27
|
||||
--> $DIR/eta.rs:22:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| foo(a));
|
||||
| ^^^^^^^^^^ help: remove closure as shown: `foo`
|
||||
@ -7,13 +7,13 @@ LL | let a = Some(1u8).map(|a| foo(a));
|
||||
= note: `-D clippy::redundant-closure` implied by `-D warnings`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:22:10
|
||||
--> $DIR/eta.rs:23:10
|
||||
|
|
||||
LL | meta(|a| foo(a));
|
||||
| ^^^^^^^^^^ help: remove closure as shown: `foo`
|
||||
|
||||
error: this expression borrows a reference that is immediately dereferenced by the compiler
|
||||
--> $DIR/eta.rs:25:21
|
||||
--> $DIR/eta.rs:26:21
|
||||
|
|
||||
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
|
||||
| ^^^ help: change this to: `&2`
|
||||
@ -21,13 +21,13 @@ LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
|
||||
= note: `-D clippy::needless-borrow` implied by `-D warnings`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:32:27
|
||||
--> $DIR/eta.rs:33:27
|
||||
|
|
||||
LL | let e = Some(1u8).map(|a| generic(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:75:51
|
||||
--> $DIR/eta.rs:76:51
|
||||
|
|
||||
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
|
||||
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
|
||||
@ -35,43 +35,43 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
|
||||
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:77:51
|
||||
--> $DIR/eta.rs:78:51
|
||||
|
|
||||
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
|
||||
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:80:42
|
||||
--> $DIR/eta.rs:81:42
|
||||
|
|
||||
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
|
||||
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:85:29
|
||||
--> $DIR/eta.rs:86:29
|
||||
|
|
||||
LL | let e = Some("str").map(|s| s.to_string());
|
||||
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:87:27
|
||||
--> $DIR/eta.rs:88:27
|
||||
|
|
||||
LL | let e = Some('a').map(|s| s.to_uppercase());
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:90:65
|
||||
--> $DIR/eta.rs:91:65
|
||||
|
|
||||
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:173:27
|
||||
--> $DIR/eta.rs:174:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| foo_ptr(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `foo_ptr`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:178:27
|
||||
--> $DIR/eta.rs:179:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| closure(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `closure`
|
||||
|
@ -1,5 +1,6 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(clippy::unused_self)]
|
||||
#![warn(clippy::expect_fun_call)]
|
||||
|
||||
/// Checks implementation of the `EXPECT_FUN_CALL` lint
|
||||
|
@ -1,5 +1,6 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(clippy::unused_self)]
|
||||
#![warn(clippy::expect_fun_call)]
|
||||
|
||||
/// Checks implementation of the `EXPECT_FUN_CALL` lint
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:28:26
|
||||
--> $DIR/expect_fun_call.rs:29:26
|
||||
|
|
||||
LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
|
||||
@ -7,61 +7,61 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code
|
||||
= note: `-D clippy::expect-fun-call` implied by `-D warnings`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:31:26
|
||||
--> $DIR/expect_fun_call.rs:32:26
|
||||
|
|
||||
LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:41:25
|
||||
--> $DIR/expect_fun_call.rs:42:25
|
||||
|
|
||||
LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:44:25
|
||||
--> $DIR/expect_fun_call.rs:45:25
|
||||
|
|
||||
LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:56:17
|
||||
--> $DIR/expect_fun_call.rs:57:17
|
||||
|
|
||||
LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:77:21
|
||||
--> $DIR/expect_fun_call.rs:78:21
|
||||
|
|
||||
LL | Some("foo").expect(&get_string());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:78:21
|
||||
--> $DIR/expect_fun_call.rs:79:21
|
||||
|
|
||||
LL | Some("foo").expect(get_string().as_ref());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:79:21
|
||||
--> $DIR/expect_fun_call.rs:80:21
|
||||
|
|
||||
LL | Some("foo").expect(get_string().as_str());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:81:21
|
||||
--> $DIR/expect_fun_call.rs:82:21
|
||||
|
|
||||
LL | Some("foo").expect(get_static_str());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_static_str()) })`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:82:21
|
||||
--> $DIR/expect_fun_call.rs:83:21
|
||||
|
|
||||
LL | Some("foo").expect(get_non_static_str(&0));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) })`
|
||||
|
||||
error: use of `expect` followed by a function call
|
||||
--> $DIR/expect_fun_call.rs:86:16
|
||||
--> $DIR/expect_fun_call.rs:87:16
|
||||
|
|
||||
LL | Some(true).expect(&format!("key {}, {}", 1, 2));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
|
||||
|
@ -3,7 +3,8 @@
|
||||
dead_code,
|
||||
clippy::needless_lifetimes,
|
||||
clippy::needless_pass_by_value,
|
||||
clippy::trivially_copy_pass_by_ref
|
||||
clippy::trivially_copy_pass_by_ref,
|
||||
clippy::unused_self
|
||||
)]
|
||||
#![warn(clippy::extra_unused_lifetimes)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this lifetime isn't used in the function definition
|
||||
--> $DIR/extra_unused_lifetimes.rs:14:14
|
||||
--> $DIR/extra_unused_lifetimes.rs:15:14
|
||||
|
|
||||
LL | fn unused_lt<'a>(x: u8) {}
|
||||
| ^^
|
||||
@ -7,19 +7,19 @@ LL | fn unused_lt<'a>(x: u8) {}
|
||||
= note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings`
|
||||
|
||||
error: this lifetime isn't used in the function definition
|
||||
--> $DIR/extra_unused_lifetimes.rs:16:25
|
||||
--> $DIR/extra_unused_lifetimes.rs:17:25
|
||||
|
|
||||
LL | fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
|
||||
| ^^
|
||||
|
||||
error: this lifetime isn't used in the function definition
|
||||
--> $DIR/extra_unused_lifetimes.rs:41:10
|
||||
--> $DIR/extra_unused_lifetimes.rs:42:10
|
||||
|
|
||||
LL | fn x<'a>(&self) {}
|
||||
| ^^
|
||||
|
||||
error: this lifetime isn't used in the function definition
|
||||
--> $DIR/extra_unused_lifetimes.rs:67:22
|
||||
--> $DIR/extra_unused_lifetimes.rs:68:22
|
||||
|
|
||||
LL | fn unused_lt<'a>(x: u8) {}
|
||||
| ^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this function has too many arguments (8/7)
|
||||
--> $DIR/functions.rs:8:1
|
||||
--> $DIR/functions.rs:7:1
|
||||
|
|
||||
LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -7,7 +7,7 @@ LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f
|
||||
= note: `-D clippy::too-many-arguments` implied by `-D warnings`
|
||||
|
||||
error: this function has too many arguments (8/7)
|
||||
--> $DIR/functions.rs:11:1
|
||||
--> $DIR/functions.rs:10:1
|
||||
|
|
||||
LL | / fn bad_multiline(
|
||||
LL | | one: u32,
|
||||
@ -19,19 +19,19 @@ LL | | ) {
|
||||
| |__^
|
||||
|
||||
error: this function has too many arguments (8/7)
|
||||
--> $DIR/functions.rs:45:5
|
||||
--> $DIR/functions.rs:44:5
|
||||
|
|
||||
LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this function has too many arguments (8/7)
|
||||
--> $DIR/functions.rs:54:5
|
||||
--> $DIR/functions.rs:53:5
|
||||
|
|
||||
LL | fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:63:34
|
||||
--> $DIR/functions.rs:62:34
|
||||
|
|
||||
LL | println!("{}", unsafe { *p });
|
||||
| ^
|
||||
@ -39,49 +39,49 @@ LL | println!("{}", unsafe { *p });
|
||||
= note: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings`
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:64:35
|
||||
--> $DIR/functions.rs:63:35
|
||||
|
|
||||
LL | println!("{:?}", unsafe { p.as_ref() });
|
||||
| ^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:65:33
|
||||
--> $DIR/functions.rs:64:33
|
||||
|
|
||||
LL | unsafe { std::ptr::read(p) };
|
||||
| ^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:76:30
|
||||
--> $DIR/functions.rs:75:30
|
||||
|
|
||||
LL | println!("{}", unsafe { *p });
|
||||
| ^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:77:31
|
||||
--> $DIR/functions.rs:76:31
|
||||
|
|
||||
LL | println!("{:?}", unsafe { p.as_ref() });
|
||||
| ^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:78:29
|
||||
--> $DIR/functions.rs:77:29
|
||||
|
|
||||
LL | unsafe { std::ptr::read(p) };
|
||||
| ^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:87:34
|
||||
--> $DIR/functions.rs:86:34
|
||||
|
|
||||
LL | println!("{}", unsafe { *p });
|
||||
| ^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:88:35
|
||||
--> $DIR/functions.rs:87:35
|
||||
|
|
||||
LL | println!("{:?}", unsafe { p.as_ref() });
|
||||
| ^
|
||||
|
||||
error: this public function dereferences a raw pointer but is not marked `unsafe`
|
||||
--> $DIR/functions.rs:89:33
|
||||
--> $DIR/functions.rs:88:33
|
||||
|
|
||||
LL | unsafe { std::ptr::read(p) };
|
||||
| ^
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![warn(clippy::inherent_to_string)]
|
||||
#![deny(clippy::inherent_to_string_shadow_display)]
|
||||
#![allow(clippy::many_single_char_names)]
|
||||
#![allow(clippy::many_single_char_names, clippy::unused_self)]
|
||||
|
||||
use std::fmt;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
// aux-build:option_helpers.rs
|
||||
|
||||
#![allow(clippy::unused_self)]
|
||||
#![warn(clippy::iter_nth)]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
|
||||
--> $DIR/iter_nth.rs:33:23
|
||||
--> $DIR/iter_nth.rs:34:23
|
||||
|
|
||||
LL | let bad_vec = some_vec.iter().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -7,37 +7,37 @@ LL | let bad_vec = some_vec.iter().nth(3);
|
||||
= note: `-D clippy::iter-nth` implied by `-D warnings`
|
||||
|
||||
error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
|
||||
--> $DIR/iter_nth.rs:34:26
|
||||
--> $DIR/iter_nth.rs:35:26
|
||||
|
|
||||
LL | let bad_slice = &some_vec[..].iter().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
|
||||
--> $DIR/iter_nth.rs:35:31
|
||||
--> $DIR/iter_nth.rs:36:31
|
||||
|
|
||||
LL | let bad_boxed_slice = boxed_slice.iter().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable
|
||||
--> $DIR/iter_nth.rs:36:29
|
||||
--> $DIR/iter_nth.rs:37:29
|
||||
|
|
||||
LL | let bad_vec_deque = some_vec_deque.iter().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable
|
||||
--> $DIR/iter_nth.rs:41:23
|
||||
--> $DIR/iter_nth.rs:42:23
|
||||
|
|
||||
LL | let bad_vec = some_vec.iter_mut().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable
|
||||
--> $DIR/iter_nth.rs:44:26
|
||||
--> $DIR/iter_nth.rs:45:26
|
||||
|
|
||||
LL | let bad_slice = &some_vec[..].iter_mut().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable
|
||||
--> $DIR/iter_nth.rs:47:29
|
||||
--> $DIR/iter_nth.rs:48:29
|
||||
|
|
||||
LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![warn(clippy::len_without_is_empty)]
|
||||
#![allow(dead_code, unused)]
|
||||
#![allow(dead_code, unused, clippy::unused_self)]
|
||||
|
||||
pub struct PubOne;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::len_zero)]
|
||||
#![allow(dead_code, unused, clippy::len_without_is_empty)]
|
||||
#![allow(dead_code, unused, clippy::len_without_is_empty, clippy::unused_self)]
|
||||
|
||||
pub struct One;
|
||||
struct Wither;
|
||||
|
@ -1,7 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::len_zero)]
|
||||
#![allow(dead_code, unused, clippy::len_without_is_empty)]
|
||||
#![allow(dead_code, unused, clippy::len_without_is_empty, clippy::unused_self)]
|
||||
|
||||
pub struct One;
|
||||
struct Wither;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![allow(unused)]
|
||||
#![allow(unused, clippy::unused_self)]
|
||||
struct Mappable {}
|
||||
|
||||
impl Mappable {
|
||||
|
@ -2,6 +2,7 @@
|
||||
//! compilation error.
|
||||
//! The .stderr output of this test should be empty. Otherwise it's a bug somewhere.
|
||||
|
||||
#![allow(clippy::unused_self)]
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
#![feature(start)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
#![allow(clippy::let_and_return)]
|
||||
#![allow(clippy::let_and_return, clippy::unused_self)]
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![allow(unused, clippy::trivially_copy_pass_by_ref)]
|
||||
#![allow(unused, clippy::trivially_copy_pass_by_ref, clippy::unused_self)]
|
||||
#![warn(clippy::mut_from_ref)]
|
||||
|
||||
struct Foo;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![allow(unused_variables, clippy::trivially_copy_pass_by_ref)]
|
||||
#![allow(unused_variables, clippy::trivially_copy_pass_by_ref, clippy::unused_self)]
|
||||
|
||||
fn takes_an_immutable_reference(a: &i32) {}
|
||||
fn takes_a_mutable_reference(a: &mut i32) {}
|
||||
|
@ -1,5 +1,10 @@
|
||||
#![warn(clippy::needless_lifetimes)]
|
||||
#![allow(dead_code, clippy::needless_pass_by_value, clippy::trivially_copy_pass_by_ref)]
|
||||
#![allow(
|
||||
dead_code,
|
||||
clippy::needless_pass_by_value,
|
||||
clippy::trivially_copy_pass_by_ref,
|
||||
clippy::unused_self
|
||||
)]
|
||||
|
||||
fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:4:1
|
||||
--> $DIR/needless_lifetimes.rs:9:1
|
||||
|
|
||||
LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -7,13 +7,13 @@ LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
|
||||
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:6:1
|
||||
--> $DIR/needless_lifetimes.rs:11:1
|
||||
|
|
||||
LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:16:1
|
||||
--> $DIR/needless_lifetimes.rs:21:1
|
||||
|
|
||||
LL | / fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 {
|
||||
LL | | x
|
||||
@ -21,7 +21,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:45:1
|
||||
--> $DIR/needless_lifetimes.rs:50:1
|
||||
|
|
||||
LL | / fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> {
|
||||
LL | | Ok(x)
|
||||
@ -29,7 +29,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:50:1
|
||||
--> $DIR/needless_lifetimes.rs:55:1
|
||||
|
|
||||
LL | / fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()>
|
||||
LL | | where
|
||||
@ -40,13 +40,13 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:62:1
|
||||
--> $DIR/needless_lifetimes.rs:67:1
|
||||
|
|
||||
LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:86:1
|
||||
--> $DIR/needless_lifetimes.rs:91:1
|
||||
|
|
||||
LL | / fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
|
||||
LL | | where
|
||||
@ -57,7 +57,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:120:5
|
||||
--> $DIR/needless_lifetimes.rs:125:5
|
||||
|
|
||||
LL | / fn self_and_out<'s>(&'s self) -> &'s u8 {
|
||||
LL | | &self.x
|
||||
@ -65,13 +65,13 @@ LL | | }
|
||||
| |_____^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:129:5
|
||||
--> $DIR/needless_lifetimes.rs:134:5
|
||||
|
|
||||
LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:148:1
|
||||
--> $DIR/needless_lifetimes.rs:153:1
|
||||
|
|
||||
LL | / fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
|
||||
LL | | unimplemented!()
|
||||
@ -79,7 +79,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:178:1
|
||||
--> $DIR/needless_lifetimes.rs:183:1
|
||||
|
|
||||
LL | / fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
|
||||
LL | | unimplemented!()
|
||||
@ -87,7 +87,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:184:1
|
||||
--> $DIR/needless_lifetimes.rs:189:1
|
||||
|
|
||||
LL | / fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
|
||||
LL | | unimplemented!()
|
||||
@ -95,7 +95,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:203:1
|
||||
--> $DIR/needless_lifetimes.rs:208:1
|
||||
|
|
||||
LL | / fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
|
||||
LL | | unimplemented!()
|
||||
@ -103,7 +103,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:211:1
|
||||
--> $DIR/needless_lifetimes.rs:216:1
|
||||
|
|
||||
LL | / fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
|
||||
LL | | unimplemented!()
|
||||
@ -111,7 +111,7 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:247:1
|
||||
--> $DIR/needless_lifetimes.rs:252:1
|
||||
|
|
||||
LL | / fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
|
||||
LL | | unimplemented!()
|
||||
@ -119,13 +119,13 @@ LL | | }
|
||||
| |_^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:254:9
|
||||
--> $DIR/needless_lifetimes.rs:259:9
|
||||
|
|
||||
LL | fn needless_lt<'a>(x: &'a u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:258:9
|
||||
--> $DIR/needless_lifetimes.rs:263:9
|
||||
|
|
||||
LL | fn needless_lt<'a>(_x: &'a u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,7 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::option_map_unit_fn)]
|
||||
#![allow(unused)]
|
||||
#![allow(unused, clippy::unused_self)]
|
||||
|
||||
fn do_nothing<T>(_: T) {}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::option_map_unit_fn)]
|
||||
#![allow(unused)]
|
||||
#![allow(unused, clippy::unused_self)]
|
||||
|
||||
fn do_nothing<T>(_: T) {}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
struct NotARange;
|
||||
|
||||
#[allow(clippy::unused_self)]
|
||||
impl NotARange {
|
||||
fn step_by(&self, _: u32) {}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
--> $DIR/range.rs:8:13
|
||||
--> $DIR/range.rs:10:13
|
||||
|
|
||||
LL | let _ = (0..1).step_by(0);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
@ -7,25 +7,25 @@ LL | let _ = (0..1).step_by(0);
|
||||
= note: `-D clippy::iterator-step-by-zero` implied by `-D warnings`
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
--> $DIR/range.rs:12:13
|
||||
--> $DIR/range.rs:14:13
|
||||
|
|
||||
LL | let _ = (1..).step_by(0);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
--> $DIR/range.rs:13:13
|
||||
--> $DIR/range.rs:15:13
|
||||
|
|
||||
LL | let _ = (1..=2).step_by(0);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
--> $DIR/range.rs:16:13
|
||||
--> $DIR/range.rs:18:13
|
||||
|
|
||||
LL | let _ = x.step_by(0);
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: It is more idiomatic to use v1.iter().enumerate()
|
||||
--> $DIR/range.rs:24:14
|
||||
--> $DIR/range.rs:26:14
|
||||
|
|
||||
LL | let _x = v1.iter().zip(0..v1.len());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -33,7 +33,7 @@ LL | let _x = v1.iter().zip(0..v1.len());
|
||||
= note: `-D clippy::range-zip-with-len` implied by `-D warnings`
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
--> $DIR/range.rs:28:13
|
||||
--> $DIR/range.rs:30:13
|
||||
|
|
||||
LL | let _ = v1.iter().step_by(2 / 3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#![feature(never_type)]
|
||||
#![warn(clippy::result_map_unit_fn)]
|
||||
#![allow(unused)]
|
||||
#![allow(unused, clippy::unused_self)]
|
||||
|
||||
fn do_nothing<T>(_: T) {}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#![feature(never_type)]
|
||||
#![warn(clippy::result_map_unit_fn)]
|
||||
#![allow(unused)]
|
||||
#![allow(unused, clippy::unused_self)]
|
||||
|
||||
fn do_nothing<T>(_: T) {}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#[derive(Copy, Clone)]
|
||||
struct HasChars;
|
||||
|
||||
#[allow(clippy::unused_self)]
|
||||
impl HasChars {
|
||||
fn chars(self) -> std::str::Chars<'static> {
|
||||
"HasChars".chars()
|
||||
|
@ -3,6 +3,7 @@
|
||||
#[derive(Copy, Clone)]
|
||||
struct HasChars;
|
||||
|
||||
#[allow(clippy::unused_self)]
|
||||
impl HasChars {
|
||||
fn chars(self) -> std::str::Chars<'static> {
|
||||
"HasChars".chars()
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: calling `.extend(_.chars())`
|
||||
--> $DIR/string_extend.rs:18:5
|
||||
--> $DIR/string_extend.rs:19:5
|
||||
|
|
||||
LL | s.extend(abc.chars());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(abc)`
|
||||
@ -7,13 +7,13 @@ LL | s.extend(abc.chars());
|
||||
= note: `-D clippy::string-extend-chars` implied by `-D warnings`
|
||||
|
||||
error: calling `.extend(_.chars())`
|
||||
--> $DIR/string_extend.rs:21:5
|
||||
--> $DIR/string_extend.rs:22:5
|
||||
|
|
||||
LL | s.extend("abc".chars());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str("abc")`
|
||||
|
||||
error: calling `.extend(_.chars())`
|
||||
--> $DIR/string_extend.rs:24:5
|
||||
--> $DIR/string_extend.rs:25:5
|
||||
|
|
||||
LL | s.extend(def.chars());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)`
|
||||
|
@ -4,7 +4,8 @@
|
||||
#![allow(
|
||||
clippy::many_single_char_names,
|
||||
clippy::blacklisted_name,
|
||||
clippy::redundant_field_names
|
||||
clippy::redundant_field_names,
|
||||
clippy::unused_self
|
||||
)]
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:50:11
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:51:11
|
||||
|
|
||||
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `u32`
|
||||
@ -7,85 +7,85 @@ LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
|
||||
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:50:20
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:51:20
|
||||
|
|
||||
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Foo`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:50:29
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:51:29
|
||||
|
|
||||
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Baz`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:57:12
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:58:12
|
||||
|
|
||||
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^^ help: consider passing by value instead: `self`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:57:22
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:58:22
|
||||
|
|
||||
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `u32`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:57:31
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:58:31
|
||||
|
|
||||
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Foo`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:57:40
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:58:40
|
||||
|
|
||||
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Baz`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:59:16
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:60:16
|
||||
|
|
||||
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `u32`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:59:25
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:60:25
|
||||
|
|
||||
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Foo`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:59:34
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:60:34
|
||||
|
|
||||
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Baz`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:71:16
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:72:16
|
||||
|
|
||||
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `u32`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:71:25
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:72:25
|
||||
|
|
||||
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Foo`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:71:34
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:72:34
|
||||
|
|
||||
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
|
||||
| ^^^^ help: consider passing by value instead: `Baz`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:75:34
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:76:34
|
||||
|
|
||||
LL | fn trait_method(&self, _foo: &Foo);
|
||||
| ^^^^ help: consider passing by value instead: `Foo`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:79:37
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:80:37
|
||||
|
|
||||
LL | fn trait_method2(&self, _color: &Color);
|
||||
| ^^^^^^ help: consider passing by value instead: `Color`
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::unit_arg)]
|
||||
#![allow(clippy::no_effect, unused_must_use)]
|
||||
#![allow(clippy::no_effect, clippy::unused_self, unused_must_use)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::unit_arg)]
|
||||
#![allow(clippy::no_effect, unused_must_use)]
|
||||
#![allow(clippy::no_effect, clippy::unused_self, unused_must_use)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
|
107
tests/ui/unused_self.rs
Normal file
107
tests/ui/unused_self.rs
Normal file
@ -0,0 +1,107 @@
|
||||
#![warn(clippy::unused_self)]
|
||||
#![allow(clippy::boxed_local)]
|
||||
|
||||
mod unused_self {
|
||||
use std::pin::Pin;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
struct A {}
|
||||
|
||||
impl A {
|
||||
fn unused_self_move(self) {}
|
||||
fn unused_self_ref(&self) {}
|
||||
fn unused_self_mut_ref(&mut self) {}
|
||||
fn unused_self_pin_ref(self: Pin<&Self>) {}
|
||||
fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {}
|
||||
fn unused_self_pin_nested(self: Pin<Arc<Self>>) {}
|
||||
fn unused_self_box(self: Box<Self>) {}
|
||||
fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 {
|
||||
x + y
|
||||
}
|
||||
fn unused_self_class_method(&self) {
|
||||
Self::static_method();
|
||||
}
|
||||
|
||||
fn static_method() {}
|
||||
}
|
||||
}
|
||||
|
||||
mod used_self {
|
||||
use std::pin::Pin;
|
||||
|
||||
struct A {
|
||||
x: u8,
|
||||
}
|
||||
|
||||
impl A {
|
||||
fn used_self_move(self) -> u8 {
|
||||
self.x
|
||||
}
|
||||
fn used_self_ref(&self) -> u8 {
|
||||
self.x
|
||||
}
|
||||
fn used_self_mut_ref(&mut self) {
|
||||
self.x += 1
|
||||
}
|
||||
fn used_self_pin_ref(self: Pin<&Self>) -> u8 {
|
||||
self.x
|
||||
}
|
||||
fn used_self_box(self: Box<Self>) -> u8 {
|
||||
self.x
|
||||
}
|
||||
fn used_self_with_other_unused_args(&self, x: u8, y: u8) -> u8 {
|
||||
self.x
|
||||
}
|
||||
fn used_in_nested_closure(&self) -> u8 {
|
||||
let mut a = || -> u8 { self.x };
|
||||
a()
|
||||
}
|
||||
|
||||
#[allow(clippy::collapsible_if)]
|
||||
fn used_self_method_nested_conditions(&self, a: bool, b: bool, c: bool, d: bool) {
|
||||
if a {
|
||||
if b {
|
||||
if c {
|
||||
if d {
|
||||
self.used_self_ref();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn foo(&self) -> u32 {
|
||||
let mut sum = 0u32;
|
||||
for i in 0..self.x {
|
||||
sum += i as u32;
|
||||
}
|
||||
sum
|
||||
}
|
||||
|
||||
fn bar(&mut self, x: u8) -> u32 {
|
||||
let mut y = 0u32;
|
||||
for i in 0..x {
|
||||
y += self.foo()
|
||||
}
|
||||
y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod not_applicable {
|
||||
use std::fmt;
|
||||
|
||||
struct A {}
|
||||
|
||||
impl fmt::Debug for A {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "A")
|
||||
}
|
||||
}
|
||||
|
||||
impl A {
|
||||
fn method(x: u8, y: u8) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
75
tests/ui/unused_self.stderr
Normal file
75
tests/ui/unused_self.stderr
Normal file
@ -0,0 +1,75 @@
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:11:29
|
||||
|
|
||||
LL | fn unused_self_move(self) {}
|
||||
| ^^^^
|
||||
|
|
||||
= note: `-D clippy::unused-self` implied by `-D warnings`
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:12:28
|
||||
|
|
||||
LL | fn unused_self_ref(&self) {}
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:13:32
|
||||
|
|
||||
LL | fn unused_self_mut_ref(&mut self) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:14:32
|
||||
|
|
||||
LL | fn unused_self_pin_ref(self: Pin<&Self>) {}
|
||||
| ^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:15:36
|
||||
|
|
||||
LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {}
|
||||
| ^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:16:35
|
||||
|
|
||||
LL | fn unused_self_pin_nested(self: Pin<Arc<Self>>) {}
|
||||
| ^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:17:28
|
||||
|
|
||||
LL | fn unused_self_box(self: Box<Self>) {}
|
||||
| ^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:18:40
|
||||
|
|
||||
LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 {
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: unused `self` argument
|
||||
--> $DIR/unused_self.rs:21:37
|
||||
|
|
||||
LL | fn unused_self_class_method(&self) {
|
||||
| ^^^^^
|
||||
|
|
||||
= help: consider refactoring to a static method or function
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
0
tests/ui/unused_self.stdout
Normal file
0
tests/ui/unused_self.stdout
Normal file
@ -10,7 +10,7 @@
|
||||
#![rustfmt::skip]
|
||||
|
||||
#![deny(clippy::unused_unit)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(dead_code, clippy::unused_self)]
|
||||
|
||||
struct Unitter;
|
||||
impl Unitter {
|
||||
|
@ -10,7 +10,7 @@
|
||||
#![rustfmt::skip]
|
||||
|
||||
#![deny(clippy::unused_unit)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(dead_code, clippy::unused_self)]
|
||||
|
||||
struct Unitter;
|
||||
impl Unitter {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![warn(clippy::wrong_self_convention)]
|
||||
#![warn(clippy::wrong_pub_self_convention)]
|
||||
#![allow(dead_code, clippy::trivially_copy_pass_by_ref)]
|
||||
#![allow(dead_code, clippy::trivially_copy_pass_by_ref, clippy::unused_self)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user