Skip to content

Commit

Permalink
buck2/rust: turn unused-dependencies errors into actual errors
Browse files Browse the repository at this point in the history
Summary:
For Reasons, `rustc` does not exit with an error status for unused
dependency errors (rust-lang/rust#96068).

We can promote them to proper errors in the rustc_action script.
Also improve how the diagnostics are rendered to make them a bit more
readable.

Reviewed By: dtolnay

Differential Revision: D35690034

fbshipit-source-id: a2571f9d6682a83527bfca9ce73dc474162a6f9c
  • Loading branch information
jsgf authored and facebook-github-bot committed Apr 21, 2022
1 parent 09308e9 commit 4b71088
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion prelude/rust/tools/rustc_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,26 @@ async def handle_output(proc, args, crate_map):

# Add more information to unused crate warnings
if diag.get("unused_extern_names", []) != []:
# Treat error-level unused dep warnings as errors
if diag.get("lint_level") in ("deny", "forbid"):
got_error_diag = True

unused_names = diag["unused_extern_names"]

if args.buck_target:
rendered_unused = []
for name in unused_names:
if name in crate_map:
rendered_unused.append("{}: {}".format(crate_map[name], name))
else:
rendered_unused.append("{}".format(name))
rendered_unused.sort()
rendered_unused = "\n ".join(rendered_unused)

diag["buck_target"] = args.buck_target
diag[
"rendered"
] = f"Target `{args.buck_target}` has unused dependencies: {','.join(unused_names)}"
] = f"Target `{args.buck_target}` has unused dependencies:\n {rendered_unused}"
diag["unused_deps"] = {
name: crate_map[name] for name in unused_names if name in crate_map
}
Expand Down Expand Up @@ -160,6 +173,10 @@ async def main():
f"res={repr(res)} got_error_diag={got_error_diag} args.failure_filter {args.failure_filter}"
)

# If rustc is reporting a silent error, make it loud
if res == 0 and got_error_diag:
res = 1

# Check for death by signal - this is always considered a failure
if res < 0:
cmdline = " ".join(shlex.quote(arg) for arg in args.rustc)
Expand Down

0 comments on commit 4b71088

Please sign in to comment.