about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
authorCamelid <camelidcamel@gmail.com>2020-12-12 13:46:25 -0800
committerCamelid <camelidcamel@gmail.com>2020-12-12 14:59:35 -0800
commitd00ca112020680928aadb221aad13bd52634823b (patch)
treea38e92d34f674930d7fc3e8c785ebb94d33caa1b /compiler/rustc_lint/src
parent5bb68c31f8cef24174a7d3499de6b4ebea069900 (diff)
Add 'consider using' message to overflowing_literals
Ironically, the overflowing_literals handler for binary or hex already
had this message! You would think it would be the other way around :)
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/types.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs
index 9ad9d53cd0d..d9f4da23d2f 100644
--- a/compiler/rustc_lint/src/types.rs
+++ b/compiler/rustc_lint/src/types.rs
@@ -331,18 +331,23 @@ fn lint_int_literal<'tcx>(
         }
 
         cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
-            lint.build(&format!("literal out of range for `{}`", t.name_str()))
-                .note(&format!(
-                    "the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
-                    cx.sess()
-                        .source_map()
-                        .span_to_snippet(lit.span)
-                        .expect("must get snippet from literal"),
-                    t.name_str(),
-                    min,
-                    max,
-                ))
-                .emit();
+            let mut err = lint.build(&format!("literal out of range for `{}`", t.name_str()));
+            err.note(&format!(
+                "the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
+                cx.sess()
+                    .source_map()
+                    .span_to_snippet(lit.span)
+                    .expect("must get snippet from literal"),
+                t.name_str(),
+                min,
+                max,
+            ));
+            if let Some(sugg_ty) =
+                get_type_suggestion(&cx.typeck_results().node_type(e.hir_id), v, negative)
+            {
+                err.help(&format!("consider using `{}` instead", sugg_ty));
+            }
+            err.emit();
         });
     }
 }