Skip to content

Commit

Permalink
Use a better message for toplevel_ref_arg lint
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samueltardieu committed Feb 1, 2025
1 parent d79f862 commit 4703aec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 argument requires ownership of the argument nonetheless. \
Consider using a reference type instead",
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/toplevel_ref_arg_non_rustfix.stderr
Original file line number Diff line number Diff line change
@@ -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 argument requires ownership of the argument nonetheless. Consider using a reference type instead
--> tests/ui/toplevel_ref_arg_non_rustfix.rs:9:15
|
LL | fn the_answer(ref mut x: u8) {
Expand All @@ -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 argument requires ownership of the argument nonetheless. Consider using a reference type instead
--> tests/ui/toplevel_ref_arg_non_rustfix.rs:20:24
|
LL | fn fun_example(ref _x: usize) {}
Expand Down

0 comments on commit 4703aec

Please sign in to comment.