1 use crate::utils::{span_help_and_lint, span_lint_and_sugg, snippet_opt};
2 use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
3 use rustc::{declare_tool_lint, lint_array};
5 use rustc_errors::Applicability;
6 use syntax::tokenstream::TokenStream;
7 use syntax::source_map::Span;
9 /// **What it does:** Checks for usage of dbg!() macro.
11 /// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It
12 /// should not be in version control.
14 /// **Known problems:** None.
24 declare_clippy_lint! {
27 "`dbg!` macro is intended as a debugging tool"
30 #[derive(Copy, Clone, Debug)]
33 impl LintPass for Pass {
34 fn get_lints(&self) -> LintArray {
35 lint_array!(DBG_MACRO)
38 fn name(&self) -> &'static str {
43 impl EarlyLintPass for Pass {
44 fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
45 if mac.node.path == "dbg" {
46 match tts_span(mac.node.tts.clone()).and_then(|span| snippet_opt(cx, span)) {
52 "`dbg!` macro is intended as a debugging tool",
53 "ensure to avoid having uses of it in version control",
55 Applicability::MaybeIncorrect,
63 "`dbg!` macro is intended as a debugging tool",
64 "ensure to avoid having uses of it in version control",
72 // Get span enclosing entire the token stream.
73 fn tts_span(tts: TokenStream) -> Option<Span> {
74 let mut cursor = tts.into_trees();
75 let first = cursor.next()?.span();
76 let span = match cursor.last() {
77 Some(tree) => first.to(tree.span()),