Skip to content

Commit

Permalink
Add attribute documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Oct 21, 2024
1 parent c0512ba commit 6d144ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [Installation](installation.md)
- [Usage](usage.md)
- [Extending Clippy coverage](lib_usage.md)
- [Configuration](configuration.md)
- [Lint Configuration](lint_configuration.md)
- [Clippy's Lints](lints.md)
Expand Down
22 changes: 22 additions & 0 deletions book/src/lib_usage.md
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)+)
}
}};
}
```

0 comments on commit 6d144ac

Please sign in to comment.