Skip to content

Spans for unused declarations don't need to be whole declaration #33961

Closed
@sophiajt

Description

@sophiajt

Currently, the spans for unused declarations, like enums and fns, span the whole declaration. Instead of spanning the whole declaration, we now put a single ^ at the beginning to say "it starts here".

But, if you compare unused enums/fns with unused variables an imports, it feels like one is pointing at the beginning and one is pointing at the name:

warning: enum is never used: `R0`, #[warn(dead_code)] on by default
  --> src/main.rs:10:1
   |>
10 |> enum R0 {
   |> ^

warning: function is never used: `bob`, #[warn(dead_code)] on by default
  --> src/main.rs:14:1
   |>
14 |> fn bob() {
   |> ^

warning: unused variable: `program`, #[warn(unused_variables)] on by default
  --> src/main.rs:24:9
   |>
24 |>     let program = Add (box Read, box Neg(box Int(8)));
   |>         ^^^^^^^

warning: unused import, #[warn(unused_imports)] on by default
  --> src/main.rs:19:9
   |>
19 |>     use R0::*;
   |>         ^^^^^^

Shouldn't we instead just underline the name in all cases (assuming there is one)?

Giving us:

warning: enum is never used: `R0`, #[warn(dead_code)] on by default
  --> src/main.rs:10:1
   |>
10 |> enum R0 {
   |>      ^^

warning: function is never used: `bob`, #[warn(dead_code)] on by default
  --> src/main.rs:14:1
   |>
14 |> fn bob() {
   |>    ^^^

warning: unused variable: `program`, #[warn(unused_variables)] on by default
  --> src/main.rs:24:9
   |>
24 |>     let program = Add (box Read, box Neg(box Int(8)));
   |>         ^^^^^^^

warning: unused import, #[warn(unused_imports)] on by default
  --> src/main.rs:19:9
   |>
19 |>     use R0::*;
   |>         ^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions