diff --git a/src/string.rs b/src/string.rs index 47ba79d927b9..5961254cd9a6 100644 --- a/src/string.rs +++ b/src/string.rs @@ -31,17 +31,17 @@ pub struct StringFormat<'a> { } // FIXME: simplify this! -pub fn rewrite_string<'a>(s: &str, fmt: &StringFormat<'a>) -> Option { +pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option { // Strip line breaks. - let re = Regex::new(r"(\\[\n\r][:space:]*)").unwrap(); - let stripped_str = re.replace_all(s, ""); + let re = Regex::new(r"([^\\](\\\\)*)\\[\n\r][:space:]*").unwrap(); + let stripped_str = re.replace_all(orig, "$1"); let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::>(); let indent = fmt.offset.to_string(fmt.config); let punctuation = ":,;."; let mut cur_start = 0; - let mut result = String::with_capacity(round_up_to_power_of_two(s.len())); + let mut result = String::with_capacity(round_up_to_power_of_two(stripped_str.len())); result.push_str(fmt.opener); let ender_length = fmt.line_end.len(); @@ -79,7 +79,7 @@ pub fn rewrite_string<'a>(s: &str, fmt: &StringFormat<'a>) -> Option { } } // Make sure there is no whitespace to the right of the break. - while cur_end < s.len() && graphemes[cur_end].trim().is_empty() { + while cur_end < stripped_str.len() && graphemes[cur_end].trim().is_empty() { cur_end += 1; } let raw_line = graphemes[cur_start..cur_end].join(""); diff --git a/tests/source/string-lit.rs b/tests/source/string-lit.rs index c0bbee4f6175..c89b798a0ea7 100644 --- a/tests/source/string-lit.rs +++ b/tests/source/string-lit.rs @@ -39,3 +39,8 @@ fn issue682() { let a = "hello \\ o/"; let b = a.replace("\\ ", "\\"); } + +fn issue716() { + println!("forall x. mult(e(), x) = x /\\ + forall x. mult(x, x) = e()"); +} diff --git a/tests/target/string-lit.rs b/tests/target/string-lit.rs index 0b5b5105b9bc..b9a676c49ea7 100644 --- a/tests/target/string-lit.rs +++ b/tests/target/string-lit.rs @@ -45,3 +45,8 @@ fn issue682() { let a = "hello \\ o/"; let b = a.replace("\\ ", "\\"); } + +fn issue716() { + println!("forall x. mult(e(), x) = x /\\ + forall x. mult(x, x) = e()"); +}