Skip to content

Commit e018a2c

Browse files
committed
Auto merge of rust-lang#10328 - compiler-errors:fix-re-erased-in-needless_pass_by_value, r=matthiaskrgr
Liberate late-bound regions rather than erasing them in `needless_pass_by_value` changelog: [`needless_pass_by_value`]: fixes an ICE when there are late-bound regions in function arguments that are needlessly passed by value Fixes rust-lang#107147 r? `@matthiaskrgr`
2 parents 4c28fdd + 17cb2e4 commit e018a2c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
149149
};
150150

151151
let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity();
152-
let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig);
152+
let fn_sig = cx.tcx.liberate_late_bound_regions(fn_def_id.to_def_id(), fn_sig);
153153

154154
for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() {
155155
// All spans generated from a proc-macro invocation are the same...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://github.com/rust-lang/rust/issues/107147
2+
3+
#![warn(clippy::needless_pass_by_value)]
4+
5+
struct Foo<'a>(&'a [(); 100]);
6+
7+
fn test(x: Foo<'_>) {}
8+
9+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: this argument is passed by value, but not consumed in the function body
2+
--> $DIR/needless_pass_by_value-w-late-bound.rs:7:12
3+
|
4+
LL | fn test(x: Foo<'_>) {}
5+
| ^^^^^^^ help: consider taking a reference instead: `&Foo<'_>`
6+
|
7+
help: consider marking this type as `Copy`
8+
--> $DIR/needless_pass_by_value-w-late-bound.rs:5:1
9+
|
10+
LL | struct Foo<'a>(&'a [(); 100]);
11+
| ^^^^^^^^^^^^^^
12+
= note: `-D clippy::needless-pass-by-value` implied by `-D warnings`
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)