mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
Add macro check
This commit is contained in:
parent
01eda52cb5
commit
ea26ae3888
1 changed files with 2 additions and 2 deletions
|
@ -134,13 +134,13 @@ impl LateLintPass for StringLitAsBytes {
|
||||||
fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
|
fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use syntax::ast::Lit_::LitStr;
|
use syntax::ast::Lit_::LitStr;
|
||||||
use utils::snippet;
|
use utils::{snippet, in_macro};
|
||||||
|
|
||||||
if let ExprMethodCall(ref name, _, ref args) = e.node {
|
if let ExprMethodCall(ref name, _, ref args) = e.node {
|
||||||
if name.node.as_str() == "as_bytes" {
|
if name.node.as_str() == "as_bytes" {
|
||||||
if let ExprLit(ref lit) = args[0].node {
|
if let ExprLit(ref lit) = args[0].node {
|
||||||
if let LitStr(ref lit_content, _) = lit.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. \
|
let msg = format!("calling `as_bytes()` on a string literal. \
|
||||||
Consider using a byte string literal instead: \
|
Consider using a byte string literal instead: \
|
||||||
`b{}`",
|
`b{}`",
|
||||||
|
|
Loading…
Reference in a new issue