Merge remote-tracking branch 'origin/master' into yati_master

This commit is contained in:
Oliver Schneider 2017-04-25 10:31:40 +02:00
commit 68369e5d37
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9
53 changed files with 717 additions and 687 deletions

View File

@ -1,6 +1,18 @@
# Change Log
All notable changes to this project will be documented in this file.
## 0.0.126 — 2017-04-24
* Update to *rustc 1.18.0-nightly (2bd4b5c6d 2017-04-23)*
## 0.0.125 — 2017-04-19
* Update to *rustc 1.18.0-nightly (9f2abadca 2017-04-18)*
## 0.0.124 — 2017-04-16
* Update to *rustc 1.18.0-nightly (d5cf1cb64 2017-04-15)*
## 0.0.123 — 2017-04-07
* Fix various false positives
## 0.0.122 — 2017-04-07
* Rustup to *rustc 1.18.0-nightly (91ae22a01 2017-04-05)*
* New lint: [`op_ref`]

View File

@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.0.122"
version = "0.0.126"
authors = [
"Manish Goregaokar <manishsmail@gmail.com>",
"Andre Bogus <bogusandre@gmail.com>",
@ -30,7 +30,7 @@ test = false
[dependencies]
# begin automatic update
clippy_lints = { version = "0.0.122", path = "clippy_lints" }
clippy_lints = { version = "0.0.126", path = "clippy_lints" }
# end automatic update
cargo_metadata = "0.1.1"

View File

@ -1,7 +1,7 @@
[package]
name = "clippy_lints"
# begin automatic update
version = "0.0.122"
version = "0.0.126"
# end automatic update
authors = [
"Manish Goregaokar <manishsmail@gmail.com>",

View File

@ -1,9 +1,10 @@
use rustc::hir::*;
use rustc::hir::def::Def;
use rustc::lint::*;
use rustc::ty;
use rustc_const_eval::lookup_const_by_id;
use syntax::ast::LitKind;
use syntax::codemap::Span;
use syntax::codemap::{Span, DUMMY_SP};
use utils::span_lint;
/// **What it does:** Checks for incompatible bit masks in comparisons.
@ -249,7 +250,15 @@ fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u128> {
ExprPath(ref qpath) => {
let def = cx.tables.qpath_def(qpath, lit.id);
if let Def::Const(def_id) = def {
lookup_const_by_id(cx.tcx, def_id, Substs::empty()).and_then(|(l, _ty)| fetch_int_literal(cx, l))
lookup_const_by_id(cx.tcx, def_id, Substs::empty()).and_then(|(l, _ty)| {
let body = if let Some(id) = cx.tcx.hir.as_local_node_id(l) {
ty::queries::mir_const_qualif::get(cx.tcx, DUMMY_SP, def_id);
cx.tcx.hir.body(cx.tcx.hir.body_owned_by(id))
} else {
cx.tcx.sess.cstore.item_body(cx.tcx, def_id)
};
fetch_int_literal(cx, &body.value)
})
} else {
None
}

View File

@ -13,6 +13,7 @@ use std::mem;
use std::rc::Rc;
use syntax::ast::{FloatTy, LitKind, StrStyle, NodeId};
use syntax::ptr::P;
use syntax::codemap::DUMMY_SP;
#[derive(Debug, Copy, Clone)]
pub enum FloatWidth {
@ -286,13 +287,19 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
let substs = self.tables
.node_id_item_substs(id)
.unwrap_or_else(|| self.tcx.intern_substs(&[]));
if let Some((const_expr, tables)) = lookup_const_by_id(self.tcx, def_id, substs) {
if let Some((const_expr, _)) = lookup_const_by_id(self.tcx, def_id, substs) {
let mut cx = ConstEvalLateContext {
tcx: self.tcx,
tables: tables,
tables: self.tcx.item_tables(const_expr),
needed_resolution: false,
};
let ret = cx.expr(const_expr);
let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
ty::queries::mir_const_qualif::get(self.tcx, DUMMY_SP, def_id);
self.tcx.hir.body(self.tcx.hir.body_owned_by(id))
} else {
self.tcx.sess.cstore.item_body(self.tcx, def_id)
};
let ret = cx.expr(&body.value);
if ret.is_some() {
self.needed_resolution = true;
}

View File

@ -223,7 +223,7 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
/// `if a { c } else if b { d } else { e }`.
fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
let mut conds = SmallVector::new();
let mut blocks : SmallVector<&Block> = SmallVector::new();
let mut blocks: SmallVector<&Block> = SmallVector::new();
while let ExprIf(ref cond, ref then_expr, ref else_expr) = expr.node {
conds.push(&**cond);
@ -315,10 +315,10 @@ fn search_same<T, Hash, Eq>(exprs: &[T], hash: Hash, eq: Eq) -> Option<(&T, &T)>
return None;
} else if exprs.len() == 2 {
return if eq(&exprs[0], &exprs[1]) {
Some((&exprs[0], &exprs[1]))
} else {
None
};
Some((&exprs[0], &exprs[1]))
} else {
None
};
}
let mut map: HashMap<_, Vec<&_>> = HashMap::with_capacity(exprs.len());

View File

@ -46,11 +46,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
if let Some((ty, map, key)) = check_cond(cx, check) {
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
// we can give a better error message
let sole_expr = {
let sole_expr = {
else_block.is_none() &&
if let ExprBlock(ref then_block) = then_block.node {
(then_block.expr.is_some() as usize) + then_block.stmts.len() == 1
} else {
} else {
true
}
};

View File

@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
let variant = &var.node;
if let Some(body_id) = variant.disr_expr {
use rustc_const_eval::*;
let constcx = ConstContext::new(cx.tcx, body_id);
let constcx = ConstContext::with_tables(cx.tcx, cx.tcx.body_tables(body_id));
let bad = match constcx.eval(&cx.tcx.hir.body(body_id).value) {
Ok(ConstVal::Integral(Usize(Us64(i)))) => i as u32 as u64 != i,
Ok(ConstVal::Integral(Isize(Is64(i)))) => i as i32 as i64 != i,

View File

@ -56,9 +56,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
if is_valid_operator(op) {
if SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
span_lint(cx,
EQ_OP,
e.span,
&format!("equal expressions as operands to `{}`", op.node.as_str()));
EQ_OP,
e.span,
&format!("equal expressions as operands to `{}`", op.node.as_str()));
} else {
let trait_id = match op.node {
BiAdd => cx.tcx.lang_items.add_trait(),
@ -66,19 +66,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
BiMul => cx.tcx.lang_items.mul_trait(),
BiDiv => cx.tcx.lang_items.div_trait(),
BiRem => cx.tcx.lang_items.rem_trait(),
BiAnd |
BiOr => None,
BiAnd | BiOr => None,
BiBitXor => cx.tcx.lang_items.bitxor_trait(),
BiBitAnd => cx.tcx.lang_items.bitand_trait(),
BiBitOr => cx.tcx.lang_items.bitor_trait(),
BiShl => cx.tcx.lang_items.shl_trait(),
BiShr => cx.tcx.lang_items.shr_trait(),
BiNe |
BiEq => cx.tcx.lang_items.eq_trait(),
BiLt |
BiLe |
BiGe |
BiGt => cx.tcx.lang_items.ord_trait(),
BiNe | BiEq => cx.tcx.lang_items.eq_trait(),
BiLt | BiLe | BiGe | BiGt => cx.tcx.lang_items.ord_trait(),
};
if let Some(trait_id) = trait_id {
#[allow(match_same_arms)]
@ -90,57 +85,55 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
(&ExprAddrOf(_, ref l), &ExprAddrOf(_, ref r)) => {
if implements_trait(cx, cx.tables.expr_ty(l), trait_id, &[cx.tables.expr_ty(r)], None) {
span_lint_and_then(cx,
OP_REF,
e.span,
"taken reference of both operands, which is done automatically by the operator anyway",
|db| {
let lsnip = snippet(cx, l.span, "...").to_string();
let rsnip = snippet(cx, r.span, "...").to_string();
multispan_sugg(db,
"use the values directly".to_string(),
vec![(left.span, lsnip),
OP_REF,
e.span,
"taken reference of both operands, which is done automatically \
by the operator anyway",
|db| {
let lsnip = snippet(cx, l.span, "...").to_string();
let rsnip = snippet(cx, r.span, "...").to_string();
multispan_sugg(db,
"use the values directly".to_string(),
vec![(left.span, lsnip),
(right.span, rsnip)]);
}
)
})
}
}
},
// &foo == bar
(&ExprAddrOf(_, ref l), _) => {
if implements_trait(cx, cx.tables.expr_ty(l), trait_id, &[cx.tables.expr_ty(right)], None) {
span_lint_and_then(cx,
OP_REF,
e.span,
"taken reference of left operand",
|db| {
let lsnip = snippet(cx, l.span, "...").to_string();
let rsnip = Sugg::hir(cx, right, "...").deref().to_string();
multispan_sugg(db,
"dereference the right operand instead".to_string(),
vec![(left.span, lsnip),
if implements_trait(cx,
cx.tables.expr_ty(l),
trait_id,
&[cx.tables.expr_ty(right)],
None) {
span_lint_and_then(cx, OP_REF, e.span, "taken reference of left operand", |db| {
let lsnip = snippet(cx, l.span, "...").to_string();
let rsnip = Sugg::hir(cx, right, "...").deref().to_string();
multispan_sugg(db,
"dereference the right operand instead".to_string(),
vec![(left.span, lsnip),
(right.span, rsnip)]);
}
)
})
}
}
},
// foo == &bar
(_, &ExprAddrOf(_, ref r)) => {
if implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[cx.tables.expr_ty(r)], None) {
span_lint_and_then(cx,
OP_REF,
e.span,
"taken reference of right operand",
|db| {
let lsnip = Sugg::hir(cx, left, "...").deref().to_string();
let rsnip = snippet(cx, r.span, "...").to_string();
multispan_sugg(db,
"dereference the left operand instead".to_string(),
vec![(left.span, lsnip),
if implements_trait(cx,
cx.tables.expr_ty(left),
trait_id,
&[cx.tables.expr_ty(r)],
None) {
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
let lsnip = Sugg::hir(cx, left, "...").deref().to_string();
let rsnip = snippet(cx, r.span, "...").to_string();
multispan_sugg(db,
"dereference the left operand instead".to_string(),
vec![(left.span, lsnip),
(right.span, rsnip)]);
}
)
})
}
}
_ => {}
},
_ => {},
}
}
}

View File

@ -98,8 +98,8 @@ pub fn get_argument_fmtstr_parts<'a, 'b>(cx: &LateContext<'a, 'b>, expr: &'a Exp
}
/// Checks if the expressions matches
/// ```rust
/// { static __STATIC_FMTSTR: s = &["a", "b", c]; __STATIC_FMTSTR }
/// ```rust, ignore
/// { static __STATIC_FMTSTR: &'static[&'static str] = &["a", "b", c]; __STATIC_FMTSTR }
/// ```
fn check_static_str(cx: &LateContext, expr: &Expr) -> bool {
if let Some(expr) = get_argument_fmtstr_parts(cx, expr) {

View File

@ -100,11 +100,19 @@ impl EarlyLintPass for Formatting {
fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
if let ast::ExprKind::Assign(ref lhs, ref rhs) = expr.node {
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(lhs.span) {
let eq_span = Span { lo: lhs.span.hi, hi: rhs.span.lo, ctxt: NO_EXPANSION };
let eq_span = Span {
lo: lhs.span.hi,
hi: rhs.span.lo,
ctxt: NO_EXPANSION,
};
if let ast::ExprKind::Unary(op, ref sub_rhs) = rhs.node {
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
let op = ast::UnOp::to_string(op);
let eqop_span= Span { lo: lhs.span.hi, hi: sub_rhs.span.lo, ctxt: NO_EXPANSION };
let eqop_span = Span {
lo: lhs.span.hi,
hi: sub_rhs.span.lo,
ctxt: NO_EXPANSION,
};
if eq_snippet.ends_with('=') {
span_note_and_lint(cx,
SUSPICIOUS_ASSIGNMENT_FORMATTING,
@ -127,7 +135,11 @@ fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
if unsugar_if(else_).is_some() && !differing_macro_contexts(then.span, else_.span) && !in_macro(then.span) {
// this will be a span from the closing } of the “then” block (excluding) to the
// “if” of the “else if” block (excluding)
let else_span = Span { lo: then.span.hi, hi: else_.span.lo, ctxt: NO_EXPANSION };
let else_span = Span {
lo: then.span.hi,
hi: else_.span.lo,
ctxt: NO_EXPANSION,
};
// the snippet should look like " else \n " with maybe comments anywhere
// its bad when there is a \n after the “else”
@ -154,9 +166,17 @@ fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
for element in array {
if let ast::ExprKind::Binary(ref op, ref lhs, _) = element.node {
if !differing_macro_contexts(lhs.span, op.span) {
let space_span = Span { lo: lhs.span.hi, hi: op.span.lo, ctxt: NO_EXPANSION };
let space_span = Span {
lo: lhs.span.hi,
hi: op.span.lo,
ctxt: NO_EXPANSION,
};
if let Some(space_snippet) = snippet_opt(cx, space_span) {
let lint_span = Span { lo: lhs.span.hi, hi: lhs.span.hi, ctxt: NO_EXPANSION };
let lint_span = Span {
lo: lhs.span.hi,
hi: lhs.span.hi,
ctxt: NO_EXPANSION,
};
if space_snippet.contains('\n') {
span_note_and_lint(cx,
POSSIBLE_MISSING_COMMA,
@ -174,10 +194,14 @@ fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for consecutive ifs.
fn check_consecutive_ifs(cx: &EarlyContext, first: &ast::Expr, second: &ast::Expr) {
if !differing_macro_contexts(first.span, second.span) && !in_macro(first.span) &&
unsugar_if(first).is_some() && unsugar_if(second).is_some() {
if !differing_macro_contexts(first.span, second.span) && !in_macro(first.span) && unsugar_if(first).is_some() &&
unsugar_if(second).is_some() {
// where the else would be
let else_span = Span { lo: first.span.hi, hi: second.span.lo, ctxt: NO_EXPANSION };
let else_span = Span {
lo: first.span.hi,
hi: second.span.lo,
ctxt: NO_EXPANSION,
};
if let Some(else_snippet) = snippet_opt(cx, else_span) {
if !else_snippet.contains('\n') {

View File

@ -11,7 +11,6 @@
#![feature(conservative_impl_trait)]
#![allow(indexing_slicing, shadow_reuse, unknown_lints, missing_docs_in_private_items)]
#![allow(needless_lifetimes)]
extern crate syntax;
extern crate syntax_pos;

View File

@ -6,6 +6,7 @@ use rustc::hir::intravisit::{Visitor, walk_ty, walk_ty_param_bound, walk_fn_decl
use std::collections::{HashSet, HashMap};
use syntax::codemap::Span;
use utils::{in_external_macro, span_lint, last_path_segment};
use syntax::symbol::keywords;
/// **What it does:** Checks for lifetime annotations which can be removed by
/// relying on lifetime elision.
@ -58,20 +59,24 @@ impl LintPass for LifetimePass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LifetimePass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemFn(ref decl, _, _, _, ref generics, _) = item.node {
check_fn_inner(cx, decl, generics, item.span);
if let ItemFn(ref decl, _, _, _, ref generics, id) = item.node {
check_fn_inner(cx, decl, Some(id), generics, item.span);
}
}
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
if let ImplItemKind::Method(ref sig, _) = item.node {
check_fn_inner(cx, &sig.decl, &sig.generics, item.span);
if let ImplItemKind::Method(ref sig, id) = item.node {
check_fn_inner(cx, &sig.decl, Some(id), &sig.generics, item.span);
}
}
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
if let TraitItemKind::Method(ref sig, _) = item.node {
check_fn_inner(cx, &sig.decl, &sig.generics, item.span);
if let TraitItemKind::Method(ref sig, ref body) = item.node {
let body = match *body {
TraitMethod::Required(_) => None,
TraitMethod::Provided(id) => Some(id),
};
check_fn_inner(cx, &sig.decl, body, &sig.generics, item.span);
}
}
}
@ -84,30 +89,38 @@ enum RefLt {
Named(Name),
}
fn bound_lifetimes(bound: &TyParamBound) -> HirVec<&Lifetime> {
if let TraitTyParamBound(ref trait_ref, _) = *bound {
trait_ref.trait_ref
.path
.segments
.last()
.expect("a path must have at least one segment")
.parameters
.lifetimes()
} else {
HirVec::new()
}
}
fn check_fn_inner<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, generics: &'tcx Generics, span: Span) {
fn check_fn_inner<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
decl: &'tcx FnDecl,
body: Option<BodyId>,
generics: &'tcx Generics,
span: Span
) {
if in_external_macro(cx, span) || has_where_lifetimes(cx, &generics.where_clause) {
return;
}
let bounds_lts = generics.ty_params
.iter()
.flat_map(|typ| typ.bounds.iter().flat_map(bound_lifetimes));
if could_use_elision(cx, decl, &generics.lifetimes, bounds_lts) {
let mut bounds_lts = Vec::new();
for typ in &generics.ty_params {
for bound in &typ.bounds {
if let TraitTyParamBound(ref trait_ref, _) = *bound {
let bounds = trait_ref.trait_ref
.path
.segments
.last()
.expect("a path must have at least one segment")
.parameters
.lifetimes();
for bound in bounds {
if bound.name != "'static" && !bound.is_elided() {
return;
}
bounds_lts.push(bound);
}
}
}
}
if could_use_elision(cx, decl, body, &generics.lifetimes, bounds_lts) {
span_lint(cx,
NEEDLESS_LIFETIMES,
span,
@ -116,11 +129,12 @@ fn check_fn_inner<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, gene
report_extra_lifetimes(cx, decl, generics);
}
fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(
fn could_use_elision<'a, 'tcx: 'a>(
cx: &LateContext<'a, 'tcx>,
func: &'tcx FnDecl,
body: Option<BodyId>,
named_lts: &'tcx [LifetimeDef],
bounds_lts: T
bounds_lts: Vec<&'tcx Lifetime>
) -> bool {
// There are two scenarios where elision works:
// * no output references, all input references have different LT
@ -144,8 +158,22 @@ fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(
output_visitor.visit_ty(ty);
}
let input_lts = lts_from_bounds(input_visitor.into_vec(), bounds_lts);
let output_lts = output_visitor.into_vec();
let input_lts = match input_visitor.into_vec() {
Some(lts) => lts_from_bounds(lts, bounds_lts.into_iter()),
None => return false,
};
let output_lts = match output_visitor.into_vec() {
Some(val) => val,
None => return false,
};
if let Some(body_id) = body {
let mut checker = BodyLifetimeChecker { lifetimes_used_in_body: false };
checker.visit_expr(&cx.tcx.hir.body(body_id).value);
if checker.lifetimes_used_in_body {
return false;
}
}
// check for lifetimes from higher scopes
for lt in input_lts.iter().chain(output_lts.iter()) {
@ -216,6 +244,7 @@ fn unique_lifetimes(lts: &[RefLt]) -> usize {
struct RefVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
lts: Vec<RefLt>,
abort: bool,
}
impl<'v, 't> RefVisitor<'v, 't> {
@ -223,6 +252,7 @@ impl<'v, 't> RefVisitor<'v, 't> {
RefVisitor {
cx: cx,
lts: Vec::new(),
abort: false,
}
}
@ -240,8 +270,8 @@ impl<'v, 't> RefVisitor<'v, 't> {
}
}
fn into_vec(self) -> Vec<RefLt> {
self.lts
fn into_vec(self) -> Option<Vec<RefLt>> {
if self.abort { None } else { Some(self.lts) }
}
fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) {
@ -292,7 +322,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
},
TyTraitObject(ref bounds, ref lt) => {
if !lt.is_elided() {
self.record(&Some(*lt));
self.abort = true;
}
for bound in bounds {
self.visit_poly_trait_ref(bound, TraitBoundModifier::None);
@ -329,10 +359,15 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &
walk_ty_param_bound(&mut visitor, bound);
}
// and check that all lifetimes are allowed
for lt in visitor.into_vec() {
if !allowed_lts.contains(&lt) {
return true;
}
match visitor.into_vec() {
None => return false,
Some(lts) => {
for lt in lts {
if !allowed_lts.contains(&lt) {
return true;
}
}
},
}
},
WherePredicate::EqPredicate(ref pred) => {
@ -384,3 +419,20 @@ fn report_extra_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, func: &'tcx
span_lint(cx, UNUSED_LIFETIMES, v, "this lifetime isn't used in the function definition");
}
}
struct BodyLifetimeChecker {
lifetimes_used_in_body: bool,
}
impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker {
// for lifetimes as parameters of generics
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
if lifetime.name != keywords::Invalid.name() && lifetime.name != "'static" {
self.lifetimes_used_in_body = true;
}
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::None
}
}

View File

@ -409,8 +409,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
if let StmtSemi(ref expr, _) = stmt.node {
if let ExprMethodCall(ref method, _, ref args) = expr.node {
if args.len() == 1 && method.node == "collect" &&
match_trait_method(cx, expr, &paths::ITERATOR) {
if args.len() == 1 && method.node == "collect" && match_trait_method(cx, expr, &paths::ITERATOR) {
span_lint(cx,
UNUSED_COLLECT,
expr.span,

View File

@ -499,9 +499,7 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool {
/// Test whether an expression is in a macro expansion (e.g. something generated by
/// `#[derive(...)`] or the like).
fn in_attributes_expansion(expr: &Expr) -> bool {
expr.span.ctxt.outer().expn_info().map_or(false, |info| {
matches!(info.callee.format, ExpnFormat::MacroAttribute(_))
})
expr.span.ctxt.outer().expn_info().map_or(false, |info| matches!(info.callee.format, ExpnFormat::MacroAttribute(_)))
}
/// Test whether `def` is a variable defined outside a macro.

View File

@ -122,6 +122,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
hir::ItemStatic(..) => "a static",
hir::ItemStruct(..) => "a struct",
hir::ItemTrait(..) => "a trait",
hir::ItemGlobalAsm(..) => "an assembly blob",
hir::ItemTy(..) => "a type alias",
hir::ItemUnion(..) => "a union",
hir::ItemDefaultImpl(..) |

View File

@ -77,27 +77,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|db| { db.span_suggestion(e.span, "you can reduce it to", hint); });
};
if let ExprBlock(ref then_block) = then_block.node {
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
(RetBool(true), RetBool(true)) |
(Bool(true), Bool(true)) => {
span_lint(cx,
NEEDLESS_BOOL,
e.span,
"this if-then-else expression will always return true");
},
(RetBool(false), RetBool(false)) |
(Bool(false), Bool(false)) => {
span_lint(cx,
NEEDLESS_BOOL,
e.span,
"this if-then-else expression will always return false");
},
(RetBool(true), RetBool(false)) => reduce(true, false),
(Bool(true), Bool(false)) => reduce(false, false),
(RetBool(false), RetBool(true)) => reduce(true, true),
(Bool(false), Bool(true)) => reduce(false, true),
_ => (),
}
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
(RetBool(true), RetBool(true)) |
(Bool(true), Bool(true)) => {
span_lint(cx,
NEEDLESS_BOOL,
e.span,
"this if-then-else expression will always return true");
},
(RetBool(false), RetBool(false)) |
(Bool(false), Bool(false)) => {
span_lint(cx,
NEEDLESS_BOOL,
e.span,
"this if-then-else expression will always return false");
},
(RetBool(true), RetBool(false)) => reduce(true, false),
(Bool(true), Bool(false)) => reduce(false, false),
(RetBool(false), RetBool(true)) => reduce(true, true),
(Bool(false), Bool(true)) => reduce(false, true),
_ => (),
}
} else {
panic!("IfExpr 'then' node is not an ExprBlock");
}

View File

@ -97,7 +97,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
},
(&ExprIndex(ref la, ref li), &ExprIndex(ref ra, ref ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri),
(&ExprIf(ref lc, ref lt, ref le), &ExprIf(ref rc, ref rt, ref re)) => {
self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
},
(&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node,
(&ExprLoop(ref lb, ref ll, ref lls), &ExprLoop(ref rb, ref rl, ref rls)) => {

View File

@ -372,6 +372,7 @@ fn print_item(cx: &LateContext, item: &hir::Item) {
},
hir::ItemMod(..) => println!("module"),
hir::ItemForeignMod(ref fm) => println!("foreign module with abi: {}", fm.abi),
hir::ItemGlobalAsm(ref asm) => println!("global asm: {:?}", asm),
hir::ItemTy(..) => {
println!("type alias for {:?}", cx.tcx.item_type(did));
},

View File

@ -690,8 +690,10 @@ fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[ast::Attribute], name: &'
/// See also `is_direct_expn_of`.
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
loop {
let span_name_span = span.ctxt.outer()
.expn_info().map(|ei| (ei.callee.name(), ei.call_site));
let span_name_span = span.ctxt
.outer()
.expn_info()
.map(|ei| (ei.callee.name(), ei.call_site));
match span_name_span {
Some((mac_name, new_span)) if mac_name == name => return Some(new_span),
@ -709,8 +711,10 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
/// `42` is considered expanded from `foo!` and `bar!` by `is_expn_of` but only `bar!` by
/// `is_direct_expn_of`.
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
let span_name_span = span.ctxt.outer()
.expn_info().map(|ei| (ei.callee.name(), ei.call_site));
let span_name_span = span.ctxt
.outer()
.expn_info()
.map(|ei| (ei.callee.name(), ei.call_site));
match span_name_span {
Some((mac_name, new_span)) if mac_name == name => Some(new_span),
@ -900,7 +904,8 @@ pub fn opt_def_id(def: Def) -> Option<DefId> {
Def::AssociatedConst(id) |
Def::Local(id) |
Def::Upvar(id, ..) |
Def::Macro(id, _) => Some(id),
Def::Macro(id, ..) |
Def::GlobalAsm(id) => Some(id),
Def::Label(..) | Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => None,
}

View File

@ -12,8 +12,13 @@ extern crate clippy_lints;
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
if let Ok(lint_store) = reg.sess.lint_store.try_borrow() {
if lint_store.get_lint_groups().iter().any(|&(s, _, _)| s == "clippy") {
reg.sess.struct_warn("running cargo clippy on a crate that also imports the clippy plugin").emit();
if lint_store
.get_lint_groups()
.iter()
.any(|&(s, _, _)| s == "clippy") {
reg.sess
.struct_warn("running cargo clippy on a crate that also imports the clippy plugin")
.emit();
return;
}
}

View File

@ -43,9 +43,10 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
sopts: &config::Options,
cfg: &ast::CrateConfig,
descriptions: &rustc_errors::registry::Registry,
output: ErrorOutputType
output: ErrorOutputType,
) -> Compilation {
self.default.early_callback(matches, sopts, cfg, descriptions, output)
self.default
.early_callback(matches, sopts, cfg, descriptions, output)
}
fn no_input(
&mut self,
@ -54,9 +55,10 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
cfg: &ast::CrateConfig,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>,
descriptions: &rustc_errors::registry::Registry
descriptions: &rustc_errors::registry::Registry,
) -> Option<(Input, Option<PathBuf>)> {
self.default.no_input(matches, sopts, cfg, odir, ofile, descriptions)
self.default
.no_input(matches, sopts, cfg, odir, ofile, descriptions)
}
fn late_callback(
&mut self,
@ -64,9 +66,10 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
sess: &Session,
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>
ofile: &Option<PathBuf>,
) -> Compilation {
self.default.late_callback(matches, sess, input, odir, ofile)
self.default
.late_callback(matches, sess, input, odir, ofile)
}
fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> driver::CompileController<'a> {
let mut control = self.default.build_controller(sess, matches);
@ -76,7 +79,8 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
control.after_parse.callback = Box::new(move |state| {
{
let mut registry = rustc_plugin::registry::Registry::new(state.session,
state.krate
state
.krate
.as_ref()
.expect("at this compilation stage \
the krate must be parsed")
@ -84,12 +88,14 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
registry.args_hidden = Some(Vec::new());
clippy_lints::register_plugins(&mut registry);
let rustc_plugin::registry::Registry { early_lint_passes,
late_lint_passes,
lint_groups,
llvm_passes,
attributes,
.. } = registry;
let rustc_plugin::registry::Registry {
early_lint_passes,
late_lint_passes,
lint_groups,
llvm_passes,
attributes,
..
} = registry;
let sess = &state.session;
let mut ls = sess.lint_store.borrow_mut();
for pass in early_lint_passes {
@ -172,29 +178,35 @@ pub fn main() {
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
// this arm is executed on the initial call to `cargo clippy`
let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path="));
let manifest_path_arg = std::env::args()
.skip(2)
.find(|val| val.starts_with("--manifest-path="));
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref()
.map(AsRef::as_ref)) {
metadata
} else {
let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.\n"));
process::exit(101);
};
let mut metadata =
if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) {
metadata
} else {
let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.\n"));
process::exit(101);
};
let manifest_path = manifest_path_arg.map(|arg| PathBuf::from(Path::new(&arg["--manifest-path=".len()..])));
let current_dir = std::env::current_dir();
let package_index = metadata.packages
let package_index = metadata
.packages
.iter()
.position(|package| {
let package_manifest_path = Path::new(&package.manifest_path);
if let Some(ref manifest_path) = manifest_path {
package_manifest_path == manifest_path
} else {
let current_dir = current_dir.as_ref().expect("could not read current directory");
let package_manifest_directory = package_manifest_path.parent()
let current_dir = current_dir
.as_ref()
.expect("could not read current directory");
let package_manifest_directory = package_manifest_path
.parent()
.expect("could not find parent directory of package manifest");
package_manifest_directory == current_dir
}
@ -209,7 +221,9 @@ pub fn main() {
std::process::exit(code);
}
} else if ["bin", "example", "test", "bench"].contains(&&**first) {
if let Err(code) = process(vec![format!("--{}", first), target.name].into_iter().chain(args)) {
if let Err(code) = process(vec![format!("--{}", first), target.name]
.into_iter()
.chain(args)) {
std::process::exit(code);
}
}
@ -218,7 +232,8 @@ pub fn main() {
}
}
} else {
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC` env var set to itself
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC`
// env var set to itself
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
@ -240,31 +255,36 @@ pub fn main() {
};
rustc_driver::in_rustc_thread(|| {
// this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
// without having to pass --sysroot or anything
let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
env::args().collect()
} else {
env::args().chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect()
};
// this conditional check for the --sysroot flag is there so users can call
// `cargo-clippy` directly
// without having to pass --sysroot or anything
let mut args: Vec<String> = if env::args().any(|s| s == "--sysroot") {
env::args().collect()
} else {
env::args()
.chain(Some("--sysroot".to_owned()))
.chain(Some(sys_root))
.collect()
};
// this check ensures that dependencies are built but not linted and the final crate is
// linted but not built
let clippy_enabled = env::args().any(|s| s == "-Zno-trans");
// this check ensures that dependencies are built but not linted and the final
// crate is
// linted but not built
let clippy_enabled = env::args().any(|s| s == "-Zno-trans");
if clippy_enabled {
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
if clippy_enabled {
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
}
let mut ccc = ClippyCompilerCalls::new(clippy_enabled);
let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None);
if let Err(err_count) = result {
if err_count > 0 {
std::process::exit(1);
}
let mut ccc = ClippyCompilerCalls::new(clippy_enabled);
let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None);
if let Err(err_count) = result {
if err_count > 0 {
std::process::exit(1);
}
}
})
.expect("rustc_thread failed");
}
})
.expect("rustc_thread failed");
}
}

View File

@ -14,14 +14,14 @@ struct Test {
fn main() {
use Baz::*;
let x = Test {
t: Some(0),
b: One,
};
let x = Test { t: Some(0), b: One };
match x {
Test { t: Some(_), b: One } => unreachable!(),
Test { t: Some(42), b: Two } => unreachable!(),
Test {
t: Some(42),
b: Two,
} => unreachable!(),
Test { t: None, .. } => unreachable!(),
Test { .. } => unreachable!(),
}

View File

@ -20,9 +20,13 @@ fn test_overlapping() {
assert_eq!(None, overlapping(&[sp(1, Bound::Included(4))]));
assert_eq!(None, overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6))]));
assert_eq!(None,
overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6)), sp(10, Bound::Included(11))]));
overlapping(&[sp(1, Bound::Included(4)),
sp(5, Bound::Included(6)),
sp(10, Bound::Included(11))]));
assert_eq!(Some((&sp(1, Bound::Included(4)), &sp(3, Bound::Included(6)))),
overlapping(&[sp(1, Bound::Included(4)), sp(3, Bound::Included(6))]));
assert_eq!(Some((&sp(5, Bound::Included(6)), &sp(6, Bound::Included(11)))),
overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6)), sp(6, Bound::Included(11))]));
overlapping(&[sp(1, Bound::Included(4)),
sp(5, Bound::Included(6)),
sp(6, Bound::Included(11))]));
}

View File

@ -19,10 +19,9 @@ error: integer arithmetic detected
error: integer arithmetic detected
--> $DIR/arithmetic.rs:10:5
|
10 | 1 %
| _____^ starting here...
10 | / 1 %
11 | | i / 2; // no error, this is part of the expression in the preceding line
| |_________^ ...ending here
| |_________^
error: integer arithmetic detected
--> $DIR/arithmetic.rs:12:5

View File

@ -2,11 +2,11 @@ error: in an 'if' condition, avoid complex blocks or closures with blocks; inste
--> $DIR/block_in_if_condition.rs:30:8
|
30 | if {
| ________^ starting here...
| ________^
31 | | let x = 3;
32 | | x == 3
33 | | } {
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/block_in_if_condition.rs:5:9

View File

@ -1,15 +1,14 @@
error: this if statement can be collapsed
--> $DIR/collapsible_if.rs:8:5
|
8 | if x == "hello" {
| _____^ starting here...
8 | / if x == "hello" {
9 | |
10 | |
11 | |
... |
14 | | }
15 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/collapsible_if.rs:4:8
@ -24,15 +23,14 @@ help: try
error: this if statement can be collapsed
--> $DIR/collapsible_if.rs:17:5
|
17 | if x == "hello" || x == "world" {
| _____^ starting here...
17 | / if x == "hello" || x == "world" {
18 | |
19 | |
20 | |
... |
23 | | }
24 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
@ -42,15 +40,14 @@ help: try
error: this if statement can be collapsed
--> $DIR/collapsible_if.rs:26:5
|
26 | if x == "hello" && x == "world" {
| _____^ starting here...
26 | / if x == "hello" && x == "world" {
27 | |
28 | |
29 | |
... |
32 | | }
33 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| if x == "hello" && x == "world" && (y == "world" || y == "hello") {
@ -60,15 +57,14 @@ help: try
error: this if statement can be collapsed
--> $DIR/collapsible_if.rs:35:5
|
35 | if x == "hello" || x == "world" {
| _____^ starting here...
35 | / if x == "hello" || x == "world" {
36 | |
37 | |
38 | |
... |
41 | | }
42 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| if (x == "hello" || x == "world") && y == "world" && y == "hello" {
@ -78,15 +74,14 @@ help: try
error: this if statement can be collapsed
--> $DIR/collapsible_if.rs:44:5
|
44 | if x == "hello" && x == "world" {
| _____^ starting here...
44 | / if x == "hello" && x == "world" {
45 | |
46 | |
47 | |
... |
50 | | }
51 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| if x == "hello" && x == "world" && y == "world" && y == "hello" {
@ -96,15 +91,14 @@ help: try
error: this if statement can be collapsed
--> $DIR/collapsible_if.rs:53:5
|
53 | if 42 == 1337 {
| _____^ starting here...
53 | / if 42 == 1337 {
54 | |
55 | |
56 | |
... |
59 | | }
60 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| if 42 == 1337 && 'a' != 'A' {
@ -115,14 +109,14 @@ error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:65:12
|
65 | } else {
| ____________^ starting here...
| ____________^
66 | |
67 | |
68 | |
... |
71 | | }
72 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| } else if y == "world" {
@ -133,14 +127,14 @@ error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:76:12
|
76 | } else {
| ____________^ starting here...
| ____________^
77 | |
78 | |
79 | |
... |
82 | | }
83 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| } else if let Some(42) = Some(42) {
@ -151,14 +145,14 @@ error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:87:12
|
87 | } else {
| ____________^ starting here...
| ____________^
88 | |
89 | |
90 | |
... |
96 | | }
97 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| } else if y == "world" {
@ -172,14 +166,14 @@ error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:101:12
|
101 | } else {
| ____________^ starting here...
| ____________^
102 | |
103 | |
104 | |
... |
110 | | }
111 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| } else if let Some(42) = Some(42) {
@ -193,14 +187,14 @@ error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:115:12
|
115 | } else {
| ____________^ starting here...
| ____________^
116 | |
117 | |
118 | |
... |
124 | | }
125 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| } else if let Some(42) = Some(42) {
@ -214,14 +208,14 @@ error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:129:12
|
129 | } else {
| ____________^ starting here...
| ____________^
130 | |
131 | |
132 | |
... |
138 | | }
139 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| } else if x == "hello" {
@ -235,14 +229,14 @@ error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:143:12
|
143 | } else {
| ____________^ starting here...
| ____________^
144 | |
145 | |
146 | |
... |
152 | | }
153 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| } else if let Some(42) = Some(42) {

View File

@ -42,14 +42,14 @@ error: this `if` has identical blocks
--> $DIR/copies.rs:40:10
|
40 | else {
| __________^ starting here...
| __________^
41 | | Foo { bar: 42 };
42 | | 0..10;
43 | | ..;
... |
47 | | foo();
48 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/copies.rs:27:8
@ -60,27 +60,27 @@ note: same as this
--> $DIR/copies.rs:30:13
|
30 | if true {
| _____________^ starting here...
| _____________^
31 | |
32 | | Foo { bar: 42 };
33 | | 0..10;
... |
38 | | foo();
39 | | }
| |_____^ ...ending here
| |_____^
error: this `match` has identical arm bodies
--> $DIR/copies.rs:91:14
|
91 | _ => {
| ______________^ starting here...
| ______________^
92 | | foo();
93 | | let mut a = 42 + [23].len() as i32;
94 | | if true {
... |
98 | | a
99 | | }
| |_________^ ...ending here
| |_________^
|
note: lint level defined here
--> $DIR/copies.rs:28:8
@ -91,26 +91,26 @@ note: same as this
--> $DIR/copies.rs:80:15
|
80 | 42 => {
| _______________^ starting here...
| _______________^
81 | |
82 | |
83 | | foo();
... |
89 | | a
90 | | }
| |_________^ ...ending here
| |_________^
note: `42` has the same arm body as the `_` wildcard, consider removing it`
--> $DIR/copies.rs:80:15
|
80 | 42 => {
| _______________^ starting here...
| _______________^
81 | |
82 | |
83 | | foo();
... |
89 | | a
90 | | }
| |_________^ ...ending here
| |_________^
error: this `match` has identical arm bodies
--> $DIR/copies.rs:107:14
@ -133,136 +133,136 @@ error: this `if` has identical blocks
--> $DIR/copies.rs:118:10
|
118 | else {
| __________^ starting here...
| __________^
119 | | 42
120 | | };
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:114:21
|
114 | let _ = if true {
| _____________________^ starting here...
| _____________________^
115 | |
116 | | 42
117 | | }
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:133:10
|
133 | else {
| __________^ starting here...
| __________^
134 | | for _ in &[42] {
135 | | let foo: &Option<_> = &Some::<u8>(42);
136 | | if true {
... |
141 | | }
142 | | }
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:122:13
|
122 | if true {
| _____________^ starting here...
| _____________^
123 | |
124 | | for _ in &[42] {
125 | | let foo: &Option<_> = &Some::<u8>(42);
... |
131 | | }
132 | | }
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:156:10
|
156 | else {
| __________^ starting here...
| __________^
157 | | let bar = if true {
158 | | 42
159 | | }
... |
165 | | bar + 1;
166 | | }
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:144:13
|
144 | if true {
| _____________^ starting here...
| _____________^
145 | |
146 | | let bar = if true {
147 | | 42
... |
154 | | bar + 1;
155 | | }
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:180:19
|
180 | else if foo() {
| ___________________^ starting here...
| ___________________^
181 | | let _ = match 42 {
182 | | 42 => 1,
183 | | a if a > 0 => 2,
... |
186 | | };
187 | | }
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:168:13
|
168 | if true {
| _____________^ starting here...
| _____________^
169 | |
170 | | let _ = match 42 {
171 | | 42 => 1,
... |
175 | | };
176 | | }
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:193:10
|
193 | else {
| __________^ starting here...
| __________^
194 | | if let Some(a) = Some(42) {}
195 | | }
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:189:13
|
189 | if true {
| _____________^ starting here...
| _____________^
190 | |
191 | | if let Some(a) = Some(42) {}
192 | | }
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:201:10
|
201 | else {
| __________^ starting here...
| __________^
202 | | if let (1, .., 3) = (1, 2, 3) {}
203 | | }
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:197:13
|
197 | if true {
| _____________^ starting here...
| _____________^
198 | |
199 | | if let (1, .., 3) = (1, 2, 3) {}
200 | | }
| |_____^ ...ending here
| |_____^
error: this `match` has identical arm bodies
--> $DIR/copies.rs:258:15
@ -353,98 +353,98 @@ error: this `if` has identical blocks
--> $DIR/copies.rs:313:12
|
313 | } else {
| ____________^ starting here...
| ____________^
314 | | 0.0
315 | | };
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:310:21
|
310 | let _ = if true {
| _____________________^ starting here...
| _____________________^
311 | |
312 | | 0.0
313 | | } else {
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:320:12
|
320 | } else {
| ____________^ starting here...
| ____________^
321 | | -0.0
322 | | };
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:317:21
|
317 | let _ = if true {
| _____________________^ starting here...
| _____________________^
318 | |
319 | | -0.0
320 | | } else {
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:341:12
|
341 | } else {
| ____________^ starting here...
| ____________^
342 | | std::f32::NAN
343 | | };
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:338:21
|
338 | let _ = if true {
| _____________________^ starting here...
| _____________________^
339 | |
340 | | std::f32::NAN
341 | | } else {
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:360:10
|
360 | else {
| __________^ starting here...
| __________^
361 | | try!(Ok("foo"));
362 | | }
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:356:13
|
356 | if true {
| _____________^ starting here...
| _____________^
357 | |
358 | | try!(Ok("foo"));
359 | | }
| |_____^ ...ending here
| |_____^
error: this `if` has identical blocks
--> $DIR/copies.rs:373:10
|
373 | else {
| __________^ starting here...
| __________^
374 | | let foo = "";
375 | | return Ok(&foo[0..]);
376 | | }
| |_____^ ...ending here
| |_____^
|
note: same as this
--> $DIR/copies.rs:364:13
|
364 | if true {
| _____________^ starting here...
| _____________^
365 | |
366 | | let foo = "";
367 | | return Ok(&foo[0..]);
368 | | }
| |_____^ ...ending here
| |_____^
error: this `if` has the same condition as a previous if
--> $DIR/copies.rs:388:13

View File

@ -1,15 +1,14 @@
error: the function has a cyclomatic complexity of 28
--> $DIR/cyclomatic_complexity.rs:7:1
|
7 | fn main() {
| _^ starting here...
7 | / fn main() {
8 | | if true {
9 | | println!("a");
10 | | }
... |
88 | | }
89 | | }
| |_^ ...ending here
| |_^
|
note: lint level defined here
--> $DIR/cyclomatic_complexity.rs:4:9
@ -21,52 +20,48 @@ note: lint level defined here
error: the function has a cyclomatic complexity of 7
--> $DIR/cyclomatic_complexity.rs:92:1
|
92 | fn kaboom() {
| _^ starting here...
92 | / fn kaboom() {
93 | | let n = 0;
94 | | 'a: for i in 0..20 {
95 | | 'b: for j in i..20 {
... |
110 | | }
111 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:138:1
|
138 | fn lots_of_short_circuits() -> bool {
| _^ starting here...
138 | / fn lots_of_short_circuits() -> bool {
139 | | true && false && true && false && true && false && true
140 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:143:1
|
143 | fn lots_of_short_circuits2() -> bool {
| _^ starting here...
143 | / fn lots_of_short_circuits2() -> bool {
144 | | true || false || true || false || true || false || true
145 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:148:1
|
148 | fn baa() {
| _^ starting here...
148 | / fn baa() {
149 | | let x = || match 99 {
150 | | 0 => 0,
151 | | 1 => 1,
... |
162 | | }
163 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
@ -74,221 +69,207 @@ error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:149:13
|
149 | let x = || match 99 {
| _____________^ starting here...
| _____________^
150 | | 0 => 0,
151 | | 1 => 1,
152 | | 2 => 2,
... |
156 | | _ => 42,
157 | | };
| |_____^ ...ending here
| |_____^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:166:1
|
166 | fn bar() {
| _^ starting here...
166 | / fn bar() {
167 | | match 99 {
168 | | 0 => println!("hi"),
169 | | _ => println!("bye"),
170 | | }
171 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:185:1
|
185 | fn barr() {
| _^ starting here...
185 | / fn barr() {
186 | | match 99 {
187 | | 0 => println!("hi"),
188 | | 1 => println!("bla"),
... |
191 | | }
192 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:195:1
|
195 | fn barr2() {
| _^ starting here...
195 | / fn barr2() {
196 | | match 99 {
197 | | 0 => println!("hi"),
198 | | 1 => println!("bla"),
... |
207 | | }
208 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:211:1
|
211 | fn barrr() {
| _^ starting here...
211 | / fn barrr() {
212 | | match 99 {
213 | | 0 => println!("hi"),
214 | | 1 => panic!("bla"),
... |
217 | | }
218 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:221:1
|
221 | fn barrr2() {
| _^ starting here...
221 | / fn barrr2() {
222 | | match 99 {
223 | | 0 => println!("hi"),
224 | | 1 => panic!("bla"),
... |
233 | | }
234 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:237:1
|
237 | fn barrrr() {
| _^ starting here...
237 | / fn barrrr() {
238 | | match 99 {
239 | | 0 => println!("hi"),
240 | | 1 => println!("bla"),
... |
243 | | }
244 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity.rs:247:1
|
247 | fn barrrr2() {
| _^ starting here...
247 | / fn barrrr2() {
248 | | match 99 {
249 | | 0 => println!("hi"),
250 | | 1 => println!("bla"),
... |
259 | | }
260 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 2
--> $DIR/cyclomatic_complexity.rs:263:1
|
263 | fn cake() {
| _^ starting here...
263 | / fn cake() {
264 | | if 4 == 5 {
265 | | println!("yea");
266 | | } else {
... |
269 | | println!("whee");
270 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 4
--> $DIR/cyclomatic_complexity.rs:274:1
|
274 | pub fn read_file(input_path: &str) -> String {
| _^ starting here...
274 | / pub fn read_file(input_path: &str) -> String {
275 | | use std::fs::File;
276 | | use std::io::{Read, Write};
277 | | use std::path::Path;
... |
299 | | }
300 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:305:1
|
305 | fn void(void: Void) {
| _^ starting here...
305 | / fn void(void: Void) {
306 | | if true {
307 | | match void {
308 | | }
309 | | }
310 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:319:1
|
319 | fn try() -> Result<i32, &'static str> {
| _^ starting here...
319 | / fn try() -> Result<i32, &'static str> {
320 | | match 5 {
321 | | 5 => Ok(5),
322 | | _ => return Err("bla"),
323 | | }
324 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:327:1
|
327 | fn try_again() -> Result<i32, &'static str> {
| _^ starting here...
327 | / fn try_again() -> Result<i32, &'static str> {
328 | | let _ = try!(Ok(42));
329 | | let _ = try!(Ok(43));
330 | | let _ = try!(Ok(44));
... |
339 | | }
340 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 1
--> $DIR/cyclomatic_complexity.rs:343:1
|
343 | fn early() -> Result<i32, &'static str> {
| _^ starting here...
343 | / fn early() -> Result<i32, &'static str> {
344 | | return Ok(5);
345 | | return Ok(5);
346 | | return Ok(5);
... |
352 | | return Ok(5);
353 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions
error: the function has a cyclomatic complexity of 8
--> $DIR/cyclomatic_complexity.rs:356:1
|
356 | fn early_ret() -> i32 {
| _^ starting here...
356 | / fn early_ret() -> i32 {
357 | | let a = if true { 42 } else { return 0; };
358 | | let a = if a < 99 { 42 } else { return 0; };
359 | | let a = if a < 99 { 42 } else { return 0; };
... |
372 | | }
373 | | }
| |_^ ...ending here
| |_^
|
= help: you could split it up into multiple smaller functions

View File

@ -1,15 +1,14 @@
error: the function has a cyclomatic complexity of 3
--> $DIR/cyclomatic_complexity_attr_used.rs:11:1
|
11 | fn kaboom() {
| _^ starting here...
11 | / fn kaboom() {
12 | | if 42 == 43 {
13 | | panic!();
14 | | } else if "cake" == "lie" {
15 | | println!("what?");
16 | | }
17 | | }
| |_^ ...ending here
| |_^
|
note: lint level defined here
--> $DIR/cyclomatic_complexity_attr_used.rs:3:9

View File

@ -13,11 +13,10 @@ note: lint level defined here
note: `PartialEq` implemented here
--> $DIR/derive.rs:22:1
|
22 | impl PartialEq for Bar {
| _^ starting here...
22 | / impl PartialEq for Bar {
23 | | fn eq(&self, _: &Bar) -> bool { true }
24 | | }
| |_^ ...ending here
| |_^
error: you are deriving `Hash` but have implemented `PartialEq` explicitly
--> $DIR/derive.rs:26:10
@ -29,21 +28,19 @@ error: you are deriving `Hash` but have implemented `PartialEq` explicitly
note: `PartialEq` implemented here
--> $DIR/derive.rs:30:1
|
30 | impl PartialEq<Baz> for Baz {
| _^ starting here...
30 | / impl PartialEq<Baz> for Baz {
31 | | fn eq(&self, _: &Baz) -> bool { true }
32 | | }
| |_^ ...ending here
| |_^
error: you are implementing `Hash` explicitly but have derived `PartialEq`
--> $DIR/derive.rs:37:1
|
37 | impl Hash for Bah {
| _^ starting here...
37 | / impl Hash for Bah {
38 | |
39 | | fn hash<H: Hasher>(&self, _: &mut H) {}
40 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(derive_hash_xor_eq)] implied by #[deny(warnings)]
note: `PartialEq` implemented here
@ -55,12 +52,11 @@ note: `PartialEq` implemented here
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:45:1
|
45 | impl Clone for Qux {
| _^ starting here...
45 | / impl Clone for Qux {
46 | |
47 | | fn clone(&self) -> Self { Qux }
48 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(expl_impl_clone_on_copy)] implied by #[deny(warnings)]
note: lint level defined here
@ -71,33 +67,30 @@ note: lint level defined here
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:45:1
|
45 | impl Clone for Qux {
| _^ starting here...
45 | / impl Clone for Qux {
46 | |
47 | | fn clone(&self) -> Self { Qux }
48 | | }
| |_^ ...ending here
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:70:1
|
70 | impl<'a> Clone for Lt<'a> {
| _^ starting here...
70 | / impl<'a> Clone for Lt<'a> {
71 | |
72 | | fn clone(&self) -> Self { unimplemented!() }
73 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(expl_impl_clone_on_copy)] implied by #[deny(warnings)]
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:70:1
|
70 | impl<'a> Clone for Lt<'a> {
| _^ starting here...
70 | / impl<'a> Clone for Lt<'a> {
71 | |
72 | | fn clone(&self) -> Self { unimplemented!() }
73 | | }
| |_^ ...ending here
| |_^
error: aborting due to 5 previous errors

View File

@ -38,13 +38,12 @@ error: Variant name starts with the enum's name
error: All variants have the same prefix: `Food`
--> $DIR/enum_variants.rs:24:1
|
24 | enum Food {
| _^ starting here...
24 | / enum Food {
25 | | FoodGood,
26 | | FoodMiddle,
27 | | FoodBad,
28 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
= help: remove the prefixes and use full paths to the variants instead of glob imports
@ -52,13 +51,12 @@ error: All variants have the same prefix: `Food`
error: All variants have the same prefix: `CallType`
--> $DIR/enum_variants.rs:34:1
|
34 | enum BadCallType {
| _^ starting here...
34 | / enum BadCallType {
35 | | CallTypeCall,
36 | | CallTypeCreate,
37 | | CallTypeDestroy,
38 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
= help: remove the prefixes and use full paths to the variants instead of glob imports
@ -66,13 +64,12 @@ error: All variants have the same prefix: `CallType`
error: All variants have the same prefix: `Constant`
--> $DIR/enum_variants.rs:45:1
|
45 | enum Consts {
| _^ starting here...
45 | / enum Consts {
46 | | ConstantInt,
47 | | ConstantCake,
48 | | ConstantLie,
49 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
= help: remove the prefixes and use full paths to the variants instead of glob imports
@ -80,13 +77,12 @@ error: All variants have the same prefix: `Constant`
error: All variants have the same prefix: `With`
--> $DIR/enum_variants.rs:78:1
|
78 | enum Seallll {
| _^ starting here...
78 | / enum Seallll {
79 | | WithOutCake,
80 | | WithOutTea,
81 | | WithOut,
82 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
= help: remove the prefixes and use full paths to the variants instead of glob imports
@ -94,13 +90,12 @@ error: All variants have the same prefix: `With`
error: All variants have the same prefix: `Prefix`
--> $DIR/enum_variants.rs:84:1
|
84 | enum NonCaps {
| _^ starting here...
84 | / enum NonCaps {
85 | | Prefix的,
86 | | PrefixTea,
87 | | PrefixCake,
88 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(enum_variant_names)] implied by #[deny(clippy)]
= help: remove the prefixes and use full paths to the variants instead of glob imports
@ -108,13 +103,12 @@ error: All variants have the same prefix: `Prefix`
error: All variants have the same prefix: `With`
--> $DIR/enum_variants.rs:90:1
|
90 | pub enum PubSeall {
| _^ starting here...
90 | / pub enum PubSeall {
91 | | WithOutCake,
92 | | WithOutTea,
93 | | WithOut,
94 | | }
| |_^ ...ending here
| |_^
|
note: lint level defined here
--> $DIR/enum_variants.rs:3:17

View File

@ -2,10 +2,10 @@ error: called `filter(p).map(q)` on an `Iterator`. This is more succinctly expre
--> $DIR/filter_methods.rs:8:21
|
8 | let _: Vec<_> = vec![5; 6].into_iter()
| _____________________^ starting here...
| _____________________^
9 | | .filter(|&x| x == 0)
10 | | .map(|x| x * 2)
| |_____________________________________________^ ...ending here
| |_____________________________________________^
|
= note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)]
note: lint level defined here
@ -18,10 +18,10 @@ error: called `filter(p).flat_map(q)` on an `Iterator`. This is more succinctly
--> $DIR/filter_methods.rs:13:21
|
13 | let _: Vec<_> = vec![5_i8; 6].into_iter()
| _____________________^ starting here...
| _____________________^
14 | | .filter(|&x| x == 0)
15 | | .flat_map(|x| x.checked_mul(2))
| |_______________________________________________________________^ ...ending here
| |_______________________________________________________________^
|
= note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)]
@ -29,10 +29,10 @@ error: called `filter_map(p).flat_map(q)` on an `Iterator`. This is more succinc
--> $DIR/filter_methods.rs:18:21
|
18 | let _: Vec<_> = vec![5_i8; 6].into_iter()
| _____________________^ starting here...
| _____________________^
19 | | .filter_map(|x| x.checked_mul(2))
20 | | .flat_map(|x| x.checked_mul(2))
| |_______________________________________________________________^ ...ending here
| |_______________________________________________________________^
|
= note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)]
@ -40,10 +40,10 @@ error: called `filter_map(p).map(q)` on an `Iterator`. This is more succinctly e
--> $DIR/filter_methods.rs:23:21
|
23 | let _: Vec<_> = vec![5_i8; 6].into_iter()
| _____________________^ starting here...
| _____________________^
24 | | .filter_map(|x| x.checked_mul(2))
25 | | .map(|x| x.checked_mul(2))
| |__________________________________________________________^ ...ending here
| |__________________________________________________________^
|
= note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)]

View File

@ -38,12 +38,11 @@ error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
--> $DIR/for_loop.rs:40:5
|
40 | for x in v.iter().next() {
| _____^ starting here...
40 | / for x in v.iter().next() {
41 | |
42 | | println!("{}", x);
43 | | }
| |_____^ ...ending here
| |_____^
|
= note: #[deny(iter_next_loop)] implied by #[deny(clippy)]
note: lint level defined here
@ -73,15 +72,14 @@ error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`
error: the loop variable `i` is only used to index `vec`.
--> $DIR/for_loop.rs:99:5
|
99 | for i in 0..vec.len() {
| _____^ starting here...
99 | / for i in 0..vec.len() {
100 | |
101 | |
102 | |
103 | |
104 | | println!("{}", vec[i]);
105 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/for_loop.rs:90:8
@ -111,15 +109,14 @@ help: consider using an iterator
error: the loop variable `j` is only used to index `STATIC`.
--> $DIR/for_loop.rs:120:5
|
120 | for j in 0..4 {
| _____^ starting here...
120 | / for j in 0..4 {
121 | |
122 | |
123 | |
124 | |
125 | | println!("{:?}", STATIC[j]);
126 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in STATIC.iter().take(4) {
@ -127,15 +124,14 @@ help: consider using an iterator
error: the loop variable `j` is only used to index `CONST`.
--> $DIR/for_loop.rs:128:5
|
128 | for j in 0..4 {
| _____^ starting here...
128 | / for j in 0..4 {
129 | |
130 | |
131 | |
132 | |
133 | | println!("{:?}", CONST[j]);
134 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in CONST.iter().take(4) {
@ -143,15 +139,14 @@ help: consider using an iterator
error: the loop variable `i` is used to index `vec`
--> $DIR/for_loop.rs:136:5
|
136 | for i in 0..vec.len() {
| _____^ starting here...
136 | / for i in 0..vec.len() {
137 | |
138 | |
139 | |
140 | |
141 | | println!("{} {}", vec[i], i);
142 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for (i, <item>) in vec.iter().enumerate() {
@ -159,15 +154,14 @@ help: consider using an iterator
error: the loop variable `i` is only used to index `vec2`.
--> $DIR/for_loop.rs:147:5
|
147 | for i in 0..vec.len() {
| _____^ starting here...
147 | / for i in 0..vec.len() {
148 | |
149 | |
150 | |
151 | |
152 | | println!("{}", vec2[i]);
153 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in vec2.iter().take(vec.len()) {
@ -175,15 +169,14 @@ help: consider using an iterator
error: the loop variable `i` is only used to index `vec`.
--> $DIR/for_loop.rs:155:5
|
155 | for i in 5..vec.len() {
| _____^ starting here...
155 | / for i in 5..vec.len() {
156 | |
157 | |
158 | |
159 | |
160 | | println!("{}", vec[i]);
161 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in vec.iter().skip(5) {
@ -191,15 +184,14 @@ help: consider using an iterator
error: the loop variable `i` is only used to index `vec`.
--> $DIR/for_loop.rs:163:5
|
163 | for i in 0..MAX_LEN {
| _____^ starting here...
163 | / for i in 0..MAX_LEN {
164 | |
165 | |
166 | |
167 | |
168 | | println!("{}", vec[i]);
169 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in vec.iter().take(MAX_LEN) {
@ -207,15 +199,14 @@ help: consider using an iterator
error: the loop variable `i` is only used to index `vec`.
--> $DIR/for_loop.rs:171:5
|
171 | for i in 0...MAX_LEN {
| _____^ starting here...
171 | / for i in 0...MAX_LEN {
172 | |
173 | |
174 | |
175 | |
176 | | println!("{}", vec[i]);
177 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in vec.iter().take(MAX_LEN + 1) {
@ -223,15 +214,14 @@ help: consider using an iterator
error: the loop variable `i` is only used to index `vec`.
--> $DIR/for_loop.rs:179:5
|
179 | for i in 5..10 {
| _____^ starting here...
179 | / for i in 5..10 {
180 | |
181 | |
182 | |
183 | |
184 | | println!("{}", vec[i]);
185 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in vec.iter().take(10).skip(5) {
@ -239,15 +229,14 @@ help: consider using an iterator
error: the loop variable `i` is only used to index `vec`.
--> $DIR/for_loop.rs:187:5
|
187 | for i in 5...10 {
| _____^ starting here...
187 | / for i in 5...10 {
188 | |
189 | |
190 | |
191 | |
192 | | println!("{}", vec[i]);
193 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for <item> in vec.iter().take(10 + 1).skip(5) {
@ -255,15 +244,14 @@ help: consider using an iterator
error: the loop variable `i` is used to index `vec`
--> $DIR/for_loop.rs:195:5
|
195 | for i in 5..vec.len() {
| _____^ starting here...
195 | / for i in 5..vec.len() {
196 | |
197 | |
198 | |
199 | |
200 | | println!("{} {}", vec[i], i);
201 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for (i, <item>) in vec.iter().enumerate().skip(5) {
@ -271,15 +259,14 @@ help: consider using an iterator
error: the loop variable `i` is used to index `vec`
--> $DIR/for_loop.rs:203:5
|
203 | for i in 5..10 {
| _____^ starting here...
203 | / for i in 5..10 {
204 | |
205 | |
206 | |
207 | |
208 | | println!("{} {}", vec[i], i);
209 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using an iterator
| for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
@ -287,14 +274,13 @@ help: consider using an iterator
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:211:5
|
211 | for i in 10..0 {
| _____^ starting here...
211 | / for i in 10..0 {
212 | |
213 | |
214 | |
215 | | println!("{}", i);
216 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/for_loop.rs:90:90
@ -307,14 +293,13 @@ help: consider using the following if you are attempting to iterate over this ra
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:218:5
|
218 | for i in 10...0 {
| _____^ starting here...
218 | / for i in 10...0 {
219 | |
220 | |
221 | |
222 | | println!("{}", i);
223 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using the following if you are attempting to iterate over this range in reverse
| for i in (0...10).rev() {
@ -322,13 +307,12 @@ help: consider using the following if you are attempting to iterate over this ra
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:225:5
|
225 | for i in MAX_LEN..0 {
| _____^ starting here...
225 | / for i in MAX_LEN..0 {
226 | |
227 | |
228 | | println!("{}", i);
229 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using the following if you are attempting to iterate over this range in reverse
| for i in (0..MAX_LEN).rev() {
@ -336,23 +320,21 @@ help: consider using the following if you are attempting to iterate over this ra
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:231:5
|
231 | for i in 5..5 {
| _____^ starting here...
231 | / for i in 5..5 {
232 | | println!("{}", i);
233 | | }
| |_____^ ...ending here
| |_____^
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:252:5
|
252 | for i in 10..5+4 {
| _____^ starting here...
252 | / for i in 10..5+4 {
253 | |
254 | |
255 | |
256 | | println!("{}", i);
257 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using the following if you are attempting to iterate over this range in reverse
| for i in (5+4..10).rev() {
@ -360,14 +342,13 @@ help: consider using the following if you are attempting to iterate over this ra
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:259:5
|
259 | for i in (5+2)..(3-1) {
| _____^ starting here...
259 | / for i in (5+2)..(3-1) {
260 | |
261 | |
262 | |
263 | | println!("{}", i);
264 | | }
| |_____^ ...ending here
| |_____^
|
help: consider using the following if you are attempting to iterate over this range in reverse
| for i in ((3-1)..(5+2)).rev() {
@ -375,11 +356,10 @@ help: consider using the following if you are attempting to iterate over this ra
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:266:5
|
266 | for i in (5+2)..(8-1) {
| _____^ starting here...
266 | / for i in (5+2)..(8-1) {
267 | | println!("{}", i);
268 | | }
| |_____^ ...ending here
| |_____^
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop.rs:289:15
@ -553,15 +533,14 @@ error: the variable `_index` is used as a loop counter. Consider using `for (_in
error: you seem to want to iterate on a map's values
--> $DIR/for_loop.rs:444:5
|
444 | for (_, v) in &m {
| _____^ starting here...
444 | / for (_, v) in &m {
445 | |
446 | |
447 | |
448 | |
449 | | let _v = v;
450 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/for_loop.rs:90:133
@ -574,15 +553,14 @@ help: use the corresponding method
error: you seem to want to iterate on a map's values
--> $DIR/for_loop.rs:453:5
|
453 | for (_, v) in &*m {
| _____^ starting here...
453 | / for (_, v) in &*m {
454 | |
455 | |
456 | |
... |
460 | | // `in *m.values()` as we used to
461 | | }
| |_____^ ...ending here
| |_____^
|
help: use the corresponding method
| for v in (*m).values() {
@ -590,15 +568,14 @@ help: use the corresponding method
error: you seem to want to iterate on a map's values
--> $DIR/for_loop.rs:464:5
|
464 | for (_, v) in &mut m {
| _____^ starting here...
464 | / for (_, v) in &mut m {
465 | |
466 | |
467 | |
468 | |
469 | | let _v = v;
470 | | }
| |_____^ ...ending here
| |_____^
|
help: use the corresponding method
| for v in m.values_mut() {
@ -606,15 +583,14 @@ help: use the corresponding method
error: you seem to want to iterate on a map's values
--> $DIR/for_loop.rs:473:5
|
473 | for (_, v) in &mut *m {
| _____^ starting here...
473 | / for (_, v) in &mut *m {
474 | |
475 | |
476 | |
477 | |
478 | | let _v = v;
479 | | }
| |_____^ ...ending here
| |_____^
|
help: use the corresponding method
| for v in (*m).values_mut() {
@ -622,15 +598,14 @@ help: use the corresponding method
error: you seem to want to iterate on a map's keys
--> $DIR/for_loop.rs:483:5
|
483 | for (k, _value) in rm {
| _____^ starting here...
483 | / for (k, _value) in rm {
484 | |
485 | |
486 | |
487 | |
488 | | let _k = k;
489 | | }
| |_____^ ...ending here
| |_____^
|
help: use the corresponding method
| for k in rm.keys() {

View File

@ -34,11 +34,11 @@ error: this is an `else if` but the formatting might hide it
--> $DIR/formatting.rs:45:6
|
45 | } else
| ______^ starting here...
| ______^
46 | |
47 | |
48 | | if foo() { // the span of the above error should continue here
| |____^ ...ending here
| |____^
|
= note: #[deny(suspicious_else_formatting)] implied by #[deny(clippy)]
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
@ -47,12 +47,12 @@ error: this is an `else if` but the formatting might hide it
--> $DIR/formatting.rs:52:6
|
52 | }
| ______^ starting here...
| ______^
53 | |
54 | |
55 | | else
56 | | if foo() { // the span of the above error should continue here
| |____^ ...ending here
| |____^
|
= note: #[deny(suspicious_else_formatting)] implied by #[deny(clippy)]
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`

View File

@ -1,11 +1,10 @@
error: this function has too many arguments (8/7)
--> $DIR/functions.rs:11:1
|
11 | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {
| _^ starting here...
11 | / fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {
12 | |
13 | | }
| |_^ ...ending here
| |_^
|
= note: #[deny(too_many_arguments)] implied by #[deny(clippy)]
note: lint level defined here

View File

@ -1,13 +1,12 @@
error: Unnecessary boolean `not` operation
--> $DIR/if_not_else.rs:9:5
|
9 | if !bla() {
| _____^ starting here...
9 | / if !bla() {
10 | | println!("Bugs");
11 | | } else {
12 | | println!("Bunny");
13 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/if_not_else.rs:4:9
@ -19,13 +18,12 @@ note: lint level defined here
error: Unnecessary `!=` operation
--> $DIR/if_not_else.rs:14:5
|
14 | if 4 != 5 {
| _____^ starting here...
14 | / if 4 != 5 {
15 | | println!("Bugs");
16 | | } else {
17 | | println!("Bunny");
18 | | }
| |_____^ ...ending here
| |_____^
|
= help: change to `==` and swap the blocks of the if/else

View File

@ -1,13 +1,12 @@
error: item `PubOne` has a public `len` method but no corresponding `is_empty` method
--> $DIR/len_zero.rs:9:1
|
9 | impl PubOne {
| _^ starting here...
9 | / impl PubOne {
10 | | pub fn len(self: &Self) -> isize {
11 | | 1
12 | | }
13 | | }
| |_^ ...ending here
| |_^
|
note: lint level defined here
--> $DIR/len_zero.rs:4:9
@ -18,37 +17,34 @@ note: lint level defined here
error: trait `PubTraitsToo` has a `len` method but no `is_empty` method
--> $DIR/len_zero.rs:55:1
|
55 | pub trait PubTraitsToo {
| _^ starting here...
55 | / pub trait PubTraitsToo {
56 | | fn len(self: &Self) -> isize;
57 | | }
| |_^ ...ending here
| |_^
error: item `HasIsEmpty` has a public `len` method but a private `is_empty` method
--> $DIR/len_zero.rs:89:1
|
89 | impl HasIsEmpty {
| _^ starting here...
89 | / impl HasIsEmpty {
90 | | pub fn len(self: &Self) -> isize {
91 | | 1
92 | | }
... |
96 | | }
97 | | }
| |_^ ...ending here
| |_^
error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` method
--> $DIR/len_zero.rs:118:1
|
118 | impl HasWrongIsEmpty {
| _^ starting here...
118 | / impl HasWrongIsEmpty {
119 | | pub fn len(self: &Self) -> isize {
120 | | 1
121 | | }
... |
125 | | }
126 | | }
| |_^ ...ending here
| |_^
error: length comparison to zero
--> $DIR/len_zero.rs:130:8

View File

@ -1,15 +1,14 @@
error: `if _ { .. } else { .. }` is an expression
--> $DIR/let_if_seq.rs:57:5
|
57 | let mut foo = 0;
| _____^ starting here...
57 | / let mut foo = 0;
58 | |
59 | |
60 | |
61 | | if f() {
62 | | foo = 42;
63 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/let_if_seq.rs:5:9
@ -23,15 +22,14 @@ help: it is more idiomatic to write
error: `if _ { .. } else { .. }` is an expression
--> $DIR/let_if_seq.rs:65:5
|
65 | let mut bar = 0;
| _____^ starting here...
65 | / let mut bar = 0;
66 | |
67 | |
68 | |
... |
74 | | f();
75 | | }
| |_____^ ...ending here
| |_____^
|
help: it is more idiomatic to write
| let <mut> bar = if f() { ..; 42 } else { ..; 0 };
@ -40,15 +38,14 @@ help: it is more idiomatic to write
error: `if _ { .. } else { .. }` is an expression
--> $DIR/let_if_seq.rs:77:5
|
77 | let quz;
| _____^ starting here...
77 | / let quz;
78 | |
79 | |
80 | |
... |
85 | | quz = 0;
86 | | }
| |_____^ ...ending here
| |_____^
|
help: it is more idiomatic to write
| let quz = if f() { 42 } else { 0 };
@ -56,15 +53,14 @@ help: it is more idiomatic to write
error: `if _ { .. } else { .. }` is an expression
--> $DIR/let_if_seq.rs:111:5
|
111 | let mut baz = 0;
| _____^ starting here...
111 | / let mut baz = 0;
112 | |
113 | |
114 | |
115 | | if f() {
116 | | baz = 42;
117 | | }
| |_____^ ...ending here
| |_____^
|
help: it is more idiomatic to write
| let <mut> baz = if f() { 42 } else { 0 };

View File

@ -128,5 +128,29 @@ fn elided_input_named_output<'a>(_arg: &str) -> &'a str { unimplemented!() }
fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
fn trait_bound<'a, T: WithLifetime<'a>>(_: &'a u8, _: T) { unimplemented!() }
// don't warn on these, see #292
fn trait_bound_bug<'a, T: WithLifetime<'a>>() { unimplemented!() }
// #740
struct Test {
vec: Vec<usize>,
}
impl Test {
fn iter<'a>(&'a self) -> Box<Iterator<Item = usize> + 'a> {
unimplemented!()
}
}
trait LintContext<'a> {}
fn f<'a, T: LintContext<'a>>(_: &T) {}
fn test<'a>(x: &'a [u8]) -> u8 {
let y: &'a u8 = &x[5];
*y
}
fn main() {
}

View File

@ -43,11 +43,10 @@ error: explicit lifetimes given in parameter types where they could be elided
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:58:1
|
58 | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
| _^ starting here...
58 | / fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
59 | | where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>
60 | | { unreachable!() }
| |__________________^ ...ending here
| |__________________^
error: explicit lifetimes given in parameter types where they could be elided
--> $DIR/lifetimes.rs:67:5

View File

@ -1,15 +1,14 @@
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
--> $DIR/matches.rs:26:5
|
26 | match ExprNode::Butterflies {
| _____^ starting here...
26 | / match ExprNode::Butterflies {
27 | |
28 | |
29 | |
30 | | ExprNode::ExprAddrOf => Some(&NODE),
31 | | _ => { let x = 5; None },
32 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/matches.rs:7:9
@ -22,15 +21,14 @@ help: try this
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
--> $DIR/matches.rs:38:5
|
38 | match x {
| _____^ starting here...
38 | / match x {
39 | |
40 | |
41 | |
42 | | Some(y) => { println!("{:?}", y); }
43 | | _ => ()
44 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(single_match)] implied by #[deny(clippy)]
note: lint level defined here
@ -44,15 +42,14 @@ help: try this
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
--> $DIR/matches.rs:47:5
|
47 | match z {
| _____^ starting here...
47 | / match z {
48 | |
49 | |
50 | |
51 | | (2...3, 7...9) => dummy(),
52 | | _ => {}
53 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(single_match)] implied by #[deny(clippy)]
help: try this
@ -61,15 +58,14 @@ help: try this
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
--> $DIR/matches.rs:72:5
|
72 | match x {
| _____^ starting here...
72 | / match x {
73 | |
74 | |
75 | |
76 | | Some(y) => dummy(),
77 | | None => ()
78 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(single_match)] implied by #[deny(clippy)]
help: try this
@ -78,15 +74,14 @@ help: try this
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
--> $DIR/matches.rs:80:5
|
80 | match y {
| _____^ starting here...
80 | / match y {
81 | |
82 | |
83 | |
84 | | Ok(y) => dummy(),
85 | | Err(..) => ()
86 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(single_match)] implied by #[deny(clippy)]
help: try this
@ -95,15 +90,14 @@ help: try this
error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`
--> $DIR/matches.rs:90:5
|
90 | match c {
| _____^ starting here...
90 | / match c {
91 | |
92 | |
93 | |
94 | | Cow::Borrowed(..) => dummy(),
95 | | Cow::Owned(..) => (),
96 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(single_match)] implied by #[deny(clippy)]
help: try this
@ -112,15 +106,14 @@ help: try this
error: you seem to be trying to match on a boolean expression
--> $DIR/matches.rs:114:5
|
114 | match test {
| _____^ starting here...
114 | / match test {
115 | |
116 | |
117 | |
118 | | true => 0,
119 | | false => 42,
120 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_bool)] implied by #[deny(clippy)]
note: lint level defined here
@ -134,15 +127,14 @@ help: consider using an if/else expression
error: you seem to be trying to match on a boolean expression
--> $DIR/matches.rs:123:5
|
123 | match option == 1 {
| _____^ starting here...
123 | / match option == 1 {
124 | |
125 | |
126 | |
127 | | true => 1,
128 | | false => 0,
129 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_bool)] implied by #[deny(clippy)]
help: consider using an if/else expression
@ -151,15 +143,14 @@ help: consider using an if/else expression
error: you seem to be trying to match on a boolean expression
--> $DIR/matches.rs:131:5
|
131 | match test {
| _____^ starting here...
131 | / match test {
132 | |
133 | |
134 | |
135 | | true => (),
136 | | false => { println!("Noooo!"); }
137 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_bool)] implied by #[deny(clippy)]
help: consider using an if/else expression
@ -168,15 +159,14 @@ help: consider using an if/else expression
error: you seem to be trying to match on a boolean expression
--> $DIR/matches.rs:139:5
|
139 | match test {
| _____^ starting here...
139 | / match test {
140 | |
141 | |
142 | |
143 | | false => { println!("Noooo!"); }
144 | | _ => (),
145 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_bool)] implied by #[deny(clippy)]
help: consider using an if/else expression
@ -185,15 +175,14 @@ help: consider using an if/else expression
error: you seem to be trying to match on a boolean expression
--> $DIR/matches.rs:147:5
|
147 | match test && test {
| _____^ starting here...
147 | / match test && test {
148 | |
149 | |
150 | |
... |
153 | | _ => (),
154 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_bool)] implied by #[deny(clippy)]
help: consider using an if/else expression
@ -215,15 +204,14 @@ note: lint level defined here
error: you seem to be trying to match on a boolean expression
--> $DIR/matches.rs:156:5
|
156 | match test {
| _____^ starting here...
156 | / match test {
157 | |
158 | |
159 | |
160 | | false => { println!("Noooo!"); }
161 | | true => { println!("Yes!"); }
162 | | };
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_bool)] implied by #[deny(clippy)]
help: consider using an if/else expression
@ -232,15 +220,14 @@ help: consider using an if/else expression
error: you don't need to add `&` to all patterns
--> $DIR/matches.rs:175:9
|
175 | match v {
| _________^ starting here...
175 | / match v {
176 | |
177 | |
178 | |
179 | | &Some(v) => println!("{:?}", v),
180 | | &None => println!("none"),
181 | | }
| |_________^ ...ending here
| |_________^
|
= note: #[deny(match_ref_pats)] implied by #[deny(clippy)]
note: lint level defined here
@ -254,15 +241,14 @@ help: instead of prefixing all patterns with `&`, you can dereference the expres
error: you don't need to add `&` to all patterns
--> $DIR/matches.rs:188:5
|
188 | match tup {
| _____^ starting here...
188 | / match tup {
189 | |
190 | |
191 | |
192 | | &(v, 1) => println!("{}", v),
193 | | _ => println!("none"),
194 | | }
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_ref_pats)] implied by #[deny(clippy)]
help: instead of prefixing all patterns with `&`, you can dereference the expression
@ -271,15 +257,14 @@ help: instead of prefixing all patterns with `&`, you can dereference the expres
error: you don't need to add `&` to both the expression and the patterns
--> $DIR/matches.rs:197:5
|
197 | match &w {
| _____^ starting here...
197 | / match &w {
198 | |
199 | |
200 | |
201 | | &Some(v) => println!("{:?}", v),
202 | | &None => println!("none"),
203 | | }
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_ref_pats)] implied by #[deny(clippy)]
help: try
@ -288,14 +273,13 @@ help: try
error: you don't need to add `&` to all patterns
--> $DIR/matches.rs:211:5
|
211 | if let &None = a {
| _____^ starting here...
211 | / if let &None = a {
212 | |
213 | |
214 | |
215 | | println!("none");
216 | | }
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_ref_pats)] implied by #[deny(clippy)]
help: instead of prefixing all patterns with `&`, you can dereference the expression
@ -304,14 +288,13 @@ help: instead of prefixing all patterns with `&`, you can dereference the expres
error: you don't need to add `&` to both the expression and the patterns
--> $DIR/matches.rs:219:5
|
219 | if let &None = &b {
| _____^ starting here...
219 | / if let &None = &b {
220 | |
221 | |
222 | |
223 | | println!("none");
224 | | }
| |_____^ ...ending here
| |_____^
|
= note: #[deny(match_ref_pats)] implied by #[deny(clippy)]
help: try

View File

@ -65,10 +65,10 @@ error: called `map(f).unwrap_or(a)` on an Option value. This can be done more di
--> $DIR/methods.rs:99:13
|
99 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
| _____________^
100 | |
101 | | .unwrap_or(0); // should lint even though this call is on a separate line
| |____________________________^ ...ending here
| |____________________________^
|
= note: #[deny(option_map_unwrap_or)] implied by #[deny(clippy_pedantic)]
note: lint level defined here
@ -82,11 +82,11 @@ error: called `map(f).unwrap_or(a)` on an Option value. This can be done more di
--> $DIR/methods.rs:103:13
|
103 | let _ = opt.map(|x| {
| _____________^ starting here...
| _____________^
104 | | x + 1
105 | | }
106 | | ).unwrap_or(0);
| |____________________________^ ...ending here
| |____________________________^
|
= note: #[deny(option_map_unwrap_or)] implied by #[deny(clippy_pedantic)]
@ -94,11 +94,11 @@ error: called `map(f).unwrap_or(a)` on an Option value. This can be done more di
--> $DIR/methods.rs:107:13
|
107 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
| _____________^
108 | | .unwrap_or({
109 | | 0
110 | | });
| |__________________^ ...ending here
| |__________________^
|
= note: #[deny(option_map_unwrap_or)] implied by #[deny(clippy_pedantic)]
@ -106,10 +106,10 @@ error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done mo
--> $DIR/methods.rs:116:13
|
116 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
| _____________^
117 | |
118 | | .unwrap_or_else(|| 0); // should lint even though this call is on a separate line
| |____________________________________^ ...ending here
| |____________________________________^
|
= note: #[deny(option_map_unwrap_or_else)] implied by #[deny(clippy_pedantic)]
note: lint level defined here
@ -123,11 +123,11 @@ error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done mo
--> $DIR/methods.rs:120:13
|
120 | let _ = opt.map(|x| {
| _____________^ starting here...
| _____________^
121 | | x + 1
122 | | }
123 | | ).unwrap_or_else(|| 0);
| |____________________________________^ ...ending here
| |____________________________________^
|
= note: #[deny(option_map_unwrap_or_else)] implied by #[deny(clippy_pedantic)]
@ -135,11 +135,11 @@ error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done mo
--> $DIR/methods.rs:124:13
|
124 | let _ = opt.map(|x| x + 1)
| _____________^ starting here...
| _____________^
125 | | .unwrap_or_else(||
126 | | 0
127 | | );
| |_________________^ ...ending here
| |_________________^
|
= note: #[deny(option_map_unwrap_or_else)] implied by #[deny(clippy_pedantic)]
@ -161,11 +161,11 @@ error: called `filter(p).next()` on an `Iterator`. This is more succinctly expre
--> $DIR/methods.rs:201:13
|
201 | let _ = v.iter().filter(|&x| {
| _____________^ starting here...
| _____________^
202 | | *x < 0
203 | | }
204 | | ).next();
| |___________________________^ ...ending here
| |___________________________^
|
= note: #[deny(filter_next)] implied by #[deny(clippy)]
@ -187,11 +187,11 @@ error: called `is_some()` after searching an `Iterator` with find. This is more
--> $DIR/methods.rs:221:13
|
221 | let _ = v.iter().find(|&x| {
| _____________^ starting here...
| _____________^
222 | | *x < 0
223 | | }
224 | | ).is_some();
| |______________________________^ ...ending here
| |______________________________^
|
= note: #[deny(search_is_some)] implied by #[deny(clippy)]
@ -208,11 +208,11 @@ error: called `is_some()` after searching an `Iterator` with position. This is m
--> $DIR/methods.rs:232:13
|
232 | let _ = v.iter().position(|&x| {
| _____________^ starting here...
| _____________^
233 | | x < 0
234 | | }
235 | | ).is_some();
| |______________________________^ ...ending here
| |______________________________^
|
= note: #[deny(search_is_some)] implied by #[deny(clippy)]
@ -229,11 +229,11 @@ error: called `is_some()` after searching an `Iterator` with rposition. This is
--> $DIR/methods.rs:243:13
|
243 | let _ = v.iter().rposition(|&x| {
| _____________^ starting here...
| _____________^
244 | | x < 0
245 | | }
246 | | ).is_some();
| |______________________________^ ...ending here
| |______________________________^
|
= note: #[deny(search_is_some)] implied by #[deny(clippy)]

View File

@ -19,12 +19,11 @@ error: missing documentation for a type alias
error: missing documentation for a struct
--> $DIR/missing-doc.rs:29:1
|
29 | struct Foo {
| _^ starting here...
29 | / struct Foo {
30 | | a: isize,
31 | | b: isize,
32 | | }
| |_^ ...ending here
| |_^
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:30:5
@ -41,12 +40,11 @@ error: missing documentation for a struct field
error: missing documentation for a struct
--> $DIR/missing-doc.rs:34:1
|
34 | pub struct PubFoo {
| _^ starting here...
34 | / pub struct PubFoo {
35 | | pub a: isize,
36 | | b: isize,
37 | | }
| |_^ ...ending here
| |_^
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:35:5
@ -87,12 +85,11 @@ error: missing documentation for a function
error: missing documentation for a trait
--> $DIR/missing-doc.rs:68:1
|
68 | pub trait C {
| _^ starting here...
68 | / pub trait C {
69 | | fn foo(&self);
70 | | fn foo_with_impl(&self) {}
71 | | }
| |_^ ...ending here
| |_^
error: missing documentation for a trait method
--> $DIR/missing-doc.rs:69:5
@ -145,25 +142,23 @@ error: missing documentation for a method
error: missing documentation for an enum
--> $DIR/missing-doc.rs:126:1
|
126 | enum Baz {
| _^ starting here...
126 | / enum Baz {
127 | | BazA {
128 | | a: isize,
129 | | b: isize
130 | | },
131 | | BarB
132 | | }
| |_^ ...ending here
| |_^
error: missing documentation for a variant
--> $DIR/missing-doc.rs:127:5
|
127 | BazA {
| _____^ starting here...
127 | / BazA {
128 | | a: isize,
129 | | b: isize
130 | | },
| |_____^ ...ending here
| |_____^
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:128:9
@ -186,22 +181,20 @@ error: missing documentation for a variant
error: missing documentation for an enum
--> $DIR/missing-doc.rs:134:1
|
134 | pub enum PubBaz {
| _^ starting here...
134 | / pub enum PubBaz {
135 | | PubBazA {
136 | | a: isize,
137 | | },
138 | | }
| |_^ ...ending here
| |_^
error: missing documentation for a variant
--> $DIR/missing-doc.rs:135:5
|
135 | PubBazA {
| _____^ starting here...
135 | / PubBazA {
136 | | a: isize,
137 | | },
| |_____^ ...ending here
| |_____^
error: missing documentation for a struct field
--> $DIR/missing-doc.rs:136:9
@ -236,15 +229,14 @@ error: missing documentation for a static
error: missing documentation for a module
--> $DIR/missing-doc.rs:180:1
|
180 | mod internal_impl {
| _^ starting here...
180 | / mod internal_impl {
181 | | /// dox
182 | | pub fn documented() {}
183 | | pub fn undocumented1() {}
... |
192 | | }
193 | | }
| |_^ ...ending here
| |_^
error: missing documentation for a function
--> $DIR/missing-doc.rs:183:5

View File

@ -1,11 +1,10 @@
error: module has the same name as its containing module
--> $DIR/module_inception.rs:7:9
|
7 | mod bar {
| _________^ starting here...
7 | / mod bar {
8 | | mod foo {}
9 | | }
| |_________^ ...ending here
| |_________^
|
note: lint level defined here
--> $DIR/module_inception.rs:3:9
@ -16,11 +15,10 @@ note: lint level defined here
error: module has the same name as its containing module
--> $DIR/module_inception.rs:12:5
|
12 | mod foo {
| _____^ starting here...
12 | / mod foo {
13 | | mod bar {}
14 | | }
| |_____^ ...ending here
| |_____^
error: aborting due to 2 previous errors

View File

@ -1,12 +1,11 @@
error: this loop never actually loops
--> $DIR/never_loop.rs:8:5
|
8 | loop {
| _____^ starting here...
8 | / loop {
9 | | println!("This is only ever printed once");
10 | | break;
11 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/never_loop.rs:4:9
@ -17,25 +16,23 @@ note: lint level defined here
error: this loop never actually loops
--> $DIR/never_loop.rs:21:5
|
21 | loop {
| _____^ starting here...
21 | / loop {
22 | | loop {
23 | | // another one
24 | | break;
25 | | }
26 | | break;
27 | | }
| |_____^ ...ending here
| |_____^
error: this loop never actually loops
--> $DIR/never_loop.rs:22:9
|
22 | loop {
| _________^ starting here...
22 | / loop {
23 | | // another one
24 | | break;
25 | | }
| |_________^ ...ending here
| |_________^
error: aborting due to 3 previous errors

View File

@ -4,7 +4,7 @@
#![deny(if_let_some_result)]
fn str_to_int(x: &str) -> i32 {
if let Some(y) = x.parse().ok() {
if let Some(y) = x.parse().ok() {
y
} else {

View File

@ -1,14 +1,13 @@
error: Matching on `Some` with `ok()` is redundant
--> $DIR/ok_if_let.rs:7:5
|
7 | if let Some(y) = x.parse().ok() {
| _____^ starting here...
7 | / if let Some(y) = x.parse().ok() {
8 | |
9 | | y
10 | | } else {
11 | | 0
12 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/ok_if_let.rs:4:9

View File

@ -1,14 +1,13 @@
error: you should not implement `visit_string` without also implementing `visit_str`
--> $DIR/serde.rs:39:5
|
39 | fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
| _____^ starting here...
39 | / fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
40 | |
41 | | where E: serde::de::Error,
42 | | {
43 | | unimplemented!()
44 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/serde.rs:3:9

View File

@ -1,11 +1,10 @@
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:11:5
|
11 | let temp = foo[0];
| _____^ starting here...
11 | / let temp = foo[0];
12 | | foo[0] = foo[1];
13 | | foo[1] = temp;
| |_________________^ ...ending here
| |_________________^
|
= note: #[deny(manual_swap)] implied by #[deny(clippy)]
note: lint level defined here
@ -19,11 +18,10 @@ help: try
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:23:5
|
23 | let temp = foo[0];
| _____^ starting here...
23 | / let temp = foo[0];
24 | | foo[0] = foo[1];
25 | | foo[1] = temp;
| |_________________^ ...ending here
| |_________________^
|
= note: #[deny(manual_swap)] implied by #[deny(clippy)]
help: try
@ -32,11 +30,10 @@ help: try
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:35:5
|
35 | let temp = foo[0];
| _____^ starting here...
35 | / let temp = foo[0];
36 | | foo[0] = foo[1];
37 | | foo[1] = temp;
| |_________________^ ...ending here
| |_________________^
|
= note: #[deny(manual_swap)] implied by #[deny(clippy)]
help: try
@ -46,10 +43,10 @@ error: this looks like you are swapping `a` and `b` manually
--> $DIR/swap.rs:60:7
|
60 | ; let t = a;
| _______^ starting here...
| _______^
61 | | a = b;
62 | | b = t;
| |_________^ ...ending here
| |_________^
|
= note: #[deny(manual_swap)] implied by #[deny(clippy)]
help: try
@ -60,10 +57,10 @@ error: this looks like you are swapping `c.0` and `a` manually
--> $DIR/swap.rs:77:7
|
77 | ; let t = c.0;
| _______^ starting here...
| _______^
78 | | c.0 = a;
79 | | a = t;
| |_________^ ...ending here
| |_________^
|
= note: #[deny(manual_swap)] implied by #[deny(clippy)]
help: try
@ -73,10 +70,9 @@ help: try
error: this looks like you are trying to swap `a` and `b`
--> $DIR/swap.rs:53:5
|
53 | a = b;
| _____^ starting here...
53 | / a = b;
54 | | b = a;
| |_________^ ...ending here
| |_________^
|
= note: #[deny(almost_swapped)] implied by #[deny(clippy)]
note: lint level defined here
@ -91,10 +87,9 @@ help: try
error: this looks like you are trying to swap `c.0` and `a`
--> $DIR/swap.rs:70:5
|
70 | c.0 = a;
| _____^ starting here...
70 | / c.0 = a;
71 | | a = c.0;
| |___________^ ...ending here
| |___________^
|
= note: #[deny(almost_swapped)] implied by #[deny(clippy)]
help: try

View File

@ -1,11 +1,10 @@
error: unused label `'label`
--> $DIR/unused_labels.rs:8:5
|
8 | 'label: for i in 1..2 {
| _____^ starting here...
8 | / 'label: for i in 1..2 {
9 | | if i > 4 { continue }
10 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/unused_labels.rs:5:9
@ -22,11 +21,10 @@ error: unused label `'a`
error: unused label `'same_label_in_two_fns`
--> $DIR/unused_labels.rs:32:5
|
32 | 'same_label_in_two_fns: loop {
| _____^ starting here...
32 | / 'same_label_in_two_fns: loop {
33 | | let _ = 1;
34 | | }
| |_____^ ...ending here
| |_____^
error: aborting due to 3 previous errors

View File

@ -1,15 +1,14 @@
error: this loop could be written as a `while let` loop
--> $DIR/while_loop.rs:9:5
|
9 | loop {
| _____^ starting here...
9 | / loop {
10 | |
11 | |
12 | |
... |
17 | | }
18 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/while_loop.rs:4:9
@ -22,15 +21,14 @@ help: try
error: this loop could be written as a `while let` loop
--> $DIR/while_loop.rs:25:5
|
25 | loop {
| _____^ starting here...
25 | / loop {
26 | |
27 | |
28 | |
... |
32 | | };
33 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| while let Some(_x) = y { .. }
@ -38,15 +36,14 @@ help: try
error: this loop could be written as a `while let` loop
--> $DIR/while_loop.rs:34:5
|
34 | loop {
| _____^ starting here...
34 | / loop {
35 | |
36 | |
37 | |
... |
43 | | let _str = "foo";
44 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| while let Some(x) = y { .. }
@ -54,15 +51,14 @@ help: try
error: this loop could be written as a `while let` loop
--> $DIR/while_loop.rs:45:5
|
45 | loop {
| _____^ starting here...
45 | / loop {
46 | |
47 | |
48 | |
... |
54 | | { let _b = "foobar"; }
55 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| while let Some(x) = y { .. }
@ -70,15 +66,14 @@ help: try
error: this loop could be written as a `while let` loop
--> $DIR/while_loop.rs:70:5
|
70 | loop {
| _____^ starting here...
70 | / loop {
71 | |
72 | |
73 | |
... |
79 | | let _ = (e, l);
80 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| while let Some(word) = "".split_whitespace().next() { .. }
@ -86,14 +81,13 @@ help: try
error: this loop could be written as a `for` loop
--> $DIR/while_loop.rs:83:5
|
83 | while let Option::Some(x) = iter.next() {
| _____^ starting here...
83 | / while let Option::Some(x) = iter.next() {
84 | |
85 | |
86 | |
87 | | println!("{}", x);
88 | | }
| |_____^ ...ending here
| |_____^
|
note: lint level defined here
--> $DIR/while_loop.rs:4:37
@ -106,14 +100,13 @@ help: try
error: this loop could be written as a `for` loop
--> $DIR/while_loop.rs:91:5
|
91 | while let Some(x) = iter.next() {
| _____^ starting here...
91 | / while let Some(x) = iter.next() {
92 | |
93 | |
94 | |
95 | | println!("{}", x);
96 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| for x in iter { .. }
@ -130,15 +123,14 @@ help: try
error: this loop could be written as a `while let` loop
--> $DIR/while_loop.rs:142:5
|
142 | loop {
| _____^ starting here...
142 | / loop {
143 | |
144 | |
145 | |
... |
150 | | loop {}
151 | | }
| |_____^ ...ending here
| |_____^
|
help: try
| while let Some(ele) = iter.next() { .. }

View File

@ -4,7 +4,8 @@
#[macro_use]
extern crate serde_derive;
/// Test that we do not lint for unused underscores in a `MacroAttribute` expansion
/// Test that we do not lint for unused underscores in a `MacroAttribute`
/// expansion
#[deny(used_underscore_binding)]
#[derive(Deserialize)]
struct MacroAttributesTest {