]> git.lizzy.rs Git - rust.git/commit
Auto merge of #65830 - Quantumplation:master, r=davidtwco,estebank
authorbors <bors@rust-lang.org>
Wed, 6 Nov 2019 09:35:27 +0000 (09:35 +0000)
committerbors <bors@rust-lang.org>
Wed, 6 Nov 2019 09:35:27 +0000 (09:35 +0000)
commit61a551b4939ec1d5596e585351038b8fbd0124ba
tree9da5e45a058cd0995ea5a35e30dc4d34fa5ea956
parente8b190ac4ad79e58d21ee1d573529ff74d8eedaa
parent6186edeae52a95952e7da16a1f66d7352287427e
Auto merge of #65830 - Quantumplation:master, r=davidtwco,estebank

Use ident.span instead of def_span in dead-code pass

Hello! First time contributor! :)

This should fix #58729.

According to @estebank in the duplicate #63064, def_span scans forward on the line until it finds a {,
and if it can't find one, falls back to the span for the whole item. This
was apparently written before the identifier span was explicitly tracked on
each node.

This means that if an unused function signature spans multiple lines, the
entire function (potentially hundreds of lines) gets flagged as dead code.
This could, for example, cause IDEs to add error squiggly's to the whole
function.

By using the span from the ident instead, we narrow the scope of this in
most cases. In a wider sense, it's probably safe to use ident.span
instead of def_span in most locations throughout the whole code base,
but since this is my first contribution, I kept it small.

Some interesting points that came up while I was working on this:
- I reorganized the tests a bit to bring some of the dead code ones all
into the same location
- A few tests were for things unrelated to dead code (like the
path-lookahead for parens), so I added #![allow(dead_code)] and
cleaned up the stderr file to reduce noise in the future
- The same fix doesn't apply to const and static declarations. I tried
adding these cases to the match expression, but that created a much
wider change to tests and error messages, so I left it off until I
could get some code review to validate the approach.