From f6a75f17f6869aa12e6624b24aab02a0230af4e8 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 3 Dec 2019 17:54:32 +0100 Subject: [PATCH 1/4] Rustup to rust-lang/rust#66935 --- clippy_lints/src/attrs.rs | 2 +- clippy_lints/src/dbg_macro.rs | 6 +++--- clippy_lints/src/write.rs | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 5c881adca2c..487ebb454e4 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -424,7 +424,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib }; if attr.style == AttrStyle::Outer { - if attr_item.tokens.is_empty() || !is_present_in_source(cx, attr.span) { + if attr_item.args.inner_tokens().is_empty() || !is_present_in_source(cx, attr.span) { return; } diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs index cf21d63880f..0b42e02bbd4 100644 --- a/clippy_lints/src/dbg_macro.rs +++ b/clippy_lints/src/dbg_macro.rs @@ -32,11 +32,11 @@ declare_lint_pass!(DbgMacro => [DBG_MACRO]); impl EarlyLintPass for DbgMacro { fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) { if mac.path == sym!(dbg) { - if let Some(sugg) = tts_span(mac.tts.clone()).and_then(|span| snippet_opt(cx, span)) { + if let Some(sugg) = tts_span(mac.args.inner_tokens()).and_then(|span| snippet_opt(cx, span)) { span_lint_and_sugg( cx, DBG_MACRO, - mac.span, + mac.span(), "`dbg!` macro is intended as a debugging tool", "ensure to avoid having uses of it in version control", sugg, @@ -46,7 +46,7 @@ impl EarlyLintPass for DbgMacro { span_help_and_lint( cx, DBG_MACRO, - mac.span, + mac.span(), "`dbg!` macro is intended as a debugging tool", "ensure to avoid having uses of it in version control", ); diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 07e8fb34c72..5160f0739ec 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -189,13 +189,13 @@ declare_lint_pass!(Write => [ impl EarlyLintPass for Write { fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) { if mac.path == sym!(println) { - span_lint(cx, PRINT_STDOUT, mac.span, "use of `println!`"); - if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) { + span_lint(cx, PRINT_STDOUT, mac.span(), "use of `println!`"); + if let (Some(fmt_str), _) = check_tts(cx, &mac.args.inner_tokens(), false) { if fmt_str.symbol == Symbol::intern("") { span_lint_and_sugg( cx, PRINTLN_EMPTY_STRING, - mac.span, + mac.span(), "using `println!(\"\")`", "replace it with", "println!()".to_string(), @@ -204,13 +204,13 @@ impl EarlyLintPass for Write { } } } else if mac.path == sym!(print) { - span_lint(cx, PRINT_STDOUT, mac.span, "use of `print!`"); - if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) { + span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`"); + if let (Some(fmt_str), _) = check_tts(cx, &mac.args.inner_tokens(), false) { if check_newlines(&fmt_str) { span_lint_and_then( cx, PRINT_WITH_NEWLINE, - mac.span, + mac.span(), "using `print!()` with a format string that ends in a single newline", |err| { err.multipart_suggestion( @@ -226,12 +226,12 @@ impl EarlyLintPass for Write { } } } else if mac.path == sym!(write) { - if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, true) { + if let (Some(fmt_str), _) = check_tts(cx, &mac.args.inner_tokens(), true) { if check_newlines(&fmt_str) { span_lint_and_then( cx, WRITE_WITH_NEWLINE, - mac.span, + mac.span(), "using `write!()` with a format string that ends in a single newline", |err| { err.multipart_suggestion( @@ -247,7 +247,7 @@ impl EarlyLintPass for Write { } } } else if mac.path == sym!(writeln) { - if let (Some(fmt_str), expr) = check_tts(cx, &mac.tts, true) { + if let (Some(fmt_str), expr) = check_tts(cx, &mac.args.inner_tokens(), true) { if fmt_str.symbol == Symbol::intern("") { let mut applicability = Applicability::MachineApplicable; let suggestion = expr.map_or_else( @@ -261,7 +261,7 @@ impl EarlyLintPass for Write { span_lint_and_sugg( cx, WRITELN_EMPTY_STRING, - mac.span, + mac.span(), format!("using `writeln!({}, \"\")`", suggestion).as_str(), "replace it with", format!("writeln!({})", suggestion), From 718558064de4f18032cfb3e64b646f782d6e3664 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Mon, 2 Dec 2019 20:01:50 -0500 Subject: [PATCH 2/4] Fire clippy::op_ref on PartialOrd but !Ord types --- clippy_lints/src/eq_op.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index a7dd9830006..803fb48436a 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { BinOpKind::Shr => (cx.tcx.lang_items().shr_trait(), false), BinOpKind::Ne | BinOpKind::Eq => (cx.tcx.lang_items().eq_trait(), true), BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ge | BinOpKind::Gt => { - (cx.tcx.lang_items().ord_trait(), true) + (cx.tcx.lang_items().partial_ord_trait(), true) }, }; if let Some(trait_id) = trait_id { From c56f72da35679f03d647731fa854fe9f9f3e7aa2 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 3 Dec 2019 18:24:26 +0100 Subject: [PATCH 3/4] Make OP_REF lint suggestion MaybeIncorrect cc #2597 --- clippy_lints/src/eq_op.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 803fb48436a..de7118916de 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -155,7 +155,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { left.span, "use the left value directly", lsnip, - Applicability::MachineApplicable, // snippet + Applicability::MaybeIncorrect, // FIXME #2597 ); }) } @@ -173,7 +173,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { right.span, "use the right value directly", rsnip, - Applicability::MachineApplicable, // snippet + Applicability::MaybeIncorrect, // FIXME #2597 ); }) } From 716239310388662ba9d54781e7c5f89dc9c8e0e9 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 3 Dec 2019 18:26:56 +0100 Subject: [PATCH 4/4] Update op_ref.stderr --- tests/ui/op_ref.stderr | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index 0f6a45f905c..a3a9adcc483 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -10,14 +10,6 @@ help: use the values directly LL | let foo = 5 - 6; | ^ ^ -error: taken reference of right operand - --> $DIR/op_ref.rs:20:8 - | -LL | if b < &a { - | ^^^^-- - | | - | help: use the right value directly: `a` - error: taken reference of right operand --> $DIR/op_ref.rs:57:13 | @@ -26,5 +18,5 @@ LL | let z = x & &y; | | | help: use the right value directly: `y` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors