Skip to content

Commit c9fc53f

Browse files
committed
Add documentation for unused-externs(-silent)
1 parent 2a544e3 commit c9fc53f

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
@@ -254,6 +254,36 @@ information, even if the diagnostics have been suppressed (such as with an
254254
}
255255
```
256256

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

0 commit comments

Comments
 (0)