Skip to content

Commit eb5f146

Browse files
committed
Fix 'impossible case reached' ICE
1 parent 5f9af5f commit eb5f146

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
174174
(
175175
preds.iter().any(|t| t.def_id() == borrow_trait),
176176
!preds.is_empty() && preds.iter().all(|t| {
177+
let ty_params = &t.skip_binder().trait_ref.substs.iter().skip(1)
178+
.cloned()
179+
.collect::<Vec<_>>();
177180
implements_trait(
178181
cx,
179182
cx.tcx.mk_imm_ref(&RegionKind::ReErased, ty),
180183
t.def_id(),
181-
&t.skip_binder()
182-
.input_types()
183-
.skip(1)
184-
.map(|ty| ty.into())
185-
.collect::<Vec<_>>(),
184+
ty_params
186185
)
187186
}),
188187
)

tests/ui/needless_pass_by_value.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,14 @@ fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
134134
println!("{}", t);
135135
}
136136

137+
// The following 3 lines should not cause an ICE. See #2831
138+
trait Bar<'a, A> {}
139+
impl<'b, T> Bar<'b, T> for T {}
140+
fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {}
141+
142+
// Also this should not cause an ICE. See #2831
143+
trait Club<'a, A> {}
144+
impl<T> Club<'static, T> for T {}
145+
fn more_fun(_item: impl Club<'static, i32>) {}
146+
137147
fn main() {}

tests/ui/needless_pass_by_value.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,17 @@ help: consider taking a reference instead
184184
129 | let CopyWrapper(s) = *z; // moved
185185
|
186186

187-
error: aborting due to 20 previous errors
187+
error: this argument is passed by value, but not consumed in the function body
188+
--> $DIR/needless_pass_by_value.rs:140:40
189+
|
190+
140 | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {}
191+
| ^ help: consider taking a reference instead: `&S`
192+
193+
error: this argument is passed by value, but not consumed in the function body
194+
--> $DIR/needless_pass_by_value.rs:145:20
195+
|
196+
145 | fn more_fun(_item: impl Club<'static, i32>) {}
197+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>`
198+
199+
error: aborting due to 22 previous errors
188200

0 commit comments

Comments
 (0)