]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/literal_representation.rs
Merge branch 'macro-use' into HEAD
[rust.git] / clippy_lints / src / literal_representation.rs
index 51ca236026c61049c8c78fd2a8d5cb90c158ae77..bb5a923eaf9ca9ed2dd78ee4073092538fcb9a7d 100644 (file)
@@ -2,6 +2,8 @@
 //! floating-point literal expressions.
 
 use rustc::lint::*;
+use rustc::{declare_lint, lint_array};
+use if_chain::if_chain;
 use syntax::ast::*;
 use syntax_pos;
 use crate::utils::{in_external_macro, snippet_opt, span_lint_and_sugg};
@@ -90,7 +92,7 @@ pub(super) enum Radix {
 
 impl Radix {
     /// Return a reasonable digit group size for this radix.
-    pub fn suggest_grouping(&self) -> usize {
+    crate fn suggest_grouping(&self) -> usize {
         match *self {
             Radix::Binary | Radix::Hexadecimal => 4,
             Radix::Octal | Radix::Decimal => 3,
@@ -101,19 +103,19 @@ pub fn suggest_grouping(&self) -> usize {
 #[derive(Debug)]
 pub(super) struct DigitInfo<'a> {
     /// Characters of a literal between the radix prefix and type suffix.
-    pub digits: &'a str,
+    crate digits: &'a str,
     /// Which radix the literal was represented in.
-    pub radix: Radix,
+    crate radix: Radix,
     /// The radix prefix, if present.
-    pub prefix: Option<&'a str>,
+    crate prefix: Option<&'a str>,
     /// The type suffix, including preceding underscore if present.
-    pub suffix: Option<&'a str>,
+    crate suffix: Option<&'a str>,
     /// True for floating-point literals.
-    pub float: bool,
+    crate float: bool,
 }
 
 impl<'a> DigitInfo<'a> {
-    pub fn new(lit: &'a str, float: bool) -> Self {
+    crate fn new(lit: &'a str, float: bool) -> Self {
         // Determine delimiter for radix prefix, if present, and radix.
         let radix = if lit.starts_with("0x") {
             Radix::Hexadecimal
@@ -160,7 +162,7 @@ pub fn new(lit: &'a str, float: bool) -> Self {
     }
 
     /// Returns digits grouped in a sensible way.
-    pub fn grouping_hint(&self) -> String {
+    crate fn grouping_hint(&self) -> String {
         let group_size = self.radix.suggest_grouping();
         if self.digits.contains('.') {
             let mut parts = self.digits.split('.');
@@ -227,12 +229,12 @@ enum WarningType {
 }
 
 impl WarningType {
-    pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: &syntax_pos::Span) {
-        match *self {
+    crate fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: syntax_pos::Span) {
+        match self {
             WarningType::UnreadableLiteral => span_lint_and_sugg(
                 cx,
                 UNREADABLE_LITERAL,
-                *span,
+                span,
                 "long literal lacking separators",
                 "consider",
                 grouping_hint.to_owned(),
@@ -240,7 +242,7 @@ pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: &syntax_pos:
             WarningType::LargeDigitGroups => span_lint_and_sugg(
                 cx,
                 LARGE_DIGIT_GROUPS,
-                *span,
+                span,
                 "digit groups should be smaller",
                 "consider",
                 grouping_hint.to_owned(),
@@ -248,7 +250,7 @@ pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: &syntax_pos:
             WarningType::InconsistentDigitGrouping => span_lint_and_sugg(
                 cx,
                 INCONSISTENT_DIGIT_GROUPING,
-                *span,
+                span,
                 "digits grouped inconsistently by underscores",
                 "consider",
                 grouping_hint.to_owned(),
@@ -256,7 +258,7 @@ pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: &syntax_pos:
             WarningType::DecimalRepresentation => span_lint_and_sugg(
                 cx,
                 DECIMAL_LITERAL_REPRESENTATION,
-                *span,
+                span,
                 "integer literal has a better hexadecimal representation",
                 "consider",
                 grouping_hint.to_owned(),
@@ -291,7 +293,7 @@ fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
 }
 
 impl LiteralDigitGrouping {
-    fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
+    fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
         match lit.node {
             LitKind::Int(..) => {
                 // Lint integral literals.
@@ -302,7 +304,7 @@ fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
                     then {
                         let digit_info = DigitInfo::new(&src, false);
                         let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
-                            warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)
+                            warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
                         });
                     }
                 }
@@ -337,15 +339,15 @@ fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
                                             if !consistent {
                                                 WarningType::InconsistentDigitGrouping.display(&digit_info.grouping_hint(),
                                                 cx,
-                                                &lit.span);
+                                                lit.span);
                                             }
                                         })
                                     .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(),
                                     cx,
-                                    &lit.span));
+                                    lit.span));
                                 }
                             })
-                        .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, &lit.span));
+                        .map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, lit.span));
                     }
                 }
             },
@@ -436,7 +438,7 @@ pub fn new(threshold: u64) -> Self {
             threshold,
         }
     }
-    fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
+    fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
         // Lint integral literals.
         if_chain! {
             if let LitKind::Int(..) = lit.node;
@@ -457,7 +459,7 @@ fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
                     let hex = format!("{:#X}", val);
                     let digit_info = DigitInfo::new(&hex[..], false);
                     let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
-                        warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)
+                        warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
                     });
                 }
             }