diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index ea7bbfe81..6fe089cf9 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -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(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()); diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index 06e9268d2..73d9f8ba1 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -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 } }; diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 6fbf99f13..764bcded5 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -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)]); - } - ) + }) } - } - _ => {} + }, + _ => {}, } } } diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 7fa8c3deb..8f8c7db64 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -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 // it’s 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') { diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index be8e04c42..a691e228a 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -89,7 +89,13 @@ enum RefLt { Named(Name), } -fn check_fn_inner<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, body: Option, generics: &'tcx Generics, span: Span) { +fn check_fn_inner<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + decl: &'tcx FnDecl, + body: Option, + generics: &'tcx Generics, + span: Span +) { if in_external_macro(cx, span) || has_where_lifetimes(cx, &generics.where_clause) { return; } @@ -128,7 +134,7 @@ fn could_use_elision<'a, 'tcx: 'a>( func: &'tcx FnDecl, body: Option, named_lts: &'tcx [LifetimeDef], - bounds_lts: Vec<&'tcx Lifetime>, + bounds_lts: Vec<&'tcx Lifetime> ) -> bool { // There are two scenarios where elision works: // * no output references, all input references have different LT @@ -265,11 +271,7 @@ impl<'v, 't> RefVisitor<'v, 't> { } fn into_vec(self) -> Option> { - if self.abort { - None - } else { - Some(self.lts) - } + if self.abort { None } else { Some(self.lts) } } fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) { @@ -359,9 +361,11 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: & // and check that all lifetimes are allowed match visitor.into_vec() { None => return false, - Some(lts) => for lt in lts { - if !allowed_lts.contains(<) { - return true; + Some(lts) => { + for lt in lts { + if !allowed_lts.contains(<) { + return true; + } } }, } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index d7760a306..7f0174fce 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -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, diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index e84fd1968..c2fc932a6 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -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. diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 53b26fc12..70ae9471b 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -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"); } diff --git a/clippy_lints/src/utils/hir.rs b/clippy_lints/src/utils/hir.rs index a818f99fe..5820f6004 100644 --- a/clippy_lints/src/utils/hir.rs +++ b/clippy_lints/src/utils/hir.rs @@ -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)) => { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index db595b079..87b430626 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -690,8 +690,10 @@ fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &' /// See also `is_direct_expn_of`. pub fn is_expn_of(mut span: Span, name: &str) -> Option { 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 { /// `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 { - 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), diff --git a/src/lib.rs b/src/lib.rs index 9672f16ed..a1e18ecc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; } } diff --git a/src/main.rs b/src/main.rs index 0e25ca973..1b3dd4f05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, ofile: &Option, - descriptions: &rustc_errors::registry::Registry + descriptions: &rustc_errors::registry::Registry, ) -> Option<(Input, Option)> { - 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, - ofile: &Option + ofile: &Option, ) -> 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 = 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 = 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"); } } diff --git a/tests/cc_seme.rs b/tests/cc_seme.rs index df2579cab..c81b32c54 100644 --- a/tests/cc_seme.rs +++ b/tests/cc_seme.rs @@ -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!(), } diff --git a/tests/matches.rs b/tests/matches.rs index 506926501..ade8db2aa 100644 --- a/tests/matches.rs +++ b/tests/matches.rs @@ -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))])); } diff --git a/tests/used_underscore_binding_macro.rs b/tests/used_underscore_binding_macro.rs index 90cb106de..b323cb5d2 100644 --- a/tests/used_underscore_binding_macro.rs +++ b/tests/used_underscore_binding_macro.rs @@ -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 {