Skip to content

Commit 4449250

Browse files
rchaser53topecongiro
authored andcommitted
fix the error with long string in raw string (#3800)
1 parent ca78653 commit 4449250

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/expr.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::Cow;
22
use std::cmp::min;
33

44
use itertools::Itertools;
5-
use syntax::parse::token::DelimToken;
5+
use syntax::parse::token::{DelimToken, LitKind};
66
use syntax::source_map::{BytePos, SourceMap, Span};
77
use syntax::{ast, ptr};
88

@@ -75,7 +75,17 @@ pub(crate) fn format_expr(
7575
choose_separator_tactic(context, expr.span),
7676
None,
7777
),
78-
ast::ExprKind::Lit(ref l) => rewrite_literal(context, l, shape),
78+
ast::ExprKind::Lit(ref l) => {
79+
if let Some(expr_rw) = rewrite_literal(context, l, shape) {
80+
Some(expr_rw)
81+
} else {
82+
if let LitKind::StrRaw(_) = l.token.kind {
83+
Some(context.snippet(l.span).trim().into())
84+
} else {
85+
None
86+
}
87+
}
88+
}
7989
ast::ExprKind::Call(ref callee, ref args) => {
8090
let inner_span = mk_sp(callee.span.hi(), expr.span.hi());
8191
let callee_str = callee.rewrite(context, shape)?;

tests/source/issue-3786.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn main() {
2+
let _ =
3+
r#"
4+
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
5+
"#;
6+
7+
let _with_newline =
8+
9+
r#"
10+
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
11+
"#;
12+
}

tests/target/issue-3786.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let _ = r#"
3+
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
4+
"#;
5+
6+
let _with_newline = r#"
7+
this is a very long string exceeded maximum width in this case maximum 100. (current this line width is about 115)
8+
"#;
9+
}

0 commit comments

Comments
 (0)