Skip to content

Commit

Permalink
fix the error with long string in raw string (#3800)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaser53 authored and topecongiro committed Sep 18, 2019
1 parent ca78653 commit 4449250
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Cow;
use std::cmp::min;

use itertools::Itertools;
use syntax::parse::token::DelimToken;
use syntax::parse::token::{DelimToken, LitKind};
use syntax::source_map::{BytePos, SourceMap, Span};
use syntax::{ast, ptr};

Expand Down Expand Up @@ -75,7 +75,17 @@ pub(crate) fn format_expr(
choose_separator_tactic(context, expr.span),
None,
),
ast::ExprKind::Lit(ref l) => rewrite_literal(context, l, shape),
ast::ExprKind::Lit(ref l) => {
if let Some(expr_rw) = rewrite_literal(context, l, shape) {
Some(expr_rw)
} else {
if let LitKind::StrRaw(_) = l.token.kind {
Some(context.snippet(l.span).trim().into())
} else {
None
}
}
}
ast::ExprKind::Call(ref callee, ref args) => {
let inner_span = mk_sp(callee.span.hi(), expr.span.hi());
let callee_str = callee.rewrite(context, shape)?;
Expand Down
12 changes: 12 additions & 0 deletions tests/source/issue-3786.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn main() {
let _ =
r#"
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
"#;

let _with_newline =

r#"
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
"#;
}
9 changes: 9 additions & 0 deletions tests/target/issue-3786.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
let _ = r#"
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
"#;

let _with_newline = r#"
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
"#;
}

0 comments on commit 4449250

Please sign in to comment.