2017-05-13 09:54:50 +00:00
|
|
|
// run-pass
|
2020-07-02 05:32:12 +00:00
|
|
|
// run-rustfix
|
|
|
|
|
Use ident instead of def_span in dead-code pass
According to @estebank, def_span scans forward on the line until it finds a {,
and if it can't find one, fallse 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.
2019-10-25 18:46:07 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
#![warn(unused_parens)]
|
2017-07-27 04:51:09 +00:00
|
|
|
|
2016-11-14 17:35:37 +00:00
|
|
|
// Parser test for #37765
|
|
|
|
|
Use ident instead of def_span in dead-code pass
According to @estebank, def_span scans forward on the line until it finds a {,
and if it can't find one, fallse 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.
2019-10-25 18:46:07 +00:00
|
|
|
fn with_parens<T: ToString>(arg: T) -> String {
|
2020-07-02 05:32:12 +00:00
|
|
|
return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value
|
2016-11-14 17:35:37 +00:00
|
|
|
}
|
|
|
|
|
Use ident instead of def_span in dead-code pass
According to @estebank, def_span scans forward on the line until it finds a {,
and if it can't find one, fallse 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.
2019-10-25 18:46:07 +00:00
|
|
|
fn no_parens<T: ToString>(arg: T) -> String {
|
2020-07-02 05:32:12 +00:00
|
|
|
return <T as ToString>::to_string(&arg);
|
2016-11-14 17:35:37 +00:00
|
|
|
}
|
|
|
|
|
2020-07-02 05:32:12 +00:00
|
|
|
fn main() {}
|