about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/nonstandard_style.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_lint/src/nonstandard_style.rs')
-rw-r--r--compiler/rustc_lint/src/nonstandard_style.rs103
1 files changed, 55 insertions, 48 deletions
diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs
index 768ad84838b..9f800e9c8c9 100644
--- a/compiler/rustc_lint/src/nonstandard_style.rs
+++ b/compiler/rustc_lint/src/nonstandard_style.rs
@@ -136,26 +136,30 @@ impl NonCamelCaseTypes {
         let name = ident.name.as_str();
 
         if !is_camel_case(name) {
-            cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, |lint| {
-                let mut err = lint.build(fluent::lint::non_camel_case_type);
-                let cc = to_camel_case(name);
-                // We cannot provide meaningful suggestions
-                // if the characters are in the category of "Lowercase Letter".
-                if *name != cc {
-                    err.span_suggestion(
-                        ident.span,
-                        fluent::lint::suggestion,
-                        to_camel_case(name),
-                        Applicability::MaybeIncorrect,
-                    );
-                } else {
-                    err.span_label(ident.span, fluent::lint::label);
-                }
+            cx.struct_span_lint(
+                NON_CAMEL_CASE_TYPES,
+                ident.span,
+                fluent::lint::non_camel_case_type,
+                |lint| {
+                    let cc = to_camel_case(name);
+                    // We cannot provide meaningful suggestions
+                    // if the characters are in the category of "Lowercase Letter".
+                    if *name != cc {
+                        lint.span_suggestion(
+                            ident.span,
+                            fluent::lint::suggestion,
+                            to_camel_case(name),
+                            Applicability::MaybeIncorrect,
+                        );
+                    } else {
+                        lint.span_label(ident.span, fluent::lint::label);
+                    }
 
-                err.set_arg("sort", sort);
-                err.set_arg("name", name);
-                err.emit();
-            })
+                    lint.set_arg("sort", sort);
+                    lint.set_arg("name", name);
+                    lint
+                },
+            )
         }
     }
 }
@@ -280,9 +284,8 @@ impl NonSnakeCase {
         let name = ident.name.as_str();
 
         if !is_snake_case(name) {
-            cx.struct_span_lint(NON_SNAKE_CASE, ident.span, |lint| {
+            cx.struct_span_lint(NON_SNAKE_CASE, ident.span, fluent::lint::non_snake_case, |lint| {
                 let sc = NonSnakeCase::to_snake_case(name);
-                let mut err = lint.build(fluent::lint::non_snake_case);
                 // We cannot provide meaningful suggestions
                 // if the characters are in the category of "Uppercase Letter".
                 if name != sc {
@@ -297,30 +300,30 @@ impl NonSnakeCase {
                             if sc_ident.name.can_be_raw() {
                                 (fluent::lint::rename_or_convert_suggestion, sc_ident.to_string())
                             } else {
-                                err.note(fluent::lint::cannot_convert_note);
+                                lint.note(fluent::lint::cannot_convert_note);
                                 (fluent::lint::rename_suggestion, String::new())
                             }
                         } else {
                             (fluent::lint::convert_suggestion, sc.clone())
                         };
 
-                        err.span_suggestion(
+                        lint.span_suggestion(
                             ident.span,
                             message,
                             suggestion,
                             Applicability::MaybeIncorrect,
                         );
                     } else {
-                        err.help(fluent::lint::help);
+                        lint.help(fluent::lint::help);
                     }
                 } else {
-                    err.span_label(ident.span, fluent::lint::label);
+                    lint.span_label(ident.span, fluent::lint::label);
                 }
 
-                err.set_arg("sort", sort);
-                err.set_arg("name", name);
-                err.set_arg("sc", sc);
-                err.emit();
+                lint.set_arg("sort", sort);
+                lint.set_arg("name", name);
+                lint.set_arg("sc", sc);
+                lint
             });
         }
     }
@@ -478,26 +481,30 @@ impl NonUpperCaseGlobals {
     fn check_upper_case(cx: &LateContext<'_>, sort: &str, ident: &Ident) {
         let name = ident.name.as_str();
         if name.chars().any(|c| c.is_lowercase()) {
-            cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, |lint| {
-                let uc = NonSnakeCase::to_snake_case(&name).to_uppercase();
-                let mut err = lint.build(fluent::lint::non_upper_case_global);
-                // We cannot provide meaningful suggestions
-                // if the characters are in the category of "Lowercase Letter".
-                if *name != uc {
-                    err.span_suggestion(
-                        ident.span,
-                        fluent::lint::suggestion,
-                        uc,
-                        Applicability::MaybeIncorrect,
-                    );
-                } else {
-                    err.span_label(ident.span, fluent::lint::label);
-                }
+            cx.struct_span_lint(
+                NON_UPPER_CASE_GLOBALS,
+                ident.span,
+                fluent::lint::non_upper_case_global,
+                |lint| {
+                    let uc = NonSnakeCase::to_snake_case(&name).to_uppercase();
+                    // We cannot provide meaningful suggestions
+                    // if the characters are in the category of "Lowercase Letter".
+                    if *name != uc {
+                        lint.span_suggestion(
+                            ident.span,
+                            fluent::lint::suggestion,
+                            uc,
+                            Applicability::MaybeIncorrect,
+                        );
+                    } else {
+                        lint.span_label(ident.span, fluent::lint::label);
+                    }
 
-                err.set_arg("sort", sort);
-                err.set_arg("name", name);
-                err.emit();
-            })
+                    lint.set_arg("sort", sort);
+                    lint.set_arg("name", name);
+                    lint
+                },
+            )
         }
     }
 }