about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-02-12 07:12:32 +0000
committerMichael Goulet <michael@errs.io>2023-02-14 23:27:46 +0000
commit17cb2e47e5503494fa506af42be289f38a3a8d73 (patch)
tree3ed579736166567a5633978f3d9eb644f175199f
parent0f7558148c22e53cd4608773b56cdfa50dcdeac3 (diff)
downloadrust-17cb2e47e5503494fa506af42be289f38a3a8d73.tar.gz
rust-17cb2e47e5503494fa506af42be289f38a3a8d73.zip
Liberate late-bound regions rather than erasing them in needless_pass_by_value
-rw-r--r--clippy_lints/src/needless_pass_by_value.rs2
-rw-r--r--tests/ui/crashes/needless_pass_by_value-w-late-bound.rs9
-rw-r--r--tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr15
3 files changed, 25 insertions, 1 deletions
diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs
index 996ea6ed723..b403092d5c7 100644
--- a/clippy_lints/src/needless_pass_by_value.rs
+++ b/clippy_lints/src/needless_pass_by_value.rs
@@ -149,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
         };
 
         let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity();
-        let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig);
+        let fn_sig = cx.tcx.liberate_late_bound_regions(fn_def_id.to_def_id(), fn_sig);
 
         for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() {
             // All spans generated from a proc-macro invocation are the same...
diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs b/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs
new file mode 100644
index 00000000000..dd3d8b8b6d1
--- /dev/null
+++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs
@@ -0,0 +1,9 @@
+// https://github.com/rust-lang/rust/issues/107147
+
+#![warn(clippy::needless_pass_by_value)]
+
+struct Foo<'a>(&'a [(); 100]);
+
+fn test(x: Foo<'_>) {}
+
+fn main() {}
diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr b/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr
new file mode 100644
index 00000000000..7a0a648974f
--- /dev/null
+++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr
@@ -0,0 +1,15 @@
+error: this argument is passed by value, but not consumed in the function body
+  --> $DIR/needless_pass_by_value-w-late-bound.rs:7:12
+   |
+LL | fn test(x: Foo<'_>) {}
+   |            ^^^^^^^ help: consider taking a reference instead: `&Foo<'_>`
+   |
+help: consider marking this type as `Copy`
+  --> $DIR/needless_pass_by_value-w-late-bound.rs:5:1
+   |
+LL | struct Foo<'a>(&'a [(); 100]);
+   | ^^^^^^^^^^^^^^
+   = note: `-D clippy::needless-pass-by-value` implied by `-D warnings`
+
+error: aborting due to previous error
+