Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cce2db0

Browse files
authoredJul 25, 2024
Rollup merge of #127528 - estebank:ascii-control-chars, r=oli-obk
Replace ASCII control chars with Unicode Control Pictures Replace ASCII control chars like `CR` with Unicode Control Pictures like `␍`: ``` error: bare CR not allowed in doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32 | LL | /// doc comment with bare CR: '␍' | ^ ``` Centralize the checking of unicode char width for the purposes of CLI display in one place. Account for the new replacements. Remove unneeded tracking of "zero-width" unicode chars, as we calculate these in the `SourceMap` as needed now.
2 parents cfc5f25 + 9bd7680 commit cce2db0

File tree

67 files changed

+216
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+216
-308
lines changed
 

‎compiler/rustc_query_system/src/ich/impls_syntax.rs

-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
7373
source_len: _,
7474
lines: _,
7575
ref multibyte_chars,
76-
ref non_narrow_chars,
7776
ref normalized_pos,
7877
} = *self;
7978

@@ -98,11 +97,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
9897
char_pos.hash_stable(hcx, hasher);
9998
}
10099

101-
non_narrow_chars.len().hash_stable(hcx, hasher);
102-
for &char_pos in non_narrow_chars.iter() {
103-
char_pos.hash_stable(hcx, hasher);
104-
}
105-
106100
normalized_pos.len().hash_stable(hcx, hasher);
107101
for &char_pos in normalized_pos.iter() {
108102
char_pos.hash_stable(hcx, hasher);

‎compiler/rustc_span/src/analyze_source_file.rs

+6-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::*;
2-
use unicode_width::UnicodeWidthChar;
32

43
#[cfg(test)]
54
mod tests;
@@ -9,15 +8,12 @@ mod tests;
98
///
109
/// This function will use an SSE2 enhanced implementation if hardware support
1110
/// is detected at runtime.
12-
pub fn analyze_source_file(
13-
src: &str,
14-
) -> (Vec<RelativeBytePos>, Vec<MultiByteChar>, Vec<NonNarrowChar>) {
11+
pub fn analyze_source_file(src: &str) -> (Vec<RelativeBytePos>, Vec<MultiByteChar>) {
1512
let mut lines = vec![RelativeBytePos::from_u32(0)];
1613
let mut multi_byte_chars = vec![];
17-
let mut non_narrow_chars = vec![];
1814

1915
// Calls the right implementation, depending on hardware support available.
20-
analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars, &mut non_narrow_chars);
16+
analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars);
2117

2218
// The code above optimistically registers a new line *after* each \n
2319
// it encounters. If that point is already outside the source_file, remove
@@ -30,7 +26,7 @@ pub fn analyze_source_file(
3026
}
3127
}
3228

33-
(lines, multi_byte_chars, non_narrow_chars)
29+
(lines, multi_byte_chars)
3430
}
3531

3632
cfg_match! {
@@ -39,11 +35,10 @@ cfg_match! {
3935
src: &str,
4036
lines: &mut Vec<RelativeBytePos>,
4137
multi_byte_chars: &mut Vec<MultiByteChar>,
42-
non_narrow_chars: &mut Vec<NonNarrowChar>,
4338
) {
4439
if is_x86_feature_detected!("sse2") {
4540
unsafe {
46-
analyze_source_file_sse2(src, lines, multi_byte_chars, non_narrow_chars);
41+
analyze_source_file_sse2(src, lines, multi_byte_chars);
4742
}
4843
} else {
4944
analyze_source_file_generic(
@@ -52,7 +47,6 @@ cfg_match! {
5247
RelativeBytePos::from_u32(0),
5348
lines,
5449
multi_byte_chars,
55-
non_narrow_chars,
5650
);
5751
}
5852
}
@@ -66,7 +60,6 @@ cfg_match! {
6660
src: &str,
6761
lines: &mut Vec<RelativeBytePos>,
6862
multi_byte_chars: &mut Vec<MultiByteChar>,
69-
non_narrow_chars: &mut Vec<NonNarrowChar>,
7063
) {
7164
#[cfg(target_arch = "x86")]
7265
use std::arch::x86::*;
@@ -159,7 +152,6 @@ cfg_match! {
159152
RelativeBytePos::from_usize(scan_start),
160153
lines,
161154
multi_byte_chars,
162-
non_narrow_chars,
163155
);
164156
}
165157

@@ -172,7 +164,6 @@ cfg_match! {
172164
RelativeBytePos::from_usize(tail_start),
173165
lines,
174166
multi_byte_chars,
175-
non_narrow_chars,
176167
);
177168
}
178169
}
@@ -183,15 +174,13 @@ cfg_match! {
183174
src: &str,
184175
lines: &mut Vec<RelativeBytePos>,
185176
multi_byte_chars: &mut Vec<MultiByteChar>,
186-
non_narrow_chars: &mut Vec<NonNarrowChar>,
187177
) {
188178
analyze_source_file_generic(
189179
src,
190180
src.len(),
191181
RelativeBytePos::from_u32(0),
192182
lines,
193183
multi_byte_chars,
194-
non_narrow_chars,
195184
);
196185
}
197186
}
@@ -205,7 +194,6 @@ fn analyze_source_file_generic(
205194
output_offset: RelativeBytePos,
206195
lines: &mut Vec<RelativeBytePos>,
207196
multi_byte_chars: &mut Vec<MultiByteChar>,
208-
non_narrow_chars: &mut Vec<NonNarrowChar>,
209197
) -> usize {
210198
assert!(src.len() >= scan_len);
211199
let mut i = 0;
@@ -227,16 +215,8 @@ fn analyze_source_file_generic(
227215

228216
let pos = RelativeBytePos::from_usize(i) + output_offset;
229217

230-
match byte {
231-
b'\n' => {
232-
lines.push(pos + RelativeBytePos(1));
233-
}
234-
b'\t' => {
235-
non_narrow_chars.push(NonNarrowChar::Tab(pos));
236-
}
237-
_ => {
238-
non_narrow_chars.push(NonNarrowChar::ZeroWidth(pos));
239-
}
218+
if let b'\n' = byte {
219+
lines.push(pos + RelativeBytePos(1));
240220
}
241221
} else if byte >= 127 {
242222
// The slow path:
@@ -252,14 +232,6 @@ fn analyze_source_file_generic(
252232
let mbc = MultiByteChar { pos, bytes: char_len as u8 };
253233
multi_byte_chars.push(mbc);
254234
}
255-
256-
// Assume control characters are zero width.
257-
// FIXME: How can we decide between `width` and `width_cjk`?
258-
let char_width = UnicodeWidthChar::width(c).unwrap_or(0);
259-
260-
if char_width != 1 {
261-
non_narrow_chars.push(NonNarrowChar::new(pos, char_width));
262-
}
263235
}
264236

265237
i += char_len;
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.