2022-06-09 22:14:24 -05:00
|
|
|
error: struct `Foo` is never constructed
|
2020-04-06 05:00:42 -05:00
|
|
|
--> $DIR/lint-dead-code-3.rs:14:8
|
2018-08-08 07:28:26 -05:00
|
|
|
|
|
2019-03-09 06:03:44 -06:00
|
|
|
LL | struct Foo;
|
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 13:46:07 -05:00
|
|
|
| ^^^
|
2018-08-08 07:28:26 -05:00
|
|
|
|
|
2020-01-22 17:57:38 -06:00
|
|
|
note: the lint level is defined here
|
2020-04-06 05:00:42 -05:00
|
|
|
--> $DIR/lint-dead-code-3.rs:4:9
|
2018-08-08 07:28:26 -05:00
|
|
|
|
|
|
|
|
LL | #![deny(dead_code)]
|
|
|
|
| ^^^^^^^^^
|
|
|
|
|
2023-04-12 15:48:50 -05:00
|
|
|
error: method `foo` is never used
|
|
|
|
--> $DIR/lint-dead-code-3.rs:16:8
|
|
|
|
|
|
2023-04-13 05:42:47 -05:00
|
|
|
LL | impl Foo {
|
|
|
|
| -------- method in this implementation
|
2023-04-12 15:48:50 -05:00
|
|
|
LL | fn foo(&self) {
|
|
|
|
| ^^^
|
|
|
|
|
2022-06-09 22:14:24 -05:00
|
|
|
error: function `bar` is never used
|
2020-04-06 05:00:42 -05:00
|
|
|
--> $DIR/lint-dead-code-3.rs:21:4
|
2018-08-08 07:28:26 -05:00
|
|
|
|
|
2019-03-09 06:03:44 -06:00
|
|
|
LL | fn bar() {
|
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 13:46:07 -05:00
|
|
|
| ^^^
|
2018-08-08 07:28:26 -05:00
|
|
|
|
2022-06-09 22:14:24 -05:00
|
|
|
error: enum `c_void` is never used
|
2020-04-06 05:00:42 -05:00
|
|
|
--> $DIR/lint-dead-code-3.rs:60:6
|
2018-08-08 07:28:26 -05:00
|
|
|
|
|
2019-03-09 06:03:44 -06:00
|
|
|
LL | enum c_void {}
|
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 13:46:07 -05:00
|
|
|
| ^^^^^^
|
2018-08-08 07:28:26 -05:00
|
|
|
|
2022-06-19 11:52:06 -05:00
|
|
|
error: function `blah` is never used
|
|
|
|
--> $DIR/lint-dead-code-3.rs:77:8
|
|
|
|
|
|
|
|
|
LL | fn blah() {}
|
|
|
|
| ^^^^
|
|
|
|
|
|
|
|
error: function `blah` is never used
|
|
|
|
--> $DIR/lint-dead-code-3.rs:81:12
|
|
|
|
|
|
|
|
|
LL | fn blah() {}
|
|
|
|
| ^^^^
|
|
|
|
|
2022-06-09 22:14:24 -05:00
|
|
|
error: function `free` is never used
|
2022-06-22 13:33:59 -05:00
|
|
|
--> $DIR/lint-dead-code-3.rs:62:8
|
2018-08-08 07:28:26 -05:00
|
|
|
|
|
2019-03-09 06:03:44 -06:00
|
|
|
LL | fn free(p: *const c_void);
|
2022-06-22 13:33:59 -05:00
|
|
|
| ^^^^
|
2018-08-08 07:28:26 -05:00
|
|
|
|
2022-06-19 11:52:06 -05:00
|
|
|
error: aborting due to 7 previous errors
|
2018-08-08 07:28:26 -05:00
|
|
|
|