]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/write.rs
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
[rust.git] / clippy_lints / src / write.rs
index b55d0d94019855313a146e81494962f0b5e348d7..7d72a21ac0360cdb22f826d2b0aa2c71418b23a5 100644 (file)
@@ -6,7 +6,7 @@
 use syntax::ast::*;
 use syntax::parse::{parser, token};
 use syntax::tokenstream::TokenStream;
-use syntax_pos::{symbol::Symbol, BytePos, Span};
+use syntax_pos::{BytePos, Span};
 
 declare_clippy_lint! {
     /// **What it does:** This lint warns when you use `println!("")` to
     /// lint is to catch debugging remnants.
     ///
     /// **Why is this bad?** The purpose of the `Debug` trait is to facilitate
-    /// debugging Rust code. It should not be used in in user-facing output.
+    /// debugging Rust code. It should not be used in user-facing output.
     ///
     /// **Example:**
     /// ```rust
+    /// # let foo = "bar";
     /// println!("{:?}", foo);
     /// ```
     pub USE_DEBUG,
 
 impl EarlyLintPass for Write {
     fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) {
-        if mac.node.path == sym!(println) {
+        if mac.path == sym!(println) {
             span_lint(cx, PRINT_STDOUT, mac.span, "use of `println!`");
-            if let (Some(fmt_str), _) = check_tts(cx, &mac.node.tts, false) {
+            if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) {
                 if fmt_str.contents.is_empty() {
                     span_lint_and_sugg(
                         cx,
@@ -197,9 +198,9 @@ fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) {
                     );
                 }
             }
-        } else if mac.node.path == sym!(print) {
+        } else if mac.path == sym!(print) {
             span_lint(cx, PRINT_STDOUT, mac.span, "use of `print!`");
-            if let (Some(fmt_str), _) = check_tts(cx, &mac.node.tts, false) {
+            if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) {
                 if check_newlines(&fmt_str) {
                     span_lint_and_then(
                         cx,
@@ -210,7 +211,7 @@ fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) {
                             err.multipart_suggestion(
                                 "use `println!` instead",
                                 vec![
-                                    (mac.node.path.span, String::from("println")),
+                                    (mac.path.span, String::from("println")),
                                     (fmt_str.newline_span(), String::new()),
                                 ],
                                 Applicability::MachineApplicable,
@@ -219,8 +220,8 @@ fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) {
                     );
                 }
             }
-        } else if mac.node.path == sym!(write) {
-            if let (Some(fmt_str), _) = check_tts(cx, &mac.node.tts, true) {
+        } else if mac.path == sym!(write) {
+            if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, true) {
                 if check_newlines(&fmt_str) {
                     span_lint_and_then(
                         cx,
@@ -231,7 +232,7 @@ fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) {
                             err.multipart_suggestion(
                                 "use `writeln!()` instead",
                                 vec![
-                                    (mac.node.path.span, String::from("writeln")),
+                                    (mac.path.span, String::from("writeln")),
                                     (fmt_str.newline_span(), String::new()),
                                 ],
                                 Applicability::MachineApplicable,
@@ -240,8 +241,8 @@ fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &Mac) {
                     )
                 }
             }
-        } else if mac.node.path == sym!(writeln) {
-            if let (Some(fmt_str), expr) = check_tts(cx, &mac.node.tts, true) {
+        } else if mac.path == sym!(writeln) {
+            if let (Some(fmt_str), expr) = check_tts(cx, &mac.tts, true) {
                 if fmt_str.contents.is_empty() {
                     let mut applicability = Applicability::MachineApplicable;
                     let suggestion = expr.map_or_else(
@@ -319,6 +320,7 @@ fn newline_span(&self) -> Span {
 /// ```rust,ignore
 /// (Some("string to write: {}"), Some(buf))
 /// ```
+#[allow(clippy::too_many_lines)]
 fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (Option<FmtStr>, Option<Expr>) {
     use fmt_macros::*;
     let tts = tts.clone();
@@ -364,7 +366,9 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
             align: AlignUnknown,
             flags: 0,
             precision: CountImplied,
+            precision_span: None,
             width: CountImplied,
+            width_span: None,
             ty: "",
         };
         if !parser.eat(&token::Comma) {
@@ -418,7 +422,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
                             match arg.position {
                                 ArgumentImplicitlyIs(_) | ArgumentIs(_) => {},
                                 ArgumentNamed(name) => {
-                                    if *p == Symbol::intern(name) {
+                                    if *p == name {
                                         seen = true;
                                         all_simple &= arg.format == SIMPLE;
                                     }