diff options
| author | Andy Russell <arussell123@gmail.com> | 2019-01-04 10:19:52 -0500 |
|---|---|---|
| committer | Andy Russell <arussell123@gmail.com> | 2019-01-08 13:24:38 -0500 |
| commit | 7c0d145ec1603fd7d4de2ef38a70baeffbedaad2 (patch) | |
| tree | 00d0ad68dd743ac633d76021057103eba75ffcdb /src | |
| parent | 3dfe36d09436317e035ee3caa19c7e1d260053e1 (diff) | |
| download | rust-7c0d145ec1603fd7d4de2ef38a70baeffbedaad2.tar.gz rust-7c0d145ec1603fd7d4de2ef38a70baeffbedaad2.zip | |
improve non_snake_case diagnostics
Use a structured suggestion and tighten the span to just the identifier.
Diffstat (limited to 'src')
25 files changed, 191 insertions, 179 deletions
diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 2694a04b94c..fa6665d1ae7 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -7,7 +7,8 @@ use lint::{EarlyContext, LateContext, LintContext, LintArray}; use lint::{EarlyLintPass, LintPass, LateLintPass}; use syntax::ast; use syntax::attr; -use syntax_pos::Span; +use syntax::errors::Applicability; +use syntax_pos::{BytePos, symbol::Ident, Span}; #[derive(PartialEq)] pub enum MethodLateContext { @@ -179,7 +180,8 @@ impl NonSnakeCase { words.join("_") } - fn check_snake_case(&self, cx: &LateContext, sort: &str, name: &str, span: Option<Span>) { + /// Checks if a given identifier is snake case, and reports a diagnostic if not. + fn check_snake_case(&self, cx: &LateContext, sort: &str, ident: &Ident) { fn is_snake_case(ident: &str) -> bool { if ident.is_empty() { return true; @@ -201,20 +203,28 @@ impl NonSnakeCase { }) } + let name = &ident.name.as_str(); + if !is_snake_case(name) { let sc = NonSnakeCase::to_snake_case(name); - let msg = if sc != name { - format!("{} `{}` should have a snake case name such as `{}`", - sort, - name, - sc) + + let msg = format!("{} `{}` should have a snake case name", sort, name); + let mut err = cx.struct_span_lint(NON_SNAKE_CASE, ident.span, &msg); + + // We have a valid span in almost all cases, but we don't have one when linting a crate + // name provided via the command line. + if !ident.span.is_dummy() { + err.span_suggestion_with_applicability( + ident.span, + "convert the identifier to snake case", + sc, + Applicability::MaybeIncorrect, + ); } else { - format!("{} `{}` should have a snake case name", sort, name) - }; - match span { - Some(span) => cx.span_lint(NON_SNAKE_CASE, span, &msg), - None => cx.lint(NON_SNAKE_CASE, &msg), + err.help(&format!("convert the identifier to snake case: `{}`", sc)); } + + err.emit(); } } } @@ -227,50 +237,75 @@ impl LintPass for NonSnakeCase { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) { - let attr_crate_name = attr::find_by_name(&cr.attrs, "crate_name") - .and_then(|at| at.value_str().map(|s| (at, s))); - if let Some(ref name) = cx.tcx.sess.opts.crate_name { - self.check_snake_case(cx, "crate", name, None); - } else if let Some((attr, name)) = attr_crate_name { - self.check_snake_case(cx, "crate", &name.as_str(), Some(attr.span)); + let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name { + Some(Ident::from_str(name)) + } else { + attr::find_by_name(&cr.attrs, "crate_name") + .and_then(|attr| attr.meta()) + .and_then(|meta| { + meta.name_value_literal().and_then(|lit| { + if let ast::LitKind::Str(name, ..) = lit.node { + // Discard the double quotes surrounding the literal. + let sp = cx.sess().source_map().span_to_snippet(lit.span) + .ok() + .and_then(|snippet| { + let left = snippet.find('"')?; + let right = snippet.rfind('"').map(|pos| snippet.len() - pos)?; + + Some( + lit.span + .with_lo(lit.span.lo() + BytePos(left as u32 + 1)) + .with_hi(lit.span.hi() - BytePos(right as u32)), + ) + }) + .unwrap_or_else(|| lit.span); + + Some(Ident::new(name, sp)) + } else { + None + } + }) + }) + }; + + if let Some(ident) = &crate_ident { + self.check_snake_case(cx, "crate", ident); } } fn check_generic_param(&mut self, cx: &LateContext, param: &hir::GenericParam) { - match param.kind { - GenericParamKind::Lifetime { .. } => { - let name = param.name.ident().as_str(); - self.check_snake_case(cx, "lifetime", &name, Some(param.span)); - } - GenericParamKind::Type { .. } => {} + if let GenericParamKind::Lifetime { .. } = param.kind { + self.check_snake_case(cx, "lifetime", ¶m.name.ident()); } } - fn check_fn(&mut self, - cx: &LateContext, - fk: FnKind, - _: &hir::FnDecl, - _: &hir::Body, - span: Span, - id: ast::NodeId) { - match fk { - FnKind::Method(name, ..) => { + fn check_fn( + &mut self, + cx: &LateContext, + fk: FnKind, + _: &hir::FnDecl, + _: &hir::Body, + _: Span, + id: ast::NodeId, + ) { + match &fk { + FnKind::Method(ident, ..) => { match method_context(cx, id) { MethodLateContext::PlainImpl => { - self.check_snake_case(cx, "method", &name.as_str(), Some(span)) + self.check_snake_case(cx, "method", ident); } MethodLateContext::TraitAutoImpl => { - self.check_snake_case(cx, "trait method", &name.as_str(), Some(span)) + self.check_snake_case(cx, "trait method", ident); } _ => (), } } - FnKind::ItemFn(name, _, header, _, attrs) => { + FnKind::ItemFn(ident, _, header, _, attrs) => { // Skip foreign-ABI #[no_mangle] functions (Issue #31924) - if header.abi != Abi::Rust && attr::find_by_name(attrs, "no_mangle").is_some() { + if header.abi != Abi::Rust && attr::contains_name(attrs, "no_mangle") { return; } - self.check_snake_case(cx, "function", &name.as_str(), Some(span)) + self.check_snake_case(cx, "function", ident); } FnKind::Closure(_) => (), } @@ -278,36 +313,35 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { if let hir::ItemKind::Mod(_) = it.node { - self.check_snake_case(cx, "module", &it.ident.as_str(), Some(it.span)); + self.check_snake_case(cx, "module", &it.ident); } } fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) { - if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(ref pnames)) = item.node { - self.check_snake_case(cx, - "trait method", - &item.ident.as_str(), - Some(item.span)); + if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = &item.node { + self.check_snake_case(cx, "trait method", &item.ident); for param_name in pnames { - self.check_snake_case(cx, "variable", ¶m_name.as_str(), Some(param_name.span)); + self.check_snake_case(cx, "variable", param_name); } } } fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) { - if let &PatKind::Binding(_, _, ref ident, _) = &p.node { - self.check_snake_case(cx, "variable", &ident.as_str(), Some(p.span)); + if let &PatKind::Binding(_, _, ident, _) = &p.node { + self.check_snake_case(cx, "variable", &ident); } } - fn check_struct_def(&mut self, - cx: &LateContext, - s: &hir::VariantData, - _: ast::Name, - _: &hir::Generics, - _: ast::NodeId) { + fn check_struct_def( + &mut self, + cx: &LateContext, + s: &hir::VariantData, + _: ast::Name, + _: &hir::Generics, + _: ast::NodeId, + ) { for sf in s.fields() { - self.check_snake_case(cx, "structure field", &sf.ident.as_str(), Some(sf.span)); + self.check_snake_case(cx, "structure field", &sf.ident); } } } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 71028ef9fc6..fa6b825f2a2 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -117,16 +117,18 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, )); } }); - let sym = Ident::with_empty_ctxt(Symbol::gensym(&format!( - "__register_diagnostic_{}", code - ))); + + let span = span.apply_mark(ecx.current_expansion.mark); + + let sym = Ident::new(Symbol::gensym(&format!("__register_diagnostic_{}", code)), span); + MacEager::items(smallvec![ ecx.item_mod( span, span, sym, - Vec::new(), - Vec::new() + vec![], + vec![], ) ]) } diff --git a/src/test/ui/enable-unstable-lib-feature.stderr b/src/test/ui/enable-unstable-lib-feature.stderr index d905ccc8ac0..51cfe7beade 100644 --- a/src/test/ui/enable-unstable-lib-feature.stderr +++ b/src/test/ui/enable-unstable-lib-feature.stderr @@ -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 diff --git a/src/test/ui/expr_attr_paren_order.stderr b/src/test/ui/expr_attr_paren_order.stderr index f3aa39f89cc..8155514191c 100644 --- a/src/test/ui/expr_attr_paren_order.stderr +++ b/src/test/ui/expr_attr_paren_order.stderr @@ -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 diff --git a/src/test/ui/lint/command-line-lint-group-deny.stderr b/src/test/ui/lint/command-line-lint-group-deny.stderr index c6a8f338298..3250a41ee0e 100644 --- a/src/test/ui/lint/command-line-lint-group-deny.stderr +++ b/src/test/ui/lint/command-line-lint-group-deny.stderr @@ -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` diff --git a/src/test/ui/lint/command-line-lint-group-forbid.stderr b/src/test/ui/lint/command-line-lint-group-forbid.stderr index 2c11cca9639..39f6da400c4 100644 --- a/src/test/ui/lint/command-line-lint-group-forbid.stderr +++ b/src/test/ui/lint/command-line-lint-group-forbid.stderr @@ -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` diff --git a/src/test/ui/lint/command-line-lint-group-warn.stderr b/src/test/ui/lint/command-line-lint-group-warn.stderr index 3939461ef57..42a198fe7e3 100644 --- a/src/test/ui/lint/command-line-lint-group-warn.stderr +++ b/src/test/ui/lint/command-line-lint-group-warn.stderr @@ -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` diff --git a/src/test/ui/lint/lint-group-nonstandard-style.stderr b/src/test/ui/lint/lint-group-nonstandard-style.stderr index d85ca7811d0..97e3ce6fd37 100644 --- a/src/test/ui/lint/lint-group-nonstandard-style.stderr +++ b/src/test/ui/lint/lint-group-nonstandard-style.stderr @@ -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 diff --git a/src/test/ui/lint/lint-non-snake-case-crate-2.rs b/src/test/ui/lint/lint-non-snake-case-crate-2.rs index 56c35c256f2..1b763a9d868 100644 --- a/src/test/ui/lint/lint-non-snake-case-crate-2.rs +++ b/src/test/ui/lint/lint-non-snake-case-crate-2.rs @@ -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)] diff --git a/src/test/ui/lint/lint-non-snake-case-crate-2.stderr b/src/test/ui/lint/lint-non-snake-case-crate-2.stderr index eef7f1c79ee..f3303191a06 100644 --- a/src/test/ui/lint/lint-non-snake-case-crate-2.stderr +++ b/src/test/ui/lint/lint-non-snake-case-crate-2.stderr @@ -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 diff --git a/src/test/ui/lint/lint-non-snake-case-crate.rs b/src/test/ui/lint/lint-non-snake-case-crate.rs index 221ce611db5..e4e84261a4e 100644 --- a/src/test/ui/lint/lint-non-snake-case-crate.rs +++ b/src/test/ui/lint/lint-non-snake-case-crate.rs @@ -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() {} diff --git a/src/test/ui/lint/lint-non-snake-case-crate.stderr b/src/test/ui/lint/lint-non-snake-case-crate.stderr index 6d8112091ec..5cfd60a76e4 100644 --- a/src/test/ui/lint/lint-non-snake-case-crate.stderr +++ b/src/test/ui/lint/lint-non-snake-case-crate.stderr @@ -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 diff --git a/src/test/ui/lint/lint-non-snake-case-functions.rs b/src/test/ui/lint/lint-non-snake-case-functions.rs index 5ad454a7a52..fa64a9f980e 100644 --- a/src/test/ui/lint/lint-non-snake-case-functions.rs +++ b/src/test/ui/lint/lint-non-snake-case-functions.rs @@ -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() { } diff --git a/src/test/ui/lint/lint-non-snake-case-functions.stderr b/src/test/ui/lint/lint-non-snake-case-functions.stderr index 508fb225437..49cbfa94126 100644 --- a/src/test/ui/lint/lint-non-snake-case-functions.stderr +++ b/src/test/ui/lint/lint-non-snake-case-functions.stderr @@ -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 diff --git a/src/test/ui/lint/lint-non-snake-case-lifetimes.rs b/src/test/ui/lint/lint-non-snake-case-lifetimes.rs index c7af431bafc..de76d2dbef2 100644 --- a/src/test/ui/lint/lint-non-snake-case-lifetimes.rs +++ b/src/test/ui/lint/lint-non-snake-case-lifetimes.rs @@ -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 () ) {} diff --git a/src/test/ui/lint/lint-non-snake-case-lifetimes.stderr b/src/test/ui/lint/lint-non-snake-case-lifetimes.stderr index 694a5a22525..970666ebcfd 100644 --- a/src/test/ui/lint/lint-non-snake-case-lifetimes.stderr +++ b/src/test/ui/lint/lint-non-snake-case-lifetimes.stderr @@ -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 diff --git a/src/test/ui/lint/lint-non-snake-case-modules.rs b/src/test/ui/lint/lint-non-snake-case-modules.rs index 90f45a4f413..73f12332172 100644 --- a/src/test/ui/lint/lint-non-snake-case-modules.rs +++ b/src/test/ui/lint/lint-non-snake-case-modules.rs @@ -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; } diff --git a/src/test/ui/lint/lint-non-snake-case-modules.stderr b/src/test/ui/lint/lint-non-snake-case-modules.stderr index ec3accf2ae8..651132e49d9 100644 --- a/src/test/ui/lint/lint-non-snake-case-modules.stderr +++ b/src/test/ui/lint/lint-non-snake-case-modules.stderr @@ -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 diff --git a/src/test/run-pass/snake-case-no-lowercase-equivalent.rs b/src/test/ui/lint/lint-non-snake-case-no-lowercase-equivalent.rs index cf7a163c4c9..9a6487d2542 100644 --- a/src/test/run-pass/snake-case-no-lowercase-equivalent.rs +++ b/src/test/ui/lint/lint-non-snake-case-no-lowercase-equivalent.rs @@ -1,3 +1,5 @@ +// compile-pass + #![allow(dead_code)] // pretty-expanded FIXME #23616 diff --git a/src/test/ui/lint/lint-uppercase-variables.rs b/src/test/ui/lint/lint-uppercase-variables.rs index 33c2968e610..86a39502a81 100644 --- a/src/test/ui/lint/lint-uppercase-variables.rs +++ b/src/test/ui/lint/lint-uppercase-variables.rs @@ -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` } diff --git a/src/test/ui/lint/lint-uppercase-variables.stderr b/src/test/ui/lint/lint-uppercase-variables.stderr index f8564668e92..0741179c4a4 100644 --- a/src/test/ui/lint/lint-uppercase-variables.stderr +++ b/src/test/ui/lint/lint-uppercase-variables.stderr @@ -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 diff --git a/src/test/ui/lint/reasons.stderr b/src/test/ui/lint/reasons.stderr index df0f9cb9b61..3bb1480a301 100644 --- a/src/test/ui/lint/reasons.stderr +++ b/src/test/ui/lint/reasons.stderr @@ -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 diff --git a/src/test/ui/regions/regions-fn-subtyping-return-static.rs b/src/test/ui/regions/regions-fn-subtyping-return-static.rs index 4d6d342f571..9010770f1dc 100644 --- a/src/test/ui/regions/regions-fn-subtyping-return-static.rs +++ b/src/test/ui/regions/regions-fn-subtyping-return-static.rs @@ -10,6 +10,7 @@ #![allow(dead_code)] #![allow(unused_variables)] +#![allow(non_snake_case)] struct S; diff --git a/src/test/ui/regions/regions-fn-subtyping-return-static.stderr b/src/test/ui/regions/regions-fn-subtyping-return-static.stderr deleted file mode 100644 index 61eaf9fcf10..00000000000 --- a/src/test/ui/regions/regions-fn-subtyping-return-static.stderr +++ /dev/null @@ -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 | | } - | |_^ - diff --git a/src/test/ui/span/issue-24690.stderr b/src/test/ui/span/issue-24690.stderr index 42b93334572..f052f866c90 100644 --- a/src/test/ui/span/issue-24690.stderr +++ b/src/test/ui/span/issue-24690.stderr @@ -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` |
