Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of cycle Clippy update #93001

Merged
merged 28 commits into from
Jan 18, 2022
Merged
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ad95279
Suggest deref when needed in `implicit_clone`
Jarcho Jan 5, 2022
875b240
Apply `not_unsafe_ptr_arg_deref` to type aliases
SeeSpring Jan 13, 2022
5cada57
Auto merge of #8273 - SeeSpring:apply_not_unsafe_ptr_arg_deref_to_typ…
bors Jan 13, 2022
adc3e66
Escape pipes in Markdown tables
thaliaarchi Jan 13, 2022
65c072d
Update markdown-it version
thaliaarchi Jan 14, 2022
7a4acf9
Auto merge of #8231 - Jarcho:implicit_clone_8227, r=camsteffen
bors Jan 14, 2022
4119801
Update copyright year for Clippy (2022 edition)
xFrednet Jan 15, 2022
70a6d7b
Erase late bound regions in `iter_not_returning_iterator`
Jarcho Jan 15, 2022
496f26c
Auto merge of #8287 - Jarcho:iter_not_returning_iterator_8285, r=Mani…
bors Jan 15, 2022
ee84ac3
issue #8239: Printed hint for lint or_fun_call is cropped and does no…
marekdownar Jan 15, 2022
4950272
issue #8239: fix to prev commit && 4 test cases
marekdownar Jan 15, 2022
cb384ff
Handle implicit named arguments in `useless_format`
Jarcho Jan 15, 2022
27845a9
Auto merge of #8274 - andrewarchi:master, r=camsteffen
bors Jan 15, 2022
d61f798
Auto merge of #8284 - xFrednet:0000-update-copyright-year-i-am-procra…
bors Jan 16, 2022
0d27bd8
Auto merge of #8295 - Jarcho:useless_format_8290, r=giraffate
bors Jan 16, 2022
1c9b31d
New line: cloned_next
pmnoxx Dec 31, 2021
d48d247
Fix clippy warnings
pmnoxx Jan 16, 2022
36396c6
Fix tests
pmnoxx Jan 16, 2022
5b6ec8c
#8214 cmp_owned suggestion flips the comparison
marekdownar Jan 16, 2022
93cad4a
Auto merge of #8203 - pmnoxx:piotr-next-lint, r=llogiq
bors Jan 16, 2022
5461ed6
Don't lint `if_same_then_else` with `if let` conditions
Jarcho Jan 16, 2022
537a7f3
Auto merge of #8297 - Jarcho:if_same_then_else_7579, r=Manishearth
bors Jan 17, 2022
d364d8a
Auto merge of #8299 - marekdownar:8214, r=Manishearth
bors Jan 17, 2022
69d78ce
removing unsafe from test fn's && renaming shrink to sugg_span
marekdownar Jan 17, 2022
2d3eb50
Move `return_self_not_must_use` to `pedantic`
xFrednet Jan 17, 2022
72c59fd
Auto merge of #8302 - xFrednet:0000-move-return-self-not-must-use, r=…
bors Jan 17, 2022
8d14c94
Auto merge of #8292 - marekdownar:8239, r=xFrednet
bors Jan 17, 2022
0fc3fda
Merge commit '8d14c94b5c0a66241b4244f1c60ac5859cec1d97' into clippyup
flip1995 Jan 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
@@ -548,6 +548,7 @@ fn is_array(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
matches!(&cx.typeck_results().expr_ty(expr).peel_refs().kind(), ty::Array(_, _))
}

#[allow(clippy::too_many_lines)]
fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool) {
#[derive(Default)]
struct EqImpl {
@@ -644,10 +645,26 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left:
hint = expr_snip;
} else {
span = expr.span.to(other.span);

let cmp_span = if other.span < expr.span {
other.span.between(expr.span)
} else {
expr.span.between(other.span)
};
if eq_impl.ty_eq_other {
hint = format!("{} == {}", expr_snip, snippet(cx, other.span, ".."));
hint = format!(
"{}{}{}",
expr_snip,
snippet(cx, cmp_span, ".."),
snippet(cx, other.span, "..")
);
} else {
hint = format!("{} == {}", snippet(cx, other.span, ".."), expr_snip);
hint = format!(
"{}{}{}",
snippet(cx, other.span, ".."),
snippet(cx, cmp_span, ".."),
expr_snip
);
}
}

29 changes: 29 additions & 0 deletions tests/ui/cmp_owned/comparison_flip.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// run-rustfix

use std::fmt::{self, Display};

fn main() {
let a = Foo;

if a != "bar" {
println!("foo");
}

if a != "bar" {
println!("foo");
}
}

struct Foo;

impl Display for Foo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "foo")
}
}

impl PartialEq<&str> for Foo {
fn eq(&self, other: &&str) -> bool {
"foo" == *other
}
}
29 changes: 29 additions & 0 deletions tests/ui/cmp_owned/comparison_flip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// run-rustfix

use std::fmt::{self, Display};

fn main() {
let a = Foo;

if a.to_string() != "bar" {
println!("foo");
}

if "bar" != a.to_string() {
println!("foo");
}
}

struct Foo;

impl Display for Foo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "foo")
}
}

impl PartialEq<&str> for Foo {
fn eq(&self, other: &&str) -> bool {
"foo" == *other
}
}
18 changes: 18 additions & 0 deletions tests/ui/cmp_owned/comparison_flip.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: this creates an owned instance just for comparison
--> $DIR/comparison_flip.rs:8:8
|
LL | if a.to_string() != "bar" {
| ^^^^^^^^^^^^^ help: try: `a`
|
= note: `-D clippy::cmp-owned` implied by `-D warnings`

error: this creates an owned instance just for comparison
--> $DIR/comparison_flip.rs:12:17
|
LL | if "bar" != a.to_string() {
| ---------^^^^^^^^^^^^^
| |
| help: try: `a != "bar"`

error: aborting due to 2 previous errors