about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorjumbatm <jumbatm@gmail.com>2020-02-02 11:11:33 +1000
committerjumbatm <jumbatm@gmail.com>2020-02-11 19:49:01 +1000
commitb2e78faa15263011dad1e9579fc59610d5b75579 (patch)
treee2213a2e65c7fb718eb0398b6c4319d1a4140faa /src
parentd246385122ffd7dd6cc5c490b7e648f58c2ff7fd (diff)
downloadrust-b2e78faa15263011dad1e9579fc59610d5b75579.tar.gz
rust-b2e78faa15263011dad1e9579fc59610d5b75579.zip
Move more work into `decorate` functions.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_lint/nonstandard_style.rs8
-rw-r--r--src/librustc_lint/types.rs20
-rw-r--r--src/librustc_typeck/check_unused.rs32
3 files changed, 28 insertions, 32 deletions
diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs
index 52f29b30f3b..d45ea10dfbf 100644
--- a/src/librustc_lint/nonstandard_style.rs
+++ b/src/librustc_lint/nonstandard_style.rs
@@ -107,8 +107,8 @@ impl NonCamelCaseTypes {
         let name = &ident.name.as_str();
 
         if !is_camel_case(name) {
-            let msg = format!("{} `{}` should have an upper camel case name", sort, name);
             cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, |lint| {
+                let msg = format!("{} `{}` should have an upper camel case name", sort, name);
                 lint.build(&msg)
                     .span_suggestion(
                         ident.span,
@@ -227,8 +227,8 @@ impl NonSnakeCase {
         if !is_snake_case(name) {
             let sc = NonSnakeCase::to_snake_case(name);
 
-            let msg = format!("{} `{}` should have a snake case name", sort, name);
             cx.struct_span_lint(NON_SNAKE_CASE, ident.span, |lint| {
+                let msg = format!("{} `{}` should have a snake case name", sort, name);
                 let mut err = lint.build(&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.
@@ -389,11 +389,9 @@ declare_lint_pass!(NonUpperCaseGlobals => [NON_UPPER_CASE_GLOBALS]);
 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()) {
-            let uc = NonSnakeCase::to_snake_case(&name).to_uppercase();
-
             cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, |lint| {
+                let uc = NonSnakeCase::to_snake_case(&name).to_uppercase();
                 lint.build(&format!("{} `{}` should have an upper case name", sort, name))
                     .span_suggestion(
                         ident.span,
diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs
index 71a86592396..d1982e9162e 100644
--- a/src/librustc_lint/types.rs
+++ b/src/librustc_lint/types.rs
@@ -151,17 +151,17 @@ fn report_bin_hex_error(
     negative: bool,
 ) {
     let size = layout::Integer::from_attr(&cx.tcx, ty).size();
-    let (t, actually) = match ty {
-        attr::IntType::SignedInt(t) => {
-            let actually = sign_extend(val, size) as i128;
-            (t.name_str(), actually.to_string())
-        }
-        attr::IntType::UnsignedInt(t) => {
-            let actually = truncate(val, size);
-            (t.name_str(), actually.to_string())
-        }
-    };
     cx.struct_span_lint(OVERFLOWING_LITERALS, expr.span, |lint| {
+        let (t, actually) = match ty {
+            attr::IntType::SignedInt(t) => {
+                let actually = sign_extend(val, size) as i128;
+                (t.name_str(), actually.to_string())
+            }
+            attr::IntType::UnsignedInt(t) => {
+                let actually = truncate(val, size);
+                (t.name_str(), actually.to_string())
+            }
+        };
         let mut err = lint.build(&format!("literal out of range for {}", t));
         err.note(&format!(
             "the literal `{}` (decimal `{}`) does not fit into \
diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs
index 6471db3efce..dd833d9751c 100644
--- a/src/librustc_typeck/check_unused.rs
+++ b/src/librustc_typeck/check_unused.rs
@@ -123,17 +123,15 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
         // We do this in any edition.
         if extern_crate.warn_if_unused {
             if let Some(&span) = unused_extern_crates.get(&extern_crate.def_id) {
-                let msg = "unused extern crate";
-
-                // Removal suggestion span needs to include attributes (Issue #54400)
-                let span_with_attrs = tcx
-                    .get_attrs(extern_crate.def_id)
-                    .iter()
-                    .map(|attr| attr.span)
-                    .fold(span, |acc, attr_span| acc.to(attr_span));
-
                 tcx.struct_span_lint_hir(lint, id, span, |lint| {
-                    lint.build(msg)
+                    // Removal suggestion span needs to include attributes (Issue #54400)
+                    let span_with_attrs = tcx
+                        .get_attrs(extern_crate.def_id)
+                        .iter()
+                        .map(|attr| attr.span)
+                        .fold(span, |acc, attr_span| acc.to(attr_span));
+
+                    lint.build("unused extern crate")
                         .span_suggestion_short(
                             span_with_attrs,
                             "remove it",
@@ -172,14 +170,14 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
         if !tcx.get_attrs(extern_crate.def_id).is_empty() {
             continue;
         }
-
-        // Otherwise, we can convert it into a `use` of some kind.
-        let base_replacement = match extern_crate.orig_name {
-            Some(orig_name) => format!("use {} as {};", orig_name, item.ident.name),
-            None => format!("use {};", item.ident.name),
-        };
-        let replacement = visibility_qualified(&item.vis, base_replacement);
         tcx.struct_span_lint_hir(lint, id, extern_crate.span, |lint| {
+            // Otherwise, we can convert it into a `use` of some kind.
+            let base_replacement = match extern_crate.orig_name {
+                Some(orig_name) => format!("use {} as {};", orig_name, item.ident.name),
+                None => format!("use {};", item.ident.name),
+            };
+
+            let replacement = visibility_qualified(&item.vis, base_replacement);
             let msg = "`extern crate` is not idiomatic in the new edition";
             let help = format!("convert it to a `{}`", visibility_qualified(&item.vis, "use"));