Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit efd6fda

Browse files
authored
Merge pull request rust-lang#3311 from rchaser53/issue-3295
fix "internal error: left behind trailing whitespace" with long lines
2 parents 7c0f59b + c2534f5 commit efd6fda

File tree

12 files changed

+137
-4
lines changed

12 files changed

+137
-4
lines changed

Configurations.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,7 @@ Format string literals where necessary
10371037

10381038
```rust
10391039
fn main() {
1040-
let lorem =
1041-
"ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
1040+
let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit amet consectetur adipiscing";
10421041
}
10431042
```
10441043

src/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use comment::{
2222
combine_strs_with_missing_comments, contains_comment, recover_comment_removed, rewrite_comment,
2323
rewrite_missing_comment, CharClasses, FindUncommented,
2424
};
25-
use config::{Config, ControlBraceStyle, IndentStyle};
25+
use config::{Config, ControlBraceStyle, IndentStyle, Version};
2626
use lists::{
2727
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
2828
struct_lit_tactic, write_list, ListFormatting, ListItem, Separator,
@@ -1264,7 +1264,11 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
12641264
.join("\n")
12651265
.trim_start(),
12661266
);
1267-
return wrap_str(indented_string_lit, context.config.max_width(), shape);
1267+
return if context.config.version() == Version::Two {
1268+
Some(indented_string_lit)
1269+
} else {
1270+
wrap_str(indented_string_lit, context.config.max_width(), shape)
1271+
};
12681272
} else {
12691273
return wrap_str(string_lit.to_owned(), context.config.max_width(), shape);
12701274
}

tests/source/configs/indent_style/block_trailing_comma_call.rs renamed to tests/source/configs/indent_style/block_trailing_comma_call/one.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-version: One
12
// rustfmt-error_on_line_overflow: false
23
// rustfmt-indent_style: Block
34

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-version: Two
2+
// rustfmt-error_on_line_overflow: false
3+
// rustfmt-indent_style: Block
4+
5+
// rustfmt should not add trailing comma when rewriting macro. See #1528.
6+
fn a() {
7+
panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:");
8+
foo(a, oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt());
9+
}

tests/source/issue-2179.rs renamed to tests/source/issue-2179/one.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-version: One
12
// rustfmt-error_on_line_overflow: false
23

34
fn issue_2179() {

tests/source/issue-2179/two.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// rustfmt-version: Two
2+
// rustfmt-error_on_line_overflow: false
3+
4+
fn issue_2179() {
5+
let (opts, rustflags, clear_env_rust_log) =
6+
{
7+
// We mustn't lock configuration for the whole build process
8+
let rls_config = rls_config.lock().unwrap();
9+
10+
let opts = CargoOptions::new(&rls_config);
11+
trace!("Cargo compilation options:\n{:?}", opts);
12+
let rustflags = prepare_cargo_rustflags(&rls_config);
13+
14+
// Warn about invalid specified bin target or package depending on current mode
15+
// TODO: Return client notifications along with diagnostics to inform the user
16+
if !rls_config.workspace_mode {
17+
let cur_pkg_targets = ws.current().unwrap().targets();
18+
19+
if let &Some(ref build_bin) = rls_config.build_bin.as_ref() {
20+
let mut bins = cur_pkg_targets.iter().filter(|x| x.is_bin());
21+
if let None = bins.find(|x| x.name() == build_bin) {
22+
warn!("cargo - couldn't find binary `{}` specified in `build_bin` configuration", build_bin);
23+
}
24+
}
25+
} else {
26+
for package in &opts.package {
27+
if let None = ws.members().find(|x| x.name() == package) {
28+
warn!("cargo - couldn't find member package `{}` specified in `analyze_package` configuration", package);
29+
}
30+
}
31+
}
32+
33+
(opts, rustflags, rls_config.clear_env_rust_log)
34+
};
35+
36+
}

tests/source/issue-3295/two.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// rustfmt-version: Two
2+
pub enum TestEnum {
3+
a,
4+
b,
5+
}
6+
7+
fn the_test(input: TestEnum) {
8+
match input {
9+
TestEnum::a => String::from("aaa"),
10+
TestEnum::b => String::from("this is a very very very very very very very very very very very very very very very ong string"),
11+
12+
};
13+
}

tests/target/configs/indent_style/block_trailing_comma_call.rs renamed to tests/target/configs/indent_style/block_trailing_comma_call/one.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-version: One
12
// rustfmt-error_on_line_overflow: false
23
// rustfmt-indent_style: Block
34

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// rustfmt-version: Two
2+
// rustfmt-error_on_line_overflow: false
3+
// rustfmt-indent_style: Block
4+
5+
// rustfmt should not add trailing comma when rewriting macro. See #1528.
6+
fn a() {
7+
panic!(
8+
"this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"
9+
);
10+
foo(
11+
a,
12+
oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt(),
13+
);
14+
}

tests/target/issue-2179.rs renamed to tests/target/issue-2179/one.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-version: One
12
// rustfmt-error_on_line_overflow: false
23

34
fn issue_2179() {

tests/target/issue-2179/two.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// rustfmt-version: Two
2+
// rustfmt-error_on_line_overflow: false
3+
4+
fn issue_2179() {
5+
let (opts, rustflags, clear_env_rust_log) = {
6+
// We mustn't lock configuration for the whole build process
7+
let rls_config = rls_config.lock().unwrap();
8+
9+
let opts = CargoOptions::new(&rls_config);
10+
trace!("Cargo compilation options:\n{:?}", opts);
11+
let rustflags = prepare_cargo_rustflags(&rls_config);
12+
13+
// Warn about invalid specified bin target or package depending on current mode
14+
// TODO: Return client notifications along with diagnostics to inform the user
15+
if !rls_config.workspace_mode {
16+
let cur_pkg_targets = ws.current().unwrap().targets();
17+
18+
if let &Some(ref build_bin) = rls_config.build_bin.as_ref() {
19+
let mut bins = cur_pkg_targets.iter().filter(|x| x.is_bin());
20+
if let None = bins.find(|x| x.name() == build_bin) {
21+
warn!(
22+
"cargo - couldn't find binary `{}` specified in `build_bin` configuration",
23+
build_bin
24+
);
25+
}
26+
}
27+
} else {
28+
for package in &opts.package {
29+
if let None = ws.members().find(|x| x.name() == package) {
30+
warn!(
31+
"cargo - couldn't find member package `{}` specified in `analyze_package` configuration",
32+
package
33+
);
34+
}
35+
}
36+
}
37+
38+
(opts, rustflags, rls_config.clear_env_rust_log)
39+
};
40+
}

tests/target/issue-3295/two.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// rustfmt-version: Two
2+
pub enum TestEnum {
3+
a,
4+
b,
5+
}
6+
7+
fn the_test(input: TestEnum) {
8+
match input {
9+
TestEnum::a => String::from("aaa"),
10+
TestEnum::b => String::from(
11+
"this is a very very very very very very very very very very very very very very very ong string",
12+
),
13+
};
14+
}

0 commit comments

Comments
 (0)