fix: correctly reconstruct raw strings
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
use crate::rustc::hir::*;
|
||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use crate::rustc::{declare_tool_lint, lint_array};
|
||||
@@ -164,15 +163,20 @@ impl LintPass for StringLitAsBytes {
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
use crate::syntax::ast::LitKind;
|
||||
use crate::syntax::ast::{LitKind, StrStyle};
|
||||
use crate::utils::{in_macro, snippet};
|
||||
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = e.node {
|
||||
if path.ident.name == "as_bytes" {
|
||||
if let ExprKind::Lit(ref lit) = args[0].node {
|
||||
if let LitKind::Str(ref lit_content, _) = lit.node {
|
||||
if let LitKind::Str(ref lit_content, style) = lit.node {
|
||||
let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#);
|
||||
let expanded = format!("\"{}\"", lit_content.as_str());
|
||||
let expanded = if let StrStyle::Raw(n) = style {
|
||||
let term = (0..n).map(|_| '#').collect::<String>();
|
||||
format!("r{0}\"{1}\"{0}", term, lit_content.as_str())
|
||||
} else {
|
||||
format!("\"{}\"", lit_content.as_str())
|
||||
};
|
||||
if callsite.starts_with("include_str!") {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
||||
Reference in New Issue
Block a user