Skip to content

Commit 2755d12

Browse files
committed
Auto merge of #3744 - phansch:fix3144, r=oli-obk
Fix ICE in needless_pass_by_value lint If I understand it correctly, we were first creating a type with a `RegionKind::ReErased` region and then deleted it again in `util::implements_trait` with: cx.tcx.erase_regions(&ty); causing the type query to fail. It looks like using `ReEmpty` works around that deletion. Fixes #3144
2 parents af43950 + f3cd819 commit 2755d12

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
193193
.skip(1)
194194
.cloned()
195195
.collect::<Vec<_>>();
196-
implements_trait(cx, cx.tcx.mk_imm_ref(&RegionKind::ReErased, ty), t.def_id(), ty_params)
196+
implements_trait(cx, cx.tcx.mk_imm_ref(&RegionKind::ReEmpty, ty), t.def_id(), ty_params)
197197
}),
198198
)
199199
};

tests/ui/needless_pass_by_value.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
)]
99

1010
use std::borrow::Borrow;
11+
use std::collections::HashSet;
1112
use std::convert::AsRef;
1213

1314
// `v` should be warned
@@ -145,4 +146,14 @@ trait Club<'a, A> {}
145146
impl<T> Club<'static, T> for T {}
146147
fn more_fun(_item: impl Club<'static, i32>) {}
147148

148-
fn main() {}
149+
fn is_sync<T>(_: T)
150+
where
151+
T: Sync,
152+
{
153+
}
154+
155+
fn main() {
156+
// This should not cause an ICE either
157+
// https://github.com/rust-lang/rust-clippy/issues/3144
158+
is_sync(HashSet::<usize>::new());
159+
}

tests/ui/needless_pass_by_value.stderr

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: this argument is passed by value, but not consumed in the function body
2-
--> $DIR/needless_pass_by_value.rs:15:23
2+
--> $DIR/needless_pass_by_value.rs:16:23
33
|
44
LL | fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T> {
55
| ^^^^^^ help: consider changing the type to: `&[T]`
66
|
77
= note: `-D clippy::needless-pass-by-value` implied by `-D warnings`
88

99
error: this argument is passed by value, but not consumed in the function body
10-
--> $DIR/needless_pass_by_value.rs:29:11
10+
--> $DIR/needless_pass_by_value.rs:30:11
1111
|
1212
LL | fn bar(x: String, y: Wrapper) {
1313
| ^^^^^^ help: consider changing the type to: `&str`
1414

1515
error: this argument is passed by value, but not consumed in the function body
16-
--> $DIR/needless_pass_by_value.rs:29:22
16+
--> $DIR/needless_pass_by_value.rs:30:22
1717
|
1818
LL | fn bar(x: String, y: Wrapper) {
1919
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
2020

2121
error: this argument is passed by value, but not consumed in the function body
22-
--> $DIR/needless_pass_by_value.rs:35:71
22+
--> $DIR/needless_pass_by_value.rs:36:71
2323
|
2424
LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: V) {
2525
| ^ help: consider taking a reference instead: `&V`
2626

2727
error: this argument is passed by value, but not consumed in the function body
28-
--> $DIR/needless_pass_by_value.rs:47:18
28+
--> $DIR/needless_pass_by_value.rs:48:18
2929
|
3030
LL | fn test_match(x: Option<Option<String>>, y: Option<Option<String>>) {
3131
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -36,13 +36,13 @@ LL | match *x {
3636
|
3737

3838
error: this argument is passed by value, but not consumed in the function body
39-
--> $DIR/needless_pass_by_value.rs:60:24
39+
--> $DIR/needless_pass_by_value.rs:61:24
4040
|
4141
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
4242
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
4343

4444
error: this argument is passed by value, but not consumed in the function body
45-
--> $DIR/needless_pass_by_value.rs:60:36
45+
--> $DIR/needless_pass_by_value.rs:61:36
4646
|
4747
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
4848
| ^^^^^^^
@@ -55,19 +55,19 @@ LL | let Wrapper(_) = *y; // still not moved
5555
|
5656

5757
error: this argument is passed by value, but not consumed in the function body
58-
--> $DIR/needless_pass_by_value.rs:76:49
58+
--> $DIR/needless_pass_by_value.rs:77:49
5959
|
6060
LL | fn test_blanket_ref<T: Foo, S: Serialize>(_foo: T, _serializable: S) {}
6161
| ^ help: consider taking a reference instead: `&T`
6262

6363
error: this argument is passed by value, but not consumed in the function body
64-
--> $DIR/needless_pass_by_value.rs:78:18
64+
--> $DIR/needless_pass_by_value.rs:79:18
6565
|
6666
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
6767
| ^^^^^^ help: consider taking a reference instead: `&String`
6868

6969
error: this argument is passed by value, but not consumed in the function body
70-
--> $DIR/needless_pass_by_value.rs:78:29
70+
--> $DIR/needless_pass_by_value.rs:79:29
7171
|
7272
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
7373
| ^^^^^^
@@ -81,13 +81,13 @@ LL | let _ = t.to_string();
8181
| ^^^^^^^^^^^^^
8282

8383
error: this argument is passed by value, but not consumed in the function body
84-
--> $DIR/needless_pass_by_value.rs:78:40
84+
--> $DIR/needless_pass_by_value.rs:79:40
8585
|
8686
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
8787
| ^^^^^^^^ help: consider taking a reference instead: `&Vec<i32>`
8888

8989
error: this argument is passed by value, but not consumed in the function body
90-
--> $DIR/needless_pass_by_value.rs:78:53
90+
--> $DIR/needless_pass_by_value.rs:79:53
9191
|
9292
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
9393
| ^^^^^^^^
@@ -101,61 +101,61 @@ LL | let _ = v.to_owned();
101101
| ^^^^^^^^^^^^
102102

103103
error: this argument is passed by value, but not consumed in the function body
104-
--> $DIR/needless_pass_by_value.rs:91:12
104+
--> $DIR/needless_pass_by_value.rs:92:12
105105
|
106106
LL | s: String,
107107
| ^^^^^^ help: consider changing the type to: `&str`
108108

109109
error: this argument is passed by value, but not consumed in the function body
110-
--> $DIR/needless_pass_by_value.rs:92:12
110+
--> $DIR/needless_pass_by_value.rs:93:12
111111
|
112112
LL | t: String,
113113
| ^^^^^^ help: consider taking a reference instead: `&String`
114114

115115
error: this argument is passed by value, but not consumed in the function body
116-
--> $DIR/needless_pass_by_value.rs:101:23
116+
--> $DIR/needless_pass_by_value.rs:102:23
117117
|
118118
LL | fn baz(&self, _u: U, _s: Self) {}
119119
| ^ help: consider taking a reference instead: `&U`
120120

121121
error: this argument is passed by value, but not consumed in the function body
122-
--> $DIR/needless_pass_by_value.rs:101:30
122+
--> $DIR/needless_pass_by_value.rs:102:30
123123
|
124124
LL | fn baz(&self, _u: U, _s: Self) {}
125125
| ^^^^ help: consider taking a reference instead: `&Self`
126126

127127
error: this argument is passed by value, but not consumed in the function body
128-
--> $DIR/needless_pass_by_value.rs:123:24
128+
--> $DIR/needless_pass_by_value.rs:124:24
129129
|
130130
LL | fn bar_copy(x: u32, y: CopyWrapper) {
131131
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
132132
|
133133
help: consider marking this type as Copy
134-
--> $DIR/needless_pass_by_value.rs:121:1
134+
--> $DIR/needless_pass_by_value.rs:122:1
135135
|
136136
LL | struct CopyWrapper(u32);
137137
| ^^^^^^^^^^^^^^^^^^^^^^^^
138138

139139
error: this argument is passed by value, but not consumed in the function body
140-
--> $DIR/needless_pass_by_value.rs:129:29
140+
--> $DIR/needless_pass_by_value.rs:130:29
141141
|
142142
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
143143
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
144144
|
145145
help: consider marking this type as Copy
146-
--> $DIR/needless_pass_by_value.rs:121:1
146+
--> $DIR/needless_pass_by_value.rs:122:1
147147
|
148148
LL | struct CopyWrapper(u32);
149149
| ^^^^^^^^^^^^^^^^^^^^^^^^
150150

151151
error: this argument is passed by value, but not consumed in the function body
152-
--> $DIR/needless_pass_by_value.rs:129:45
152+
--> $DIR/needless_pass_by_value.rs:130:45
153153
|
154154
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
155155
| ^^^^^^^^^^^
156156
|
157157
help: consider marking this type as Copy
158-
--> $DIR/needless_pass_by_value.rs:121:1
158+
--> $DIR/needless_pass_by_value.rs:122:1
159159
|
160160
LL | struct CopyWrapper(u32);
161161
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -168,13 +168,13 @@ LL | let CopyWrapper(_) = *y; // still not moved
168168
|
169169

170170
error: this argument is passed by value, but not consumed in the function body
171-
--> $DIR/needless_pass_by_value.rs:129:61
171+
--> $DIR/needless_pass_by_value.rs:130:61
172172
|
173173
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
174174
| ^^^^^^^^^^^
175175
|
176176
help: consider marking this type as Copy
177-
--> $DIR/needless_pass_by_value.rs:121:1
177+
--> $DIR/needless_pass_by_value.rs:122:1
178178
|
179179
LL | struct CopyWrapper(u32);
180180
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -185,13 +185,13 @@ LL | let CopyWrapper(s) = *z; // moved
185185
|
186186

187187
error: this argument is passed by value, but not consumed in the function body
188-
--> $DIR/needless_pass_by_value.rs:141:40
188+
--> $DIR/needless_pass_by_value.rs:142:40
189189
|
190190
LL | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {}
191191
| ^ help: consider taking a reference instead: `&S`
192192

193193
error: this argument is passed by value, but not consumed in the function body
194-
--> $DIR/needless_pass_by_value.rs:146:20
194+
--> $DIR/needless_pass_by_value.rs:147:20
195195
|
196196
LL | fn more_fun(_item: impl Club<'static, i32>) {}
197197
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>`

0 commit comments

Comments
 (0)