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,
);
}
}
- } 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,
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,
);
}
}
- } 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,
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,
)
}
}
- } 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(
/// ```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();
align: AlignUnknown,
flags: 0,
precision: CountImplied,
+ precision_span: None,
width: CountImplied,
+ width_span: None,
ty: "",
};
if !parser.eat(&token::Comma) {
match arg.position {
ArgumentImplicitlyIs(_) | ArgumentIs(_) => {},
ArgumentNamed(name) => {
- if *p == Symbol::intern(name) {
+ if *p == name {
seen = true;
all_simple &= arg.format == SIMPLE;
}