Skip to content

Commit 7e5cfbe

Browse files
authored
Use a better message for toplevel_ref_arg lint (rust-lang#14132)
A `ref` pattern applied to an argument is not ignored. It creates a reference as expected, but still requires the function to take ownership of the argument given to it. Fix rust-lang#14131 changelog: [`toplevel_ref_arg`]: use a clearer lint message
2 parents d79f862 + 7848488 commit 7e5cfbe

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

clippy_lints/src/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
169169
TOPLEVEL_REF_ARG,
170170
arg.hir_id,
171171
arg.pat.span,
172-
"`ref` directly on a function argument is ignored. \
172+
"`ref` directly on a function parameter does not prevent taking ownership of the passed argument. \
173173
Consider using a reference type instead",
174174
);
175175
}

tests/ui/toplevel_ref_arg_non_rustfix.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `ref` directly on a function argument is ignored. Consider using a reference type instead
1+
error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead
22
--> tests/ui/toplevel_ref_arg_non_rustfix.rs:9:15
33
|
44
LL | fn the_answer(ref mut x: u8) {
@@ -7,7 +7,7 @@ LL | fn the_answer(ref mut x: u8) {
77
= note: `-D clippy::toplevel-ref-arg` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]`
99

10-
error: `ref` directly on a function argument is ignored. Consider using a reference type instead
10+
error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead
1111
--> tests/ui/toplevel_ref_arg_non_rustfix.rs:20:24
1212
|
1313
LL | fn fun_example(ref _x: usize) {}

0 commit comments

Comments
 (0)