Skip to content

Commit 8880b70

Browse files
committed
Add documentation for unused-externs(-silent)
1 parent fdcb8a9 commit 8880b70

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/doc/rustc/src/json.md

+30
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,36 @@ information, even if the diagnostics have been suppressed (such as with an
262262
}
263263
```
264264

265+
## Unused Dependency Notifications
266+
267+
The options `--json=unused-externs` and `--json=unused-externs-silent` in
268+
conjunction with the `unused-crate-dependencies` lint will emit JSON structures
269+
reporting any crate dependencies (specified with `--extern`) which never had any
270+
symbols referenced. These are intended to be consumed by the build system which
271+
can then emit diagnostics telling the user to remove the unused dependencies
272+
from `Cargo.toml` (or whatever build-system file defines dependencies).
273+
274+
The JSON structure is:
275+
```json
276+
{
277+
"lint_level": "deny", /* Level of the warning */
278+
"unused_names": [
279+
"foo" /* Names of unused crates, as specified with --extern foo=libfoo.rlib */
280+
],
281+
}
282+
```
283+
284+
The warn/deny/forbid lint level (as defined either on the command line or in the
285+
source) dictates the `lint_level` in the JSON. With `unused-externs`, a
286+
`deny` or `forbid` level diagnostic will also cause `rustc` to exit with a
287+
failure exit code.
288+
289+
`unused-externs-silent` will report the diagnostic the same way, but will not
290+
cause `rustc` to exit with failure - it's up to the consumer to flag failure
291+
appropriately. (This is needed by Cargo which shares the same dependencies
292+
across multiple build targets, so it should only report an unused dependency if
293+
its not used by any of the targets.)
294+
265295
[option-emit]: command-line-arguments.md#option-emit
266296
[option-error-format]: command-line-arguments.md#option-error-format
267297
[option-json]: command-line-arguments.md#option-json

0 commit comments

Comments
 (0)