improve non_snake_case diagnostics

Use a structured suggestion and tighten the span to just the identifier.
This commit is contained in:
Andy Russell 2019-01-04 10:19:52 -05:00
parent 3dfe36d094
commit 7c0d145ec1
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
25 changed files with 191 additions and 179 deletions

View file

@ -1,8 +1,8 @@
error: function `BOGUS` should have a snake case name such as `bogus`
--> $DIR/enable-unstable-lib-feature.rs:12:1
error: function `BOGUS` should have a snake case name
--> $DIR/enable-unstable-lib-feature.rs:12:8
|
LL | pub fn BOGUS() { } //~ ERROR
| ^^^^^^^^^^^^^^^^^^
| ^^^^^ help: convert the identifier to snake case: `bogus`
|
note: lint level defined here
--> $DIR/enable-unstable-lib-feature.rs:6:9

View file

@ -1,8 +1,8 @@
error: variable `X` should have a snake case name such as `x`
error: variable `X` should have a snake case name
--> $DIR/expr_attr_paren_order.rs:19:17
|
LL | let X = 0; //~ ERROR snake case name
| ^
| ^ help: convert the identifier to snake case: `x`
|
note: lint level defined here
--> $DIR/expr_attr_paren_order.rs:17:17

View file

@ -1,8 +1,8 @@
error: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing`
error: variable `_InappropriateCamelCasing` should have a snake case name
--> $DIR/command-line-lint-group-deny.rs:4:9
|
LL | let _InappropriateCamelCasing = true; //~ ERROR should have a snake
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
|
= note: `-D non-snake-case` implied by `-D bad-style`

View file

@ -1,8 +1,8 @@
error: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing`
error: variable `_InappropriateCamelCasing` should have a snake case name
--> $DIR/command-line-lint-group-forbid.rs:4:9
|
LL | let _InappropriateCamelCasing = true; //~ ERROR should have a snake
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
|
= note: `-F non-snake-case` implied by `-F bad-style`

View file

@ -1,8 +1,8 @@
warning: variable `_InappropriateCamelCasing` should have a snake case name such as `_inappropriate_camel_casing`
warning: variable `_InappropriateCamelCasing` should have a snake case name
--> $DIR/command-line-lint-group-warn.rs:5:9
|
LL | let _InappropriateCamelCasing = true;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
|
= note: `-W non-snake-case` implied by `-W bad-style`

View file

@ -11,11 +11,11 @@ LL | #![warn(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[warn(non_camel_case_types)] implied by #[warn(nonstandard_style)]
error: function `CamelCase` should have a snake case name such as `camel_case`
--> $DIR/lint-group-nonstandard-style.rs:4:1
error: function `CamelCase` should have a snake case name
--> $DIR/lint-group-nonstandard-style.rs:4:4
|
LL | fn CamelCase() {} //~ ERROR should have a snake
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^ help: convert the identifier to snake case: `camel_case`
|
note: lint level defined here
--> $DIR/lint-group-nonstandard-style.rs:1:9
@ -24,11 +24,11 @@ LL | #![deny(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[deny(non_snake_case)] implied by #[deny(nonstandard_style)]
error: function `CamelCase` should have a snake case name such as `camel_case`
--> $DIR/lint-group-nonstandard-style.rs:12:9
error: function `CamelCase` should have a snake case name
--> $DIR/lint-group-nonstandard-style.rs:12:12
|
LL | fn CamelCase() {} //~ ERROR should have a snake
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^ help: convert the identifier to snake case: `camel_case`
|
note: lint level defined here
--> $DIR/lint-group-nonstandard-style.rs:10:14
@ -50,11 +50,11 @@ LL | #[forbid(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[forbid(non_upper_case_globals)] implied by #[forbid(nonstandard_style)]
warning: function `CamelCase` should have a snake case name such as `camel_case`
--> $DIR/lint-group-nonstandard-style.rs:20:9
warning: function `CamelCase` should have a snake case name
--> $DIR/lint-group-nonstandard-style.rs:20:12
|
LL | fn CamelCase() {} //~ WARN should have a snake
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^ help: convert the identifier to snake case: `camel_case`
|
note: lint level defined here
--> $DIR/lint-group-nonstandard-style.rs:18:17

View file

@ -1,5 +1,5 @@
// compile-flags: --crate-name NonSnakeCase
// error-pattern: crate `NonSnakeCase` should have a snake case name such as `non_snake_case`
// error-pattern: crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]

View file

@ -1,10 +1,11 @@
error: crate `NonSnakeCase` should have a snake case name such as `non_snake_case`
error: crate `NonSnakeCase` should have a snake case name
|
note: lint level defined here
--> $DIR/lint-non-snake-case-crate-2.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
= help: convert the identifier to snake case: `non_snake_case`
error: aborting due to previous error

View file

@ -1,5 +1,5 @@
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name such as `non_snake_case`
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]
fn main() {}

View file

@ -1,8 +1,8 @@
error: crate `NonSnakeCase` should have a snake case name such as `non_snake_case`
--> $DIR/lint-non-snake-case-crate.rs:1:1
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate.rs:1:18
|
LL | #![crate_name = "NonSnakeCase"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
|
note: lint level defined here
--> $DIR/lint-non-snake-case-crate.rs:3:9

View file

@ -5,28 +5,28 @@ struct Foo;
impl Foo {
fn Foo_Method() {}
//~^ ERROR method `Foo_Method` should have a snake case name such as `foo_method`
//~^ ERROR method `Foo_Method` should have a snake case name
// Don't allow two underscores in a row
fn foo__method(&self) {}
//~^ ERROR method `foo__method` should have a snake case name such as `foo_method`
//~^ ERROR method `foo__method` should have a snake case name
pub fn xyZ(&mut self) {}
//~^ ERROR method `xyZ` should have a snake case name such as `xy_z`
//~^ ERROR method `xyZ` should have a snake case name
fn render_HTML() {}
//~^ ERROR method `render_HTML` should have a snake case name such as `render_html`
//~^ ERROR method `render_HTML` should have a snake case name
}
trait X {
fn ABC();
//~^ ERROR trait method `ABC` should have a snake case name such as `abc`
//~^ ERROR trait method `ABC` should have a snake case name
fn a_b_C(&self) {}
//~^ ERROR trait method `a_b_C` should have a snake case name such as `a_b_c`
//~^ ERROR trait method `a_b_C` should have a snake case name
fn something__else(&mut self);
//~^ ERROR trait method `something__else` should have a snake case name such as `something_else`
//~^ ERROR trait method `something__else` should have a snake case name
}
impl X for Foo {
@ -36,9 +36,9 @@ impl X for Foo {
}
fn Cookie() {}
//~^ ERROR function `Cookie` should have a snake case name such as `cookie`
//~^ ERROR function `Cookie` should have a snake case name
pub fn bi_S_Cuit() {}
//~^ ERROR function `bi_S_Cuit` should have a snake case name such as `bi_s_cuit`
//~^ ERROR function `bi_S_Cuit` should have a snake case name
fn main() { }

View file

@ -1,8 +1,8 @@
error: method `Foo_Method` should have a snake case name such as `foo_method`
--> $DIR/lint-non-snake-case-functions.rs:7:5
error: method `Foo_Method` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:7:8
|
LL | fn Foo_Method() {}
| ^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^ help: convert the identifier to snake case: `foo_method`
|
note: lint level defined here
--> $DIR/lint-non-snake-case-functions.rs:1:9
@ -10,53 +10,53 @@ note: lint level defined here
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: method `foo__method` should have a snake case name such as `foo_method`
--> $DIR/lint-non-snake-case-functions.rs:11:5
error: method `foo__method` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:11:8
|
LL | fn foo__method(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^ help: convert the identifier to snake case: `foo_method`
error: method `xyZ` should have a snake case name such as `xy_z`
--> $DIR/lint-non-snake-case-functions.rs:14:5
error: method `xyZ` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:14:12
|
LL | pub fn xyZ(&mut self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^ help: convert the identifier to snake case: `xy_z`
error: method `render_HTML` should have a snake case name such as `render_html`
--> $DIR/lint-non-snake-case-functions.rs:17:5
error: method `render_HTML` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:17:8
|
LL | fn render_HTML() {}
| ^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^ help: convert the identifier to snake case: `render_html`
error: trait method `ABC` should have a snake case name such as `abc`
--> $DIR/lint-non-snake-case-functions.rs:22:5
error: trait method `ABC` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:22:8
|
LL | fn ABC();
| ^^^^^^^^^
| ^^^ help: convert the identifier to snake case: `abc`
error: trait method `a_b_C` should have a snake case name such as `a_b_c`
--> $DIR/lint-non-snake-case-functions.rs:25:5
error: trait method `a_b_C` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:25:8
|
LL | fn a_b_C(&self) {}
| ^^^^^^^^^^^^^^^^^^
| ^^^^^ help: convert the identifier to snake case: `a_b_c`
error: trait method `something__else` should have a snake case name such as `something_else`
--> $DIR/lint-non-snake-case-functions.rs:28:5
error: trait method `something__else` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:28:8
|
LL | fn something__else(&mut self);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `something_else`
error: function `Cookie` should have a snake case name such as `cookie`
--> $DIR/lint-non-snake-case-functions.rs:38:1
error: function `Cookie` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:38:4
|
LL | fn Cookie() {}
| ^^^^^^^^^^^^^^
| ^^^^^^ help: convert the identifier to snake case: `cookie`
error: function `bi_S_Cuit` should have a snake case name such as `bi_s_cuit`
--> $DIR/lint-non-snake-case-functions.rs:41:1
error: function `bi_S_Cuit` should have a snake case name
--> $DIR/lint-non-snake-case-functions.rs:41:8
|
LL | pub fn bi_S_Cuit() {}
| ^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^ help: convert the identifier to snake case: `bi_s_cuit`
error: aborting due to 9 previous errors

View file

@ -1,7 +1,7 @@
#![deny(non_snake_case)]
#![allow(dead_code)]
fn f<'FooBar>( //~ ERROR lifetime `'FooBar` should have a snake case name such as `'foo_bar`
fn f<'FooBar>( //~ ERROR lifetime `'FooBar` should have a snake case name
_: &'FooBar ()
) {}

View file

@ -1,8 +1,8 @@
error: lifetime `'FooBar` should have a snake case name such as `'foo_bar`
error: lifetime `'FooBar` should have a snake case name
--> $DIR/lint-non-snake-case-lifetimes.rs:4:6
|
LL | fn f<'FooBar>( //~ ERROR lifetime `'FooBar` should have a snake case name such as `'foo_bar`
| ^^^^^^^
LL | fn f<'FooBar>( //~ ERROR lifetime `'FooBar` should have a snake case name
| ^^^^^^^ help: convert the identifier to snake case: `'foo_bar`
|
note: lint level defined here
--> $DIR/lint-non-snake-case-lifetimes.rs:1:9

View file

@ -1,7 +1,7 @@
#![deny(non_snake_case)]
#![allow(dead_code)]
mod FooBar { //~ ERROR module `FooBar` should have a snake case name such as `foo_bar`
mod FooBar { //~ ERROR module `FooBar` should have a snake case name
pub struct S;
}

View file

@ -1,10 +1,8 @@
error: module `FooBar` should have a snake case name such as `foo_bar`
--> $DIR/lint-non-snake-case-modules.rs:4:1
error: module `FooBar` should have a snake case name
--> $DIR/lint-non-snake-case-modules.rs:4:5
|
LL | / mod FooBar { //~ ERROR module `FooBar` should have a snake case name such as `foo_bar`
LL | | pub struct S;
LL | | }
| |_^
LL | mod FooBar { //~ ERROR module `FooBar` should have a snake case name
| ^^^^^^ help: convert the identifier to snake case: `foo_bar`
|
note: lint level defined here
--> $DIR/lint-non-snake-case-modules.rs:1:9

View file

@ -0,0 +1,12 @@
// compile-pass
#![allow(dead_code)]
// pretty-expanded FIXME #23616
#![feature(non_ascii_idents)]
#![deny(non_snake_case)]
// This name is neither upper nor lower case
fn () {}
fn main() {}

View file

@ -7,20 +7,20 @@ mod foo {
}
struct Something {
X: usize //~ ERROR structure field `X` should have a snake case name such as `x`
X: usize //~ ERROR structure field `X` should have a snake case name
}
fn test(Xx: usize) { //~ ERROR variable `Xx` should have a snake case name such as `xx`
fn test(Xx: usize) { //~ ERROR variable `Xx` should have a snake case name
println!("{}", Xx);
}
fn main() {
let Test: usize = 0; //~ ERROR variable `Test` should have a snake case name such as `test`
let Test: usize = 0; //~ ERROR variable `Test` should have a snake case name
println!("{}", Test);
match foo::Foo::Foo {
Foo => {}
//~^ ERROR variable `Foo` should have a snake case name such as `foo`
//~^ ERROR variable `Foo` should have a snake case name
//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo`
//~^^^ WARN unused variable: `Foo`
}

View file

@ -17,11 +17,11 @@ LL | #![warn(unused)]
| ^^^^^^
= note: #[warn(unused_variables)] implied by #[warn(unused)]
error: structure field `X` should have a snake case name such as `x`
error: structure field `X` should have a snake case name
--> $DIR/lint-uppercase-variables.rs:10:5
|
LL | X: usize //~ ERROR structure field `X` should have a snake case name such as `x`
| ^^^^^^^^
LL | X: usize //~ ERROR structure field `X` should have a snake case name
| ^ help: convert the identifier to snake case: `x`
|
note: lint level defined here
--> $DIR/lint-uppercase-variables.rs:3:9
@ -29,23 +29,23 @@ note: lint level defined here
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: variable `Xx` should have a snake case name such as `xx`
error: variable `Xx` should have a snake case name
--> $DIR/lint-uppercase-variables.rs:13:9
|
LL | fn test(Xx: usize) { //~ ERROR variable `Xx` should have a snake case name such as `xx`
| ^^
LL | fn test(Xx: usize) { //~ ERROR variable `Xx` should have a snake case name
| ^^ help: convert the identifier to snake case: `xx`
error: variable `Test` should have a snake case name such as `test`
error: variable `Test` should have a snake case name
--> $DIR/lint-uppercase-variables.rs:18:9
|
LL | let Test: usize = 0; //~ ERROR variable `Test` should have a snake case name such as `test`
| ^^^^
LL | let Test: usize = 0; //~ ERROR variable `Test` should have a snake case name
| ^^^^ help: convert the identifier to snake case: `test`
error: variable `Foo` should have a snake case name such as `foo`
error: variable `Foo` should have a snake case name
--> $DIR/lint-uppercase-variables.rs:22:9
|
LL | Foo => {}
| ^^^
| ^^^ help: convert the identifier to snake case: `foo`
error: aborting due to 4 previous errors

View file

@ -11,11 +11,11 @@ note: lint level defined here
LL | #![warn(elided_lifetimes_in_paths,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
warning: variable `Social_exchange_psychology` should have a snake case name such as `social_exchange_psychology`
warning: variable `Social_exchange_psychology` should have a snake case name
--> $DIR/reasons.rs:30:9
|
LL | let Social_exchange_psychology = CheaterDetectionMechanism {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `social_exchange_psychology`
|
= note: people shouldn't have to change their usual style habits
to contribute to our project

View file

@ -10,6 +10,7 @@
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
struct S;

View file

@ -1,26 +0,0 @@
warning: function `want_F` should have a snake case name such as `want_f`
--> $DIR/regions-fn-subtyping-return-static.rs:18:1
|
LL | fn want_F(f: F) { }
| ^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(non_snake_case)] on by default
warning: function `want_G` should have a snake case name such as `want_g`
--> $DIR/regions-fn-subtyping-return-static.rs:22:1
|
LL | fn want_G(f: G) { }
| ^^^^^^^^^^^^^^^^^^^
warning: function `supply_F` should have a snake case name such as `supply_f`
--> $DIR/regions-fn-subtyping-return-static.rs:39:1
|
LL | / fn supply_F() {
LL | | want_F(foo);
LL | |
LL | | want_F(bar);
LL | |
LL | | want_F(baz);
LL | | }
| |_^

View file

@ -11,17 +11,17 @@ LL | #![warn(unused)]
| ^^^^^^
= note: #[warn(unused_variables)] implied by #[warn(unused)]
warning: variable `theTwo` should have a snake case name such as `the_two`
warning: variable `theTwo` should have a snake case name
--> $DIR/issue-24690.rs:12:9
|
LL | let theTwo = 2; //~ WARN should have a snake case name
| ^^^^^^
| ^^^^^^ help: convert the identifier to snake case: `the_two`
|
= note: #[warn(non_snake_case)] on by default
warning: variable `theOtherTwo` should have a snake case name such as `the_other_two`
warning: variable `theOtherTwo` should have a snake case name
--> $DIR/issue-24690.rs:13:9
|
LL | let theOtherTwo = 2; //~ WARN should have a snake case name
| ^^^^^^^^^^^
| ^^^^^^^^^^^ help: convert the identifier to snake case: `the_other_two`