Skip to content

Suggestion Span for non_upper_case_globals could be more precise #48103

Closed
@phansch

Description

@phansch

Playground link: https://play.rust-lang.org/?gist=054aaeb143021ea121fc0c091903697b&version=nightly

It currently prints:

warning: static variable `hello` should have an upper case name such as `HELLO`
 --> src/main.rs:3:1
  |
3 | static hello: &str = "Hello";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(non_upper_case_globals)] on by default

warning: constant `world` should have an upper case name such as `WORLD`
 --> src/main.rs:4:1
  |
4 | const world: &str = ", world!";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It would be nicer if it only underlines the variable name itself:

warning: static variable `hello` should have an upper case name such as `HELLO`
 --> src/main.rs:3:1
  |
3 | static hello: &str = "Hello";
  |        ^^^^^
  |
  = note: #[warn(non_upper_case_globals)] on by default

warning: constant `world` should have an upper case name such as `WORLD`
 --> src/main.rs:4:1
  |
4 | const world: &str = ", world!";
  |       ^^^^^

I have some basic lint writing experience through clippy, so I would like to give this a go.

Metadata

Metadata

Assignees

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