-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No lint in external macro for
toplevel_ref_arg
- Loading branch information
Showing
7 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead | ||
--> $DIR/toplevel_ref_arg.rs:10:9 | ||
--> $DIR/toplevel_ref_arg.rs:20:9 | ||
| | ||
LL | let ref _x = 1; | ||
| ----^^^^^^----- help: try: `let _x = &1;` | ||
| | ||
= note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` | ||
|
||
error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead | ||
--> $DIR/toplevel_ref_arg.rs:12:9 | ||
--> $DIR/toplevel_ref_arg.rs:22:9 | ||
| | ||
LL | let ref _y: (&_, u8) = (&1, 2); | ||
| ----^^^^^^--------------------- help: try: `let _y: &(&_, u8) = &(&1, 2);` | ||
|
||
error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead | ||
--> $DIR/toplevel_ref_arg.rs:14:9 | ||
--> $DIR/toplevel_ref_arg.rs:24:9 | ||
| | ||
LL | let ref _z = 1 + 2; | ||
| ----^^^^^^--------- help: try: `let _z = &(1 + 2);` | ||
|
||
error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead | ||
--> $DIR/toplevel_ref_arg.rs:16:9 | ||
--> $DIR/toplevel_ref_arg.rs:26:9 | ||
| | ||
LL | let ref mut _z = 1 + 2; | ||
| ----^^^^^^^^^^--------- help: try: `let _z = &mut (1 + 2);` | ||
|
||
error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead | ||
--> $DIR/toplevel_ref_arg.rs:21:9 | ||
--> $DIR/toplevel_ref_arg.rs:31:9 | ||
| | ||
LL | let ref _x = vec![1, 2, 3]; | ||
| ----^^^^^^----------------- help: try: `let _x = &vec![1, 2, 3];` | ||
|
||
error: aborting due to 5 previous errors | ||
error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead | ||
--> $DIR/toplevel_ref_arg.rs:11:13 | ||
| | ||
LL | let ref _y = 42; | ||
| ----^^^^^^------ help: try: `let _y = &42;` | ||
... | ||
LL | gen_binding!(); | ||
| --------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 6 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
// aux-build:macro_rules.rs | ||
|
||
#![warn(clippy::toplevel_ref_arg)] | ||
#![allow(unused)] | ||
|
||
#[macro_use] | ||
extern crate macro_rules; | ||
|
||
fn the_answer(ref mut x: u8) { | ||
*x = 42; | ||
} | ||
|
||
macro_rules! gen_function { | ||
() => { | ||
fn fun_example(ref _x: usize) {} | ||
}; | ||
} | ||
|
||
fn main() { | ||
let mut x = 0; | ||
the_answer(x); | ||
|
||
// lint in macro | ||
#[allow(unused)] | ||
{ | ||
gen_function!(); | ||
} | ||
|
||
// do not lint in external macro | ||
{ | ||
ref_arg_function!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
error: `ref` directly on a function argument is ignored. Consider using a reference type instead. | ||
--> $DIR/toplevel_ref_arg_non_rustfix.rs:4:15 | ||
--> $DIR/toplevel_ref_arg_non_rustfix.rs:9:15 | ||
| | ||
LL | fn the_answer(ref mut x: u8) { | ||
| ^^^^^^^^^ | ||
| | ||
= note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
error: `ref` directly on a function argument is ignored. Consider using a reference type instead. | ||
--> $DIR/toplevel_ref_arg_non_rustfix.rs:15:24 | ||
| | ||
LL | fn fun_example(ref _x: usize) {} | ||
| ^^^^^^ | ||
... | ||
LL | gen_function!(); | ||
| ---------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|