Skip to content

Commit 92e426e

Browse files
committed
Add attribute documentation
1 parent c0512ba commit 92e426e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [Installation](installation.md)
66
- [Usage](usage.md)
7+
- [Extending Clippy coverage](lib_usage.md)
78
- [Configuration](configuration.md)
89
- [Lint Configuration](lint_configuration.md)
910
- [Clippy's Lints](lints.md)

book/src/lib_usage.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Modifying Clippy behavior with attributes
2+
3+
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.
4+
5+
## `#[clippy::format_args]`
6+
7+
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.
8+
9+
### Example
10+
11+
```rust
12+
/// A macro that prints a message if a condition is true
13+
#[clipy::format_args]
14+
macro_rules! print_if {
15+
($condition:expr, $($args:tt)+) => {{
16+
if $condition {
17+
println!($($args)+)
18+
}
19+
}};
20+
}
21+
```

0 commit comments

Comments
 (0)