Skip to content

Commit 6d144ac

Browse files
committed
Add attribute documentation
1 parent c0512ba commit 6d144ac

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

book/src/SUMMARY.md

+1
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

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#[macro_export]
14+
#[clippy::format_args]
15+
macro_rules! print_if {
16+
($condition:expr, $($args:tt)+) => {{
17+
if $condition {
18+
println!($($args)+)
19+
}
20+
}};
21+
}
22+
```

0 commit comments

Comments
 (0)