-
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.
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Modifying Clippy behavior with attributes | ||
|
||
In some cases it is possible extend Clippy coverage to include 3rd party libraries. At this moment, only one such modification is possible: adding a `#[clippy::format_args]` attribute to a macro that supports `format!`-like syntax. | ||
|
||
## `#[clippy::format_args]` | ||
|
||
This attribute can be added to a macro that supports `format!`-like syntax. It tells Clippy that the macro is a formatting macro, and that the arguments to the macro should be linted as if they were arguments to `format!`. Any lint that would apply to a `format!` call will also apply to the macro call. The macro may have additional arguments before the format string, and these will be ignored. | ||
|
||
### Example | ||
|
||
```rust | ||
/// A macro that prints a message if a condition is true | ||
#[macro_export] | ||
#[clippy::format_args] | ||
macro_rules! print_if { | ||
($condition:expr, $($args:tt)+) => {{ | ||
if $condition { | ||
println!($($args)+) | ||
} | ||
}}; | ||
} | ||
``` |