Skip to content

Commit 0d8a27a

Browse files
committed
Auto merge of rust-lang#6510 - alex-700:fix-ptr-arg-lint, r=llogiq
don't ignore expression after first not matched method call in PtrCloneVisitor fixes rust-lang#6509 changelog: none
2 parents 61a3ee7 + 203715a commit 0d8a27a

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

clippy_lints/src/utils/ptr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> {
7272
}
7373
}
7474
}
75-
return;
7675
}
7776
walk_expr(self, expr);
7877
}

tests/ui/ptr_arg.rs

+19
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,22 @@ mod issue_5644 {
136136
}
137137
}
138138
}
139+
140+
mod issue6509 {
141+
use std::path::PathBuf;
142+
143+
fn foo_vec(vec: &Vec<u8>) {
144+
let _ = vec.clone().pop();
145+
let _ = vec.clone().clone();
146+
}
147+
148+
fn foo_path(path: &PathBuf) {
149+
let _ = path.clone().pop();
150+
let _ = path.clone().clone();
151+
}
152+
153+
fn foo_str(str: &PathBuf) {
154+
let _ = str.clone().pop();
155+
let _ = str.clone().clone();
156+
}
157+
}

tests/ui/ptr_arg.stderr

+58-1
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,62 @@ error: using a reference to `Cow` is not recommended.
114114
LL | fn test_cow_with_ref(c: &Cow<[i32]>) {}
115115
| ^^^^^^^^^^^ help: change this to: `&[i32]`
116116

117-
error: aborting due to 9 previous errors
117+
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
118+
--> $DIR/ptr_arg.rs:143:21
119+
|
120+
LL | fn foo_vec(vec: &Vec<u8>) {
121+
| ^^^^^^^^
122+
|
123+
help: change this to
124+
|
125+
LL | fn foo_vec(vec: &[u8]) {
126+
| ^^^^^
127+
help: change `vec.clone()` to
128+
|
129+
LL | let _ = vec.to_owned().pop();
130+
| ^^^^^^^^^^^^^^
131+
help: change `vec.clone()` to
132+
|
133+
LL | let _ = vec.to_owned().clone();
134+
| ^^^^^^^^^^^^^^
135+
136+
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
137+
--> $DIR/ptr_arg.rs:148:23
138+
|
139+
LL | fn foo_path(path: &PathBuf) {
140+
| ^^^^^^^^
141+
|
142+
help: change this to
143+
|
144+
LL | fn foo_path(path: &Path) {
145+
| ^^^^^
146+
help: change `path.clone()` to
147+
|
148+
LL | let _ = path.to_path_buf().pop();
149+
| ^^^^^^^^^^^^^^^^^^
150+
help: change `path.clone()` to
151+
|
152+
LL | let _ = path.to_path_buf().clone();
153+
| ^^^^^^^^^^^^^^^^^^
154+
155+
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
156+
--> $DIR/ptr_arg.rs:153:21
157+
|
158+
LL | fn foo_str(str: &PathBuf) {
159+
| ^^^^^^^^
160+
|
161+
help: change this to
162+
|
163+
LL | fn foo_str(str: &Path) {
164+
| ^^^^^
165+
help: change `str.clone()` to
166+
|
167+
LL | let _ = str.to_path_buf().pop();
168+
| ^^^^^^^^^^^^^^^^^
169+
help: change `str.clone()` to
170+
|
171+
LL | let _ = str.to_path_buf().clone();
172+
| ^^^^^^^^^^^^^^^^^
173+
174+
error: aborting due to 12 previous errors
118175

0 commit comments

Comments
 (0)