Use a better message for toplevel_ref_arg lint (#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 #14131

changelog: [`toplevel_ref_arg`]: use a clearer lint message
This commit is contained in:
Manish Goregaokar 2025-02-01 14:13:06 +00:00 committed by GitHub
commit 7e5cfbe373
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
TOPLEVEL_REF_ARG,
arg.hir_id,
arg.pat.span,
"`ref` directly on a function argument is ignored. \
"`ref` directly on a function parameter does not prevent taking ownership of the passed argument. \
Consider using a reference type instead",
);
}

View file

@ -1,4 +1,4 @@
error: `ref` directly on a function argument is ignored. Consider using a reference type instead
error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead
--> tests/ui/toplevel_ref_arg_non_rustfix.rs:9:15
|
LL | fn the_answer(ref mut x: u8) {
@ -7,7 +7,7 @@ LL | fn the_answer(ref mut x: u8) {
= note: `-D clippy::toplevel-ref-arg` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]`
error: `ref` directly on a function argument is ignored. Consider using a reference type instead
error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead
--> tests/ui/toplevel_ref_arg_non_rustfix.rs:20:24
|
LL | fn fun_example(ref _x: usize) {}