|
7 | 7 | // option. This file may not be copied, modified, or distributed
|
8 | 8 | // except according to those terms.
|
9 | 9 |
|
10 |
| - |
11 | 10 | use crate::rustc::hir::*;
|
12 | 11 | use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
13 | 12 | use crate::rustc::{declare_tool_lint, lint_array};
|
@@ -164,15 +163,20 @@ impl LintPass for StringLitAsBytes {
|
164 | 163 |
|
165 | 164 | impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
|
166 | 165 | fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
167 |
| - use crate::syntax::ast::LitKind; |
| 166 | + use crate::syntax::ast::{LitKind, StrStyle}; |
168 | 167 | use crate::utils::{in_macro, snippet};
|
169 | 168 |
|
170 | 169 | if let ExprKind::MethodCall(ref path, _, ref args) = e.node {
|
171 | 170 | if path.ident.name == "as_bytes" {
|
172 | 171 | if let ExprKind::Lit(ref lit) = args[0].node {
|
173 |
| - if let LitKind::Str(ref lit_content, _) = lit.node { |
| 172 | + if let LitKind::Str(ref lit_content, style) = lit.node { |
174 | 173 | let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#);
|
175 |
| - let expanded = format!("\"{}\"", lit_content.as_str()); |
| 174 | + let expanded = if let StrStyle::Raw(n) = style { |
| 175 | + let term = (0..n).map(|_| '#').collect::<String>(); |
| 176 | + format!("r{0}\"{1}\"{0}", term, lit_content.as_str()) |
| 177 | + } else { |
| 178 | + format!("\"{}\"", lit_content.as_str()) |
| 179 | + }; |
176 | 180 | if callsite.starts_with("include_str!") {
|
177 | 181 | span_lint_and_sugg(
|
178 | 182 | cx,
|
|
0 commit comments