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