about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_lint/src/pass_by_value.rs14
-rw-r--r--src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs8
-rw-r--r--src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr18
3 files changed, 25 insertions, 15 deletions
diff --git a/compiler/rustc_lint/src/pass_by_value.rs b/compiler/rustc_lint/src/pass_by_value.rs
index 3435a5a6c82..26d0560bf89 100644
--- a/compiler/rustc_lint/src/pass_by_value.rs
+++ b/compiler/rustc_lint/src/pass_by_value.rs
@@ -73,19 +73,15 @@ fn gen_args(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> String {
         let params = args
             .args
             .iter()
-            .filter_map(|arg| match arg {
-                GenericArg::Lifetime(lt) => Some(lt.name.ident().to_string()),
+            .map(|arg| match arg {
+                GenericArg::Lifetime(lt) => lt.name.ident().to_string(),
                 GenericArg::Type(ty) => {
-                    let snippet =
-                        cx.tcx.sess.source_map().span_to_snippet(ty.span).unwrap_or_default();
-                    Some(snippet)
+                    cx.tcx.sess.source_map().span_to_snippet(ty.span).unwrap_or_default()
                 }
                 GenericArg::Const(c) => {
-                    let snippet =
-                        cx.tcx.sess.source_map().span_to_snippet(c.span).unwrap_or_default();
-                    Some(snippet)
+                    cx.tcx.sess.source_map().span_to_snippet(c.span).unwrap_or_default()
                 }
-                _ => None,
+                GenericArg::Infer(_) => String::from("_"),
             })
             .collect::<Vec<_>>();
 
diff --git a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs
index f8ab0f056d7..402c41f3766 100644
--- a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs
+++ b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs
@@ -105,11 +105,13 @@ struct WithParameters<T, const N: usize, M = u32> {
 }
 
 impl<T> WithParameters<T, 1> {
-    fn test(
+    fn test<'a>(
         value: WithParameters<T, 1>,
-        reference: &WithParameters<T, 1>, //~ ERROR passing `WithParameters<T, 1>` by reference
+        reference: &'a WithParameters<T, 1>, //~ ERROR passing `WithParameters<T, 1>` by reference
         reference_with_m: &WithParameters<T, 1, u32>, //~ ERROR passing `WithParameters<T, 1, u32>` by reference
-    ) {
+    ) -> &'a WithParameters<T, 1> {
+        //~^ ERROR passing `WithParameters<T, 1>` by reference
+        reference as &WithParameters<_, 1> //~ ERROR passing `WithParameters<_, 1>` by reference
     }
 }
 
diff --git a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr
index c5307f0f67d..7f6e57b38f3 100644
--- a/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr
+++ b/src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.stderr
@@ -103,8 +103,8 @@ LL |         reference: &CustomAlias,
 error: passing `WithParameters<T, 1>` by reference
   --> $DIR/rustc_pass_by_value.rs:110:20
    |
-LL |         reference: &WithParameters<T, 1>,
-   |                    ^^^^^^^^^^^^^^^^^^^^^ help: try passing by value: `WithParameters<T, 1>`
+LL |         reference: &'a WithParameters<T, 1>,
+   |                    ^^^^^^^^^^^^^^^^^^^^^^^^ help: try passing by value: `WithParameters<T, 1>`
 
 error: passing `WithParameters<T, 1, u32>` by reference
   --> $DIR/rustc_pass_by_value.rs:111:27
@@ -112,5 +112,17 @@ error: passing `WithParameters<T, 1, u32>` by reference
 LL |         reference_with_m: &WithParameters<T, 1, u32>,
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try passing by value: `WithParameters<T, 1, u32>`
 
-error: aborting due to 18 previous errors
+error: passing `WithParameters<T, 1>` by reference
+  --> $DIR/rustc_pass_by_value.rs:112:10
+   |
+LL |     ) -> &'a WithParameters<T, 1> {
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^ help: try passing by value: `WithParameters<T, 1>`
+
+error: passing `WithParameters<_, 1>` by reference
+  --> $DIR/rustc_pass_by_value.rs:114:22
+   |
+LL |         reference as &WithParameters<_, 1>
+   |                      ^^^^^^^^^^^^^^^^^^^^^ help: try passing by value: `WithParameters<_, 1>`
+
+error: aborting due to 20 previous errors