Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit29c8e7f

Browse files
committed
Fix character split when strip code
1 parentdd3a5ca commit29c8e7f

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

‎src/formatter/mod.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
cmp,
33
fmt::{self,Display,Write},
4+
iter::once,
45
};
56

67
pubmod style;
@@ -217,16 +218,21 @@ impl<'a> DisplayList<'a> {
217218
}else{
218219
false
219220
};
221+
letmut ended =false;
220222
let range = text
221223
.char_indices()
224+
.chain(once((text.len(),'\0')))
222225
.skip(left)
223226
.take_while(|(_, ch)|{
227+
if ended{
228+
returnfalse;
229+
}
224230
// Make sure that the trimming on the right will fall within the terminal width.
225231
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is.
226232
// For now, just accept that sometimes the code line will be longer than desired.
227233
taken += unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1);
228234
if taken > right - left{
229-
returnfalse;
235+
ended =true;
230236
}
231237
true
232238
})
@@ -238,7 +244,7 @@ impl<'a> DisplayList<'a> {
238244
}
239245
});
240246

241-
text[range.0.expect("One character at line")..=range.1].fmt(f)?;
247+
text[range.0.expect("One character at line")..range.1].fmt(f)?;
242248

243249
if cut_right{
244250
// We have stripped some code after the right-most span end, make it clear we did so.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[title]
2+
id ="E0308"
3+
label ="mismatched types"
4+
annotation_type ="Error"
5+
6+
[[slices]]
7+
source =" let _: () = 42ñ"
8+
line_start =4
9+
origin ="$DIR/whitespace-trimming.rs"
10+
11+
[[slices.annotations]]
12+
label ="expected (), found integer"
13+
annotation_type ="Error"
14+
range = [192,194]
15+
16+
[opt]
17+
color =false
18+
anonymized_line_numbers =true
19+
[opt.margin]
20+
whitespace_left =180
21+
span_left =192
22+
span_right =194
23+
label_right =221
24+
column_width =140
25+
max_line_len =195
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/whitespace-trimming.rs:4:193
3+
|
4+
LL | ... let _: () = 42ñ
5+
| ^^ expected (), found integer
6+
|

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp