]> git.lizzy.rs Git - rust.git/commitdiff
Add macro check
authorFlorian Hartwig <florian.j.hartwig@gmail.com>
Tue, 19 Jan 2016 18:43:29 +0000 (19:43 +0100)
committerFlorian Hartwig <florian.j.hartwig@gmail.com>
Tue, 19 Jan 2016 19:08:56 +0000 (20:08 +0100)
src/strings.rs

index c32289f84fda611f080d28e731a36c1ca29cd760..16ee08b1894936fba4671690cad29cceffbc900d 100644 (file)
@@ -134,13 +134,13 @@ impl LateLintPass for StringLitAsBytes {
     fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
         use std::ascii::AsciiExt;
         use syntax::ast::Lit_::LitStr;
-        use utils::snippet;
+        use utils::{snippet, in_macro};
 
         if let ExprMethodCall(ref name, _, ref args) = e.node {
             if name.node.as_str() == "as_bytes" {
                 if let ExprLit(ref lit) = args[0].node {
                     if let LitStr(ref lit_content, _) = lit.node {
-                        if lit_content.chars().all(|c| c.is_ascii()) {
+                        if lit_content.chars().all(|c| c.is_ascii()) && !in_macro(cx, e.span) {
                             let msg = format!("calling `as_bytes()` on a string literal. \
                                                Consider using a byte string literal instead: \
                                                `b{}`",