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.
This commit is contained in:
Matthias Krüger 2024-07-25 04:43:19 +02:00 committed by GitHub
commit cce2db06c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
67 changed files with 216 additions and 308 deletions

View file

@ -3882,7 +3882,6 @@ dependencies = [
"termcolor", "termcolor",
"termize", "termize",
"tracing", "tracing",
"unicode-width",
"windows", "windows",
] ]

View file

@ -26,7 +26,6 @@ serde_json = "1.0.59"
termcolor = "1.2.0" termcolor = "1.2.0"
termize = "0.1.1" termize = "0.1.1"
tracing = "0.1" tracing = "0.1"
unicode-width = "0.1.4"
# tidy-alphabetical-end # tidy-alphabetical-end
[target.'cfg(windows)'.dependencies.windows] [target.'cfg(windows)'.dependencies.windows]

View file

@ -8,7 +8,7 @@
//! The output types are defined in `rustc_session::config::ErrorOutputType`. //! The output types are defined in `rustc_session::config::ErrorOutputType`.
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
use rustc_span::{FileLines, FileName, SourceFile, Span}; use rustc_span::{char_width, FileLines, FileName, SourceFile, Span};
use crate::snippet::{ use crate::snippet::{
Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString, Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
@ -677,10 +677,7 @@ impl HumanEmitter {
.skip(left) .skip(left)
.take_while(|ch| { .take_while(|ch| {
// Make sure that the trimming on the right will fall within the terminal width. // Make sure that the trimming on the right will fall within the terminal width.
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` let next = char_width(*ch);
// is. For now, just accept that sometimes the code line will be longer than
// desired.
let next = unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1);
if taken + next > right - left { if taken + next > right - left {
return false; return false;
} }
@ -742,11 +739,7 @@ impl HumanEmitter {
let left = margin.left(source_string.len()); let left = margin.left(source_string.len());
// Account for unicode characters of width !=0 that were removed. // Account for unicode characters of width !=0 that were removed.
let left = source_string let left = source_string.chars().take(left).map(|ch| char_width(ch)).sum();
.chars()
.take(left)
.map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1))
.sum();
self.draw_line( self.draw_line(
buffer, buffer,
@ -2039,7 +2032,7 @@ impl HumanEmitter {
let sub_len: usize = let sub_len: usize =
if is_whitespace_addition { &part.snippet } else { part.snippet.trim() } if is_whitespace_addition { &part.snippet } else { part.snippet.trim() }
.chars() .chars()
.map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) .map(|ch| char_width(ch))
.sum(); .sum();
let offset: isize = offsets let offset: isize = offsets
@ -2076,11 +2069,8 @@ impl HumanEmitter {
} }
// length of the code after substitution // length of the code after substitution
let full_sub_len = part let full_sub_len =
.snippet part.snippet.chars().map(|ch| char_width(ch)).sum::<usize>() as isize;
.chars()
.map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1))
.sum::<usize>() as isize;
// length of the code to be substituted // length of the code to be substituted
let snippet_len = span_end_pos as isize - span_start_pos as isize; let snippet_len = span_end_pos as isize - span_start_pos as isize;
@ -2568,18 +2558,53 @@ fn num_decimal_digits(num: usize) -> usize {
} }
// We replace some characters so the CLI output is always consistent and underlines aligned. // We replace some characters so the CLI output is always consistent and underlines aligned.
// Keep the following list in sync with `rustc_span::char_width`.
const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
('\t', " "), // We do our own tab replacement ('\t', " "), // We do our own tab replacement
('\u{200D}', ""), // Replace ZWJ with nothing for consistent terminal output of grapheme clusters. ('\u{200D}', ""), // Replace ZWJ with nothing for consistent terminal output of grapheme clusters.
('\u{202A}', ""), // The following unicode text flow control characters are inconsistently ('\u{202A}', "<EFBFBD>"), // The following unicode text flow control characters are inconsistently
('\u{202B}', ""), // supported across CLIs and can cause confusion due to the bytes on disk ('\u{202B}', "<EFBFBD>"), // supported across CLIs and can cause confusion due to the bytes on disk
('\u{202D}', ""), // not corresponding to the visible source code, so we replace them always. ('\u{202D}', "<EFBFBD>"), // not corresponding to the visible source code, so we replace them always.
('\u{202E}', ""), ('\u{202E}', "<EFBFBD>"),
('\u{2066}', ""), ('\u{2066}', "<EFBFBD>"),
('\u{2067}', ""), ('\u{2067}', "<EFBFBD>"),
('\u{2068}', ""), ('\u{2068}', "<EFBFBD>"),
('\u{202C}', ""), ('\u{202C}', "<EFBFBD>"),
('\u{2069}', ""), ('\u{2069}', "<EFBFBD>"),
// In terminals without Unicode support the following will be garbled, but in *all* terminals
// the underlying codepoint will be as well. We could gate this replacement behind a "unicode
// support" gate.
('\u{0000}', ""),
('\u{0001}', ""),
('\u{0002}', ""),
('\u{0003}', ""),
('\u{0004}', ""),
('\u{0005}', ""),
('\u{0006}', ""),
('\u{0007}', ""),
('\u{0008}', ""),
('\u{000B}', ""),
('\u{000C}', ""),
('\u{000D}', ""),
('\u{000E}', ""),
('\u{000F}', ""),
('\u{0010}', ""),
('\u{0011}', ""),
('\u{0012}', ""),
('\u{0013}', ""),
('\u{0014}', ""),
('\u{0015}', ""),
('\u{0016}', ""),
('\u{0017}', ""),
('\u{0018}', ""),
('\u{0019}', ""),
('\u{001A}', ""),
('\u{001B}', ""),
('\u{001C}', ""),
('\u{001D}', ""),
('\u{001E}', ""),
('\u{001F}', ""),
('\u{007F}', ""),
]; ];
fn normalize_whitespace(str: &str) -> String { fn normalize_whitespace(str: &str) -> String {

View file

@ -1728,7 +1728,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
source_len, source_len,
lines, lines,
multibyte_chars, multibyte_chars,
non_narrow_chars,
normalized_pos, normalized_pos,
stable_id, stable_id,
.. ..
@ -1780,7 +1779,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
self.cnum, self.cnum,
lines, lines,
multibyte_chars, multibyte_chars,
non_narrow_chars,
normalized_pos, normalized_pos,
source_file_index, source_file_index,
); );

View file

@ -73,7 +73,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
source_len: _, source_len: _,
lines: _, lines: _,
ref multibyte_chars, ref multibyte_chars,
ref non_narrow_chars,
ref normalized_pos, ref normalized_pos,
} = *self; } = *self;
@ -98,11 +97,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
char_pos.hash_stable(hcx, hasher); char_pos.hash_stable(hcx, hasher);
} }
non_narrow_chars.len().hash_stable(hcx, hasher);
for &char_pos in non_narrow_chars.iter() {
char_pos.hash_stable(hcx, hasher);
}
normalized_pos.len().hash_stable(hcx, hasher); normalized_pos.len().hash_stable(hcx, hasher);
for &char_pos in normalized_pos.iter() { for &char_pos in normalized_pos.iter() {
char_pos.hash_stable(hcx, hasher); char_pos.hash_stable(hcx, hasher);

View file

@ -1,5 +1,4 @@
use super::*; use super::*;
use unicode_width::UnicodeWidthChar;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
@ -9,15 +8,12 @@ mod tests;
/// ///
/// This function will use an SSE2 enhanced implementation if hardware support /// This function will use an SSE2 enhanced implementation if hardware support
/// is detected at runtime. /// is detected at runtime.
pub fn analyze_source_file( pub fn analyze_source_file(src: &str) -> (Vec<RelativeBytePos>, Vec<MultiByteChar>) {
src: &str,
) -> (Vec<RelativeBytePos>, Vec<MultiByteChar>, Vec<NonNarrowChar>) {
let mut lines = vec![RelativeBytePos::from_u32(0)]; let mut lines = vec![RelativeBytePos::from_u32(0)];
let mut multi_byte_chars = vec![]; let mut multi_byte_chars = vec![];
let mut non_narrow_chars = vec![];
// Calls the right implementation, depending on hardware support available. // Calls the right implementation, depending on hardware support available.
analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars, &mut non_narrow_chars); analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars);
// The code above optimistically registers a new line *after* each \n // The code above optimistically registers a new line *after* each \n
// it encounters. If that point is already outside the source_file, remove // it encounters. If that point is already outside the source_file, remove
@ -30,7 +26,7 @@ pub fn analyze_source_file(
} }
} }
(lines, multi_byte_chars, non_narrow_chars) (lines, multi_byte_chars)
} }
cfg_match! { cfg_match! {
@ -39,11 +35,10 @@ cfg_match! {
src: &str, src: &str,
lines: &mut Vec<RelativeBytePos>, lines: &mut Vec<RelativeBytePos>,
multi_byte_chars: &mut Vec<MultiByteChar>, multi_byte_chars: &mut Vec<MultiByteChar>,
non_narrow_chars: &mut Vec<NonNarrowChar>,
) { ) {
if is_x86_feature_detected!("sse2") { if is_x86_feature_detected!("sse2") {
unsafe { unsafe {
analyze_source_file_sse2(src, lines, multi_byte_chars, non_narrow_chars); analyze_source_file_sse2(src, lines, multi_byte_chars);
} }
} else { } else {
analyze_source_file_generic( analyze_source_file_generic(
@ -52,7 +47,6 @@ cfg_match! {
RelativeBytePos::from_u32(0), RelativeBytePos::from_u32(0),
lines, lines,
multi_byte_chars, multi_byte_chars,
non_narrow_chars,
); );
} }
} }
@ -66,7 +60,6 @@ cfg_match! {
src: &str, src: &str,
lines: &mut Vec<RelativeBytePos>, lines: &mut Vec<RelativeBytePos>,
multi_byte_chars: &mut Vec<MultiByteChar>, multi_byte_chars: &mut Vec<MultiByteChar>,
non_narrow_chars: &mut Vec<NonNarrowChar>,
) { ) {
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
use std::arch::x86::*; use std::arch::x86::*;
@ -159,7 +152,6 @@ cfg_match! {
RelativeBytePos::from_usize(scan_start), RelativeBytePos::from_usize(scan_start),
lines, lines,
multi_byte_chars, multi_byte_chars,
non_narrow_chars,
); );
} }
@ -172,7 +164,6 @@ cfg_match! {
RelativeBytePos::from_usize(tail_start), RelativeBytePos::from_usize(tail_start),
lines, lines,
multi_byte_chars, multi_byte_chars,
non_narrow_chars,
); );
} }
} }
@ -183,7 +174,6 @@ cfg_match! {
src: &str, src: &str,
lines: &mut Vec<RelativeBytePos>, lines: &mut Vec<RelativeBytePos>,
multi_byte_chars: &mut Vec<MultiByteChar>, multi_byte_chars: &mut Vec<MultiByteChar>,
non_narrow_chars: &mut Vec<NonNarrowChar>,
) { ) {
analyze_source_file_generic( analyze_source_file_generic(
src, src,
@ -191,7 +181,6 @@ cfg_match! {
RelativeBytePos::from_u32(0), RelativeBytePos::from_u32(0),
lines, lines,
multi_byte_chars, multi_byte_chars,
non_narrow_chars,
); );
} }
} }
@ -205,7 +194,6 @@ fn analyze_source_file_generic(
output_offset: RelativeBytePos, output_offset: RelativeBytePos,
lines: &mut Vec<RelativeBytePos>, lines: &mut Vec<RelativeBytePos>,
multi_byte_chars: &mut Vec<MultiByteChar>, multi_byte_chars: &mut Vec<MultiByteChar>,
non_narrow_chars: &mut Vec<NonNarrowChar>,
) -> usize { ) -> usize {
assert!(src.len() >= scan_len); assert!(src.len() >= scan_len);
let mut i = 0; let mut i = 0;
@ -227,16 +215,8 @@ fn analyze_source_file_generic(
let pos = RelativeBytePos::from_usize(i) + output_offset; let pos = RelativeBytePos::from_usize(i) + output_offset;
match byte { if let b'\n' = byte {
b'\n' => { lines.push(pos + RelativeBytePos(1));
lines.push(pos + RelativeBytePos(1));
}
b'\t' => {
non_narrow_chars.push(NonNarrowChar::Tab(pos));
}
_ => {
non_narrow_chars.push(NonNarrowChar::ZeroWidth(pos));
}
} }
} else if byte >= 127 { } else if byte >= 127 {
// The slow path: // The slow path:
@ -252,14 +232,6 @@ fn analyze_source_file_generic(
let mbc = MultiByteChar { pos, bytes: char_len as u8 }; let mbc = MultiByteChar { pos, bytes: char_len as u8 };
multi_byte_chars.push(mbc); multi_byte_chars.push(mbc);
} }
// Assume control characters are zero width.
// FIXME: How can we decide between `width` and `width_cjk`?
let char_width = UnicodeWidthChar::width(c).unwrap_or(0);
if char_width != 1 {
non_narrow_chars.push(NonNarrowChar::new(pos, char_width));
}
} }
i += char_len; i += char_len;

View file

@ -4,11 +4,10 @@ macro_rules! test {
(case: $test_name:ident, (case: $test_name:ident,
text: $text:expr, text: $text:expr,
lines: $lines:expr, lines: $lines:expr,
multi_byte_chars: $multi_byte_chars:expr, multi_byte_chars: $multi_byte_chars:expr,) => {
non_narrow_chars: $non_narrow_chars:expr,) => {
#[test] #[test]
fn $test_name() { fn $test_name() {
let (lines, multi_byte_chars, non_narrow_chars) = analyze_source_file($text); let (lines, multi_byte_chars) = analyze_source_file($text);
let expected_lines: Vec<RelativeBytePos> = let expected_lines: Vec<RelativeBytePos> =
$lines.into_iter().map(RelativeBytePos).collect(); $lines.into_iter().map(RelativeBytePos).collect();
@ -21,13 +20,6 @@ macro_rules! test {
.collect(); .collect();
assert_eq!(multi_byte_chars, expected_mbcs); assert_eq!(multi_byte_chars, expected_mbcs);
let expected_nncs: Vec<NonNarrowChar> = $non_narrow_chars
.into_iter()
.map(|(pos, width)| NonNarrowChar::new(RelativeBytePos(pos), width))
.collect();
assert_eq!(non_narrow_chars, expected_nncs);
} }
}; };
} }
@ -37,7 +29,6 @@ test!(
text: "", text: "",
lines: vec![], lines: vec![],
multi_byte_chars: vec![], multi_byte_chars: vec![],
non_narrow_chars: vec![],
); );
test!( test!(
@ -45,7 +36,6 @@ test!(
text: "a\nc", text: "a\nc",
lines: vec![0, 2], lines: vec![0, 2],
multi_byte_chars: vec![], multi_byte_chars: vec![],
non_narrow_chars: vec![],
); );
test!( test!(
@ -53,7 +43,6 @@ test!(
text: "012345678\nabcdef012345678\na", text: "012345678\nabcdef012345678\na",
lines: vec![0, 10, 26], lines: vec![0, 10, 26],
multi_byte_chars: vec![], multi_byte_chars: vec![],
non_narrow_chars: vec![],
); );
test!( test!(
@ -61,7 +50,6 @@ test!(
text: "01234β789\nbcdef0123456789abcdef", text: "01234β789\nbcdef0123456789abcdef",
lines: vec![0, 11], lines: vec![0, 11],
multi_byte_chars: vec![(5, 2)], multi_byte_chars: vec![(5, 2)],
non_narrow_chars: vec![],
); );
test!( test!(
@ -69,7 +57,6 @@ test!(
text: "01234\u{07}6789\nbcdef0123456789abcdef", text: "01234\u{07}6789\nbcdef0123456789abcdef",
lines: vec![0, 11], lines: vec![0, 11],
multi_byte_chars: vec![], multi_byte_chars: vec![],
non_narrow_chars: vec![(5, 0)],
); );
test!( test!(
@ -77,7 +64,6 @@ test!(
text: "aβc", text: "aβc",
lines: vec![0], lines: vec![0],
multi_byte_chars: vec![(1, 2)], multi_byte_chars: vec![(1, 2)],
non_narrow_chars: vec![],
); );
test!( test!(
@ -85,7 +71,6 @@ test!(
text: "0123456789abcΔf012345β", text: "0123456789abcΔf012345β",
lines: vec![0], lines: vec![0],
multi_byte_chars: vec![(13, 2), (22, 2)], multi_byte_chars: vec![(13, 2), (22, 2)],
non_narrow_chars: vec![],
); );
test!( test!(
@ -93,7 +78,6 @@ test!(
text: "0123456789abcdeΔ123456789abcdef01234", text: "0123456789abcdeΔ123456789abcdef01234",
lines: vec![0], lines: vec![0],
multi_byte_chars: vec![(15, 2)], multi_byte_chars: vec![(15, 2)],
non_narrow_chars: vec![],
); );
test!( test!(
@ -101,7 +85,6 @@ test!(
text: "0123456789abcdeΔ....", text: "0123456789abcdeΔ....",
lines: vec![0], lines: vec![0],
multi_byte_chars: vec![(15, 2)], multi_byte_chars: vec![(15, 2)],
non_narrow_chars: vec![],
); );
test!( test!(
@ -109,7 +92,6 @@ test!(
text: "0\t2", text: "0\t2",
lines: vec![0], lines: vec![0],
multi_byte_chars: vec![], multi_byte_chars: vec![],
non_narrow_chars: vec![(1, 4)],
); );
test!( test!(
@ -117,7 +99,6 @@ test!(
text: "01\t3456789abcdef01234567\u{07}9", text: "01\t3456789abcdef01234567\u{07}9",
lines: vec![0], lines: vec![0],
multi_byte_chars: vec![], multi_byte_chars: vec![],
non_narrow_chars: vec![(2, 4), (24, 0)],
); );
test!( test!(
@ -125,5 +106,4 @@ test!(
text: "01\t345\n789abcΔf01234567\u{07}9\nbcΔf", text: "01\t345\n789abcΔf01234567\u{07}9\nbcΔf",
lines: vec![0, 7, 27], lines: vec![0, 7, 27],
multi_byte_chars: vec![(13, 2), (29, 2)], multi_byte_chars: vec![(13, 2), (29, 2)],
non_narrow_chars: vec![(2, 4), (24, 0)],
); );

View file

@ -1345,68 +1345,6 @@ pub struct MultiByteChar {
pub bytes: u8, pub bytes: u8,
} }
/// Identifies an offset of a non-narrow character in a `SourceFile`.
#[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug, HashStable_Generic)]
pub enum NonNarrowChar {
/// Represents a zero-width character.
ZeroWidth(RelativeBytePos),
/// Represents a wide (full-width) character.
Wide(RelativeBytePos),
/// Represents a tab character, represented visually with a width of 4 characters.
Tab(RelativeBytePos),
}
impl NonNarrowChar {
fn new(pos: RelativeBytePos, width: usize) -> Self {
match width {
0 => NonNarrowChar::ZeroWidth(pos),
2 => NonNarrowChar::Wide(pos),
4 => NonNarrowChar::Tab(pos),
_ => panic!("width {width} given for non-narrow character"),
}
}
/// Returns the relative offset of the character in the `SourceFile`.
pub fn pos(&self) -> RelativeBytePos {
match *self {
NonNarrowChar::ZeroWidth(p) | NonNarrowChar::Wide(p) | NonNarrowChar::Tab(p) => p,
}
}
/// Returns the width of the character, 0 (zero-width) or 2 (wide).
pub fn width(&self) -> usize {
match *self {
NonNarrowChar::ZeroWidth(_) => 0,
NonNarrowChar::Wide(_) => 2,
NonNarrowChar::Tab(_) => 4,
}
}
}
impl Add<RelativeBytePos> for NonNarrowChar {
type Output = Self;
fn add(self, rhs: RelativeBytePos) -> Self {
match self {
NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos + rhs),
NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos + rhs),
NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos + rhs),
}
}
}
impl Sub<RelativeBytePos> for NonNarrowChar {
type Output = Self;
fn sub(self, rhs: RelativeBytePos) -> Self {
match self {
NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos - rhs),
NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos - rhs),
NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos - rhs),
}
}
}
/// Identifies an offset of a character that was normalized away from `SourceFile`. /// Identifies an offset of a character that was normalized away from `SourceFile`.
#[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug, HashStable_Generic)] #[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug, HashStable_Generic)]
pub struct NormalizedPos { pub struct NormalizedPos {
@ -1581,8 +1519,6 @@ pub struct SourceFile {
pub lines: FreezeLock<SourceFileLines>, pub lines: FreezeLock<SourceFileLines>,
/// Locations of multi-byte characters in the source code. /// Locations of multi-byte characters in the source code.
pub multibyte_chars: Vec<MultiByteChar>, pub multibyte_chars: Vec<MultiByteChar>,
/// Width of characters that are not narrow in the source code.
pub non_narrow_chars: Vec<NonNarrowChar>,
/// Locations of characters removed during normalization. /// Locations of characters removed during normalization.
pub normalized_pos: Vec<NormalizedPos>, pub normalized_pos: Vec<NormalizedPos>,
/// A hash of the filename & crate-id, used for uniquely identifying source /// A hash of the filename & crate-id, used for uniquely identifying source
@ -1604,7 +1540,6 @@ impl Clone for SourceFile {
source_len: self.source_len, source_len: self.source_len,
lines: self.lines.clone(), lines: self.lines.clone(),
multibyte_chars: self.multibyte_chars.clone(), multibyte_chars: self.multibyte_chars.clone(),
non_narrow_chars: self.non_narrow_chars.clone(),
normalized_pos: self.normalized_pos.clone(), normalized_pos: self.normalized_pos.clone(),
stable_id: self.stable_id, stable_id: self.stable_id,
cnum: self.cnum, cnum: self.cnum,
@ -1679,7 +1614,6 @@ impl<S: SpanEncoder> Encodable<S> for SourceFile {
} }
self.multibyte_chars.encode(s); self.multibyte_chars.encode(s);
self.non_narrow_chars.encode(s);
self.stable_id.encode(s); self.stable_id.encode(s);
self.normalized_pos.encode(s); self.normalized_pos.encode(s);
self.cnum.encode(s); self.cnum.encode(s);
@ -1706,7 +1640,6 @@ impl<D: SpanDecoder> Decodable<D> for SourceFile {
} }
}; };
let multibyte_chars: Vec<MultiByteChar> = Decodable::decode(d); let multibyte_chars: Vec<MultiByteChar> = Decodable::decode(d);
let non_narrow_chars: Vec<NonNarrowChar> = Decodable::decode(d);
let stable_id = Decodable::decode(d); let stable_id = Decodable::decode(d);
let normalized_pos: Vec<NormalizedPos> = Decodable::decode(d); let normalized_pos: Vec<NormalizedPos> = Decodable::decode(d);
let cnum: CrateNum = Decodable::decode(d); let cnum: CrateNum = Decodable::decode(d);
@ -1721,7 +1654,6 @@ impl<D: SpanDecoder> Decodable<D> for SourceFile {
external_src: FreezeLock::frozen(ExternalSource::Unneeded), external_src: FreezeLock::frozen(ExternalSource::Unneeded),
lines: FreezeLock::new(lines), lines: FreezeLock::new(lines),
multibyte_chars, multibyte_chars,
non_narrow_chars,
normalized_pos, normalized_pos,
stable_id, stable_id,
cnum, cnum,
@ -1809,8 +1741,7 @@ impl SourceFile {
let source_len = src.len(); let source_len = src.len();
let source_len = u32::try_from(source_len).map_err(|_| OffsetOverflowError)?; let source_len = u32::try_from(source_len).map_err(|_| OffsetOverflowError)?;
let (lines, multibyte_chars, non_narrow_chars) = let (lines, multibyte_chars) = analyze_source_file::analyze_source_file(&src);
analyze_source_file::analyze_source_file(&src);
Ok(SourceFile { Ok(SourceFile {
name, name,
@ -1821,7 +1752,6 @@ impl SourceFile {
source_len: RelativeBytePos::from_u32(source_len), source_len: RelativeBytePos::from_u32(source_len),
lines: FreezeLock::frozen(SourceFileLines::Lines(lines)), lines: FreezeLock::frozen(SourceFileLines::Lines(lines)),
multibyte_chars, multibyte_chars,
non_narrow_chars,
normalized_pos, normalized_pos,
stable_id, stable_id,
cnum: LOCAL_CRATE, cnum: LOCAL_CRATE,
@ -2130,41 +2060,45 @@ impl SourceFile {
let pos = self.relative_position(pos); let pos = self.relative_position(pos);
let (line, col_or_chpos) = self.lookup_file_pos(pos); let (line, col_or_chpos) = self.lookup_file_pos(pos);
if line > 0 { if line > 0 {
let col = col_or_chpos; let Some(code) = self.get_line(line - 1) else {
let linebpos = self.lines()[line - 1]; // If we don't have the code available, it is ok as a fallback to return the bytepos
let col_display = { // instead of the "display" column, which is only used to properly show underlines
let start_width_idx = self // in the terminal.
.non_narrow_chars // FIXME: we'll want better handling of this in the future for the sake of tools
.binary_search_by_key(&linebpos, |x| x.pos()) // that want to use the display col instead of byte offsets to modify Rust code, but
.unwrap_or_else(|x| x); // that is a problem for another day, the previous code was already incorrect for
let end_width_idx = self // both displaying *and* third party tools using the json output naïvely.
.non_narrow_chars tracing::info!("couldn't find line {line} {:?}", self.name);
.binary_search_by_key(&pos, |x| x.pos()) return (line, col_or_chpos, col_or_chpos.0);
.unwrap_or_else(|x| x);
let special_chars = end_width_idx - start_width_idx;
let non_narrow: usize = self.non_narrow_chars[start_width_idx..end_width_idx]
.iter()
.map(|x| x.width())
.sum();
col.0 - special_chars + non_narrow
}; };
(line, col, col_display) let display_col = code.chars().take(col_or_chpos.0).map(|ch| char_width(ch)).sum();
(line, col_or_chpos, display_col)
} else { } else {
let chpos = col_or_chpos; // This is never meant to happen?
let col_display = { (0, col_or_chpos, col_or_chpos.0)
let end_width_idx = self
.non_narrow_chars
.binary_search_by_key(&pos, |x| x.pos())
.unwrap_or_else(|x| x);
let non_narrow: usize =
self.non_narrow_chars[0..end_width_idx].iter().map(|x| x.width()).sum();
chpos.0 - end_width_idx + non_narrow
};
(0, chpos, col_display)
} }
} }
} }
pub fn char_width(ch: char) -> usize {
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. For now,
// just accept that sometimes the code line will be longer than desired.
match ch {
'\t' => 4,
// Keep the following list in sync with `rustc_errors::emitter::OUTPUT_REPLACEMENTS`. These
// are control points that we replace before printing with a visible codepoint for the sake
// of being able to point at them with underlines.
'\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}'
| '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}'
| '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}'
| '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}'
| '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}'
| '\u{007F}' | '\u{202A}' | '\u{202B}' | '\u{202D}' | '\u{202E}' | '\u{2066}'
| '\u{2067}' | '\u{2068}' | '\u{202C}' | '\u{2069}' => 1,
_ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1),
}
}
/// Normalizes the source code and records the normalizations. /// Normalizes the source code and records the normalizations.
fn normalize_src(src: &mut String) -> Vec<NormalizedPos> { fn normalize_src(src: &mut String) -> Vec<NormalizedPos> {
let mut normalized_pos = vec![]; let mut normalized_pos = vec![];

View file

@ -330,7 +330,6 @@ impl SourceMap {
cnum: CrateNum, cnum: CrateNum,
file_local_lines: FreezeLock<SourceFileLines>, file_local_lines: FreezeLock<SourceFileLines>,
multibyte_chars: Vec<MultiByteChar>, multibyte_chars: Vec<MultiByteChar>,
non_narrow_chars: Vec<NonNarrowChar>,
normalized_pos: Vec<NormalizedPos>, normalized_pos: Vec<NormalizedPos>,
metadata_index: u32, metadata_index: u32,
) -> Lrc<SourceFile> { ) -> Lrc<SourceFile> {
@ -348,7 +347,6 @@ impl SourceMap {
source_len, source_len,
lines: file_local_lines, lines: file_local_lines,
multibyte_chars, multibyte_chars,
non_narrow_chars,
normalized_pos, normalized_pos,
stable_id, stable_id,
cnum, cnum,

View file

@ -232,7 +232,6 @@ fn t10() {
source_len, source_len,
lines, lines,
multibyte_chars, multibyte_chars,
non_narrow_chars,
normalized_pos, normalized_pos,
stable_id, stable_id,
.. ..
@ -246,7 +245,6 @@ fn t10() {
CrateNum::ZERO, CrateNum::ZERO,
FreezeLock::new(lines.read().clone()), FreezeLock::new(lines.read().clone()),
multibyte_chars, multibyte_chars,
non_narrow_chars,
normalized_pos, normalized_pos,
0, 0,
); );

View file

@ -2,7 +2,7 @@ error[E0765]: unterminated double quote string
--> $DIR/test-compile-fail3.rs:3:1 --> $DIR/test-compile-fail3.rs:3:1
| |
3 | "fail 3 | "fail
| ^^^^^^ | ^^^^^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -4,7 +4,7 @@ error[E0765]: unterminated double quote string
LL | """; LL | """;
| ___________________^ | ___________________^
LL | | } LL | | }
| |__^ | |_^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -2,7 +2,7 @@ error[E0601]: `main` function not found in crate `E0601`
--> $DIR/E0601.rs:1:37 --> $DIR/E0601.rs:1:37
| |
LL | LL |
| ^ consider adding a `main` function to `$DIR/E0601.rs` | ^ consider adding a `main` function to `$DIR/E0601.rs`
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -4,7 +4,7 @@ error[E0765]: unterminated double quote string
LL | "😊""; LL | "😊"";
| _________^ | _________^
LL | | } LL | | }
| |__^ | |_^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,31 +1,31 @@
error: bare CR not allowed in doc-comment error: bare CR not allowed in doc-comment
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32 --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32
| |
LL | /// doc comment with bare CR: ' ' LL | /// doc comment with bare CR: ''
| ^ | ^
error: bare CR not allowed in block doc-comment error: bare CR not allowed in block doc-comment
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:7:38 --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:7:38
| |
LL | /** block doc comment with bare CR: ' ' */ LL | /** block doc comment with bare CR: '' */
| ^ | ^
error: bare CR not allowed in doc-comment error: bare CR not allowed in doc-comment
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:12:36 --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:12:36
| |
LL | //! doc comment with bare CR: ' ' LL | //! doc comment with bare CR: ''
| ^ | ^
error: bare CR not allowed in block doc-comment error: bare CR not allowed in block doc-comment
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:15:42 --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:15:42
| |
LL | /*! block doc comment with bare CR: ' ' */ LL | /*! block doc comment with bare CR: '' */
| ^ | ^
error: bare CR not allowed in string, use `\r` instead error: bare CR not allowed in string, use `\r` instead
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:19:18 --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:19:18
| |
LL | let _s = "foo bar"; LL | let _s = "foobar";
| ^ | ^
| |
help: escape the character help: escape the character
@ -36,13 +36,13 @@ LL | let _s = "foo\rbar";
error: bare CR not allowed in raw string error: bare CR not allowed in raw string
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:22:19 --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:22:19
| |
LL | let _s = r"bar foo"; LL | let _s = r"barfoo";
| ^ | ^
error: unknown character escape: `\r` error: unknown character escape: `\r`
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:25:19 --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:25:19
| |
LL | let _s = "foo\ bar"; LL | let _s = "foo\bar";
| ^ unknown character escape | ^ unknown character escape
| |
= help: this is an isolated carriage return; consider checking your editor and version control settings = help: this is an isolated carriage return; consider checking your editor and version control settings

View file

@ -2,7 +2,7 @@ error[E0758]: unterminated block comment
--> $DIR/unterminated-comment.rs:1:1 --> $DIR/unterminated-comment.rs:1:1
| |
LL | /* LL | /*
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -12,7 +12,7 @@ LL | | /*
| | | | | |
| | ...as last nested comment starts here, maybe you want to close this instead? | | ...as last nested comment starts here, maybe you want to close this instead?
LL | | */ LL | | */
| |_--^ | |_-^
| | | |
| ...and last nested comment terminates here. | ...and last nested comment terminates here.

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-104897.rs:5:18 --> $DIR/issue-104897.rs:5:18
| |
LL | fn f(){(print!(á LL | fn f(){(print!(á
| -- - ^ | -- - ^
| || | | || |
| || unclosed delimiter | || unclosed delimiter
| |unclosed delimiter | |unclosed delimiter

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11 --> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11
| |
LL | fn a(){{{ LL | fn a(){{{
| --- ^ | ---^
| ||| | |||
| ||unclosed delimiter | ||unclosed delimiter
| |unclosed delimiter | |unclosed delimiter

Binary file not shown.

View file

@ -25,7 +25,7 @@ LL | '\n';
error: character constant must be escaped: `\r` error: character constant must be escaped: `\r`
--> $DIR/bad-char-literals.rs:15:6 --> $DIR/bad-char-literals.rs:15:6
| |
LL | ' '; LL | '';
| ^ | ^
| |
help: escape the character help: escape the character
@ -33,8 +33,19 @@ help: escape the character
LL | '\r'; LL | '\r';
| ++ | ++
error: character literal may only contain one codepoint
--> $DIR/bad-char-literals.rs:18:5
|
LL | '-␀-';
| ^^^^^
|
help: if you meant to write a string literal, use double quotes
|
LL | "-␀-";
| ~ ~
error: character constant must be escaped: `\t` error: character constant must be escaped: `\t`
--> $DIR/bad-char-literals.rs:18:6 --> $DIR/bad-char-literals.rs:21:6
| |
LL | ' '; LL | ' ';
| ^^^^ | ^^^^
@ -44,5 +55,5 @@ help: escape the character
LL | '\t'; LL | '\t';
| ++ | ++
error: aborting due to 4 previous errors error: aborting due to 5 previous errors

View file

@ -31,7 +31,7 @@ LL | && let () = ()
LL | } LL | }
| - ...as it matches this but it has different indentation | - ...as it matches this but it has different indentation
LL | } LL | }
| ^ | ^
error: found a `{` in the middle of a let-chain error: found a `{` in the middle of a let-chain
--> $DIR/brace-in-let-chain.rs:14:24 --> $DIR/brace-in-let-chain.rs:14:24

View file

@ -43,7 +43,7 @@ error[E0766]: unterminated double quote byte string
LL | b"a LL | b"a
| ______^ | ______^
LL | | } LL | | }
| |__^ | |_^
error: aborting due to 6 previous errors error: aborting due to 6 previous errors

View file

@ -11,7 +11,7 @@ LL | }
| - ...as it matches this but it has different indentation | - ...as it matches this but it has different indentation
... ...
LL | fn main() { } LL | fn main() { }
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -4,7 +4,7 @@ error: this file contains an unclosed delimiter
LL | struct S { LL | struct S {
| - unclosed delimiter | - unclosed delimiter
LL | x: [u8; R LL | x: [u8; R
| - ^ | - ^
| | | |
| unclosed delimiter | unclosed delimiter

View file

@ -20,7 +20,7 @@ LL | #![cfg] {
LL | #![w,) LL | #![w,)
| - missing open `(` for this delimiter | - missing open `(` for this delimiter
LL | LL |
| ^ | ^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -16,7 +16,7 @@ LL | #![c={#![c[)x
| | unclosed delimiter | | unclosed delimiter
| unclosed delimiter | unclosed delimiter
LL | LL |
| ^ | ^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-107705.rs:3:67 --> $DIR/issue-107705.rs:3:67
| |
LL | fn f() {a(b:&, LL | fn f() {a(b:&,
| - - unclosed delimiter ^ | - - unclosed delimiter ^
| | | |
| unclosed delimiter | unclosed delimiter

View file

@ -10,7 +10,7 @@ LL | }
| - ...as it matches this but it has different indentation | - ...as it matches this but it has different indentation
... ...
LL | LL |
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-62546.rs:1:60 --> $DIR/issue-62546.rs:1:60
| |
LL | pub t(# LL | pub t(#
| - unclosed delimiter ^ | - unclosed delimiter ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-62554.rs:5:89 --> $DIR/issue-62554.rs:5:89
| |
LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 {
| - - - - - ^ | - - - - -^
| | | | | | | | | | | |
| | | | | unclosed delimiter | | | | | unclosed delimiter
| | | | unclosed delimiter | | | | unclosed delimiter

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-62881.rs:3:96 --> $DIR/issue-62881.rs:3:96
| |
LL | fn f() -> isize { fn f() -> isize {} pub f< LL | fn f() -> isize { fn f() -> isize {} pub f<
| - unclosed delimiter ^ | - unclosed delimiter ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -8,7 +8,7 @@ LL | fn f() { assert_eq!(f(), (), assert_eq!(assert_eq!
| unclosed delimiter | unclosed delimiter
LL | LL |
LL | fn main() {} LL | fn main() {}
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -25,7 +25,7 @@ LL | fn p() { match s { v, E { [) {) }
| unclosed delimiter | unclosed delimiter
LL | LL |
LL | LL |
| ^ | ^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -10,7 +10,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-63116.rs:3:18 --> $DIR/issue-63116.rs:3:18
| |
LL | impl W <s(f;Y(;] LL | impl W <s(f;Y(;]
| - - ^ | - -^
| | | | | |
| | missing open `[` for this delimiter | | missing open `[` for this delimiter
| unclosed delimiter | unclosed delimiter

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-63135.rs:3:16 --> $DIR/issue-63135.rs:3:16
| |
LL | fn i(n{...,f # LL | fn i(n{...,f #
| - - ^ | - - ^
| | | | | |
| | unclosed delimiter | | unclosed delimiter
| unclosed delimiter | unclosed delimiter

View file

@ -41,7 +41,7 @@ LL | V = [Vec::new; { [0].len() ].len() as isize,
| - missing open `[` for this delimiter | - missing open `[` for this delimiter
... ...
LL | fn main() {} LL | fn main() {}
| ^ | ^
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -10,7 +10,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-81804.rs:6:11 --> $DIR/issue-81804.rs:6:11
| |
LL | fn p([=(} LL | fn p([=(}
| -- ^ | -- ^
| || | ||
| |unclosed delimiter | |unclosed delimiter
| unclosed delimiter | unclosed delimiter

View file

@ -11,7 +11,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-81827.rs:10:27 --> $DIR/issue-81827.rs:10:27
| |
LL | fn r()->i{0|{#[cfg(r(0{]0 LL | fn r()->i{0|{#[cfg(r(0{]0
| - - - ^ | - - - ^
| | | | | | | |
| | | missing open `[` for this delimiter | | | missing open `[` for this delimiter
| | unclosed delimiter | | unclosed delimiter

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-84104.rs:2:13 --> $DIR/issue-84104.rs:2:13
| |
LL | #[i=i::<ښܖ< LL | #[i=i::<ښܖ<
| - ^ | - ^
| | | |
| unclosed delimiter | unclosed delimiter

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-84148-2.rs:2:16 --> $DIR/issue-84148-2.rs:2:16
| |
LL | fn f(t:for<>t? LL | fn f(t:for<>t?
| - ^ | - ^
| | | |
| unclosed delimiter | unclosed delimiter

View file

@ -8,7 +8,7 @@ LL | fn m(){print!("",(c for&g
| unclosed delimiter | unclosed delimiter
... ...
LL | e LL | e
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -5,7 +5,7 @@ LL | impl T for () {
| - unclosed delimiter | - unclosed delimiter
... ...
LL | LL |
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -5,7 +5,7 @@ LL | pub(crate) struct Bar<T> {
| - unclosed delimiter | - unclosed delimiter
... ...
LL | fn main() {} LL | fn main() {}
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -5,7 +5,7 @@ LL | trait T {
| - unclosed delimiter | - unclosed delimiter
... ...
LL | fn main() {} LL | fn main() {}
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -28,7 +28,7 @@ LL | (( h (const {( default ( await ( await ( (move {await((((}}
| unclosed delimiter | unclosed delimiter
... ...
LL | LL |
| ^ | ^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -10,7 +10,7 @@ LL | }
| - ...as it matches this but it has different indentation | - ...as it matches this but it has different indentation
... ...
LL | } LL | }
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,7 +1,7 @@
error: bare CR not allowed in raw string error: bare CR not allowed in raw string
--> $DIR/raw-byte-string-literals.rs:4:9 --> $DIR/raw-byte-string-literals.rs:4:9
| |
LL | br"a "; LL | br"a";
| ^ | ^
error: non-ASCII character in raw byte string literal error: non-ASCII character in raw byte string literal

View file

@ -1,20 +1,20 @@
error: bare CR not allowed in doc-comment error: bare CR not allowed in doc-comment
--> $DIR/several-carriage-returns-in-doc-comment.rs:6:12 --> $DIR/several-carriage-returns-in-doc-comment.rs:6:12
| |
LL | /// This do c comment contains three isolated `\r` symbols LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols
| ^ | ^
error: bare CR not allowed in doc-comment error: bare CR not allowed in doc-comment
--> $DIR/several-carriage-returns-in-doc-comment.rs:6:32 --> $DIR/several-carriage-returns-in-doc-comment.rs:6:32
| |
LL | /// This do c comment contains three isolated `\r` symbols LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols
| ^ | ^
error: bare CR not allowed in doc-comment error: bare CR not allowed in doc-comment
--> $DIR/several-carriage-returns-in-doc-comment.rs:6:52 --> $DIR/several-carriage-returns-in-doc-comment.rs:6:52
| |
LL | /// This do c comment contains three isolated `\r` symbols LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols
| ^ | ^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -1,7 +1,7 @@
error: unknown character escape: `\r` error: unknown character escape: `\r`
--> $DIR/trailing-carriage-return-in-string.rs:10:25 --> $DIR/trailing-carriage-return-in-string.rs:10:25
| |
LL | let bad = "This is \ a test"; LL | let bad = "This is \ a test";
| ^ unknown character escape | ^ unknown character escape
| |
= help: this is an isolated carriage return; consider checking your editor and version control settings = help: this is an isolated carriage return; consider checking your editor and version control settings

View file

@ -3,7 +3,7 @@ error[E0765]: unterminated double quote string
| |
LL | / " LL | / "
LL | | } LL | | }
| |__^ | |_^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -11,7 +11,7 @@ LL | }
| - ...as it matches this but it has different indentation | - ...as it matches this but it has different indentation
... ...
LL | LL |
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -17,78 +17,78 @@ LL | println!("{:?}", b"us\u{202B}e\u{202A}r");
error: non-ASCII character in byte string literal error: non-ASCII character in byte string literal
--> $DIR/unicode-control-codepoints.rs:16:26 --> $DIR/unicode-control-codepoints.rs:16:26
| |
LL | println!("{:?}", b"/* } if isAdmin begin admins only "); LL | println!("{:?}", b"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only ");
| ^ must be ASCII but is '\u{202e}' | ^ must be ASCII but is '\u{202e}'
| |
help: if you meant to use the UTF-8 encoding of '\u{202e}', use \xHH escapes help: if you meant to use the UTF-8 encoding of '\u{202e}', use \xHH escapes
| |
LL | println!("{:?}", b"/*\xE2\x80\xAE } if isAdmin begin admins only "); LL | println!("{:?}", b"/*\xE2\x80\xAE } <EFBFBD>if isAdmin<69> <20> begin admins only ");
| ~~~~~~~~~~~~ | ~~~~~~~~~~~~
error: non-ASCII character in byte string literal error: non-ASCII character in byte string literal
--> $DIR/unicode-control-codepoints.rs:16:30 --> $DIR/unicode-control-codepoints.rs:16:30
| |
LL | println!("{:?}", b"/* } if isAdmin begin admins only "); LL | println!("{:?}", b"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only ");
| ^ must be ASCII but is '\u{2066}' | ^ must be ASCII but is '\u{2066}'
| |
help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes
| |
LL | println!("{:?}", b"/* } \xE2\x81\xA6if isAdmin begin admins only "); LL | println!("{:?}", b"/*<EFBFBD> } \xE2\x81\xA6if isAdmin<69> <20> begin admins only ");
| ~~~~~~~~~~~~ | ~~~~~~~~~~~~
error: non-ASCII character in byte string literal error: non-ASCII character in byte string literal
--> $DIR/unicode-control-codepoints.rs:16:41 --> $DIR/unicode-control-codepoints.rs:16:41
| |
LL | println!("{:?}", b"/* } if isAdmin begin admins only "); LL | println!("{:?}", b"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only ");
| ^ must be ASCII but is '\u{2069}' | ^ must be ASCII but is '\u{2069}'
| |
help: if you meant to use the UTF-8 encoding of '\u{2069}', use \xHH escapes help: if you meant to use the UTF-8 encoding of '\u{2069}', use \xHH escapes
| |
LL | println!("{:?}", b"/* } if isAdmin\xE2\x81\xA9 begin admins only "); LL | println!("{:?}", b"/*<EFBFBD> } <EFBFBD>if isAdmin\xE2\x81\xA9 <EFBFBD> begin admins only ");
| ~~~~~~~~~~~~ | ~~~~~~~~~~~~
error: non-ASCII character in byte string literal error: non-ASCII character in byte string literal
--> $DIR/unicode-control-codepoints.rs:16:43 --> $DIR/unicode-control-codepoints.rs:16:43
| |
LL | println!("{:?}", b"/* } if isAdmin begin admins only "); LL | println!("{:?}", b"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only ");
| ^ must be ASCII but is '\u{2066}' | ^ must be ASCII but is '\u{2066}'
| |
help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes
| |
LL | println!("{:?}", b"/* } if isAdmin \xE2\x81\xA6 begin admins only "); LL | println!("{:?}", b"/*<EFBFBD> } <EFBFBD>if isAdmin<EFBFBD> \xE2\x81\xA6 begin admins only ");
| ~~~~~~~~~~~~ | ~~~~~~~~~~~~
error: non-ASCII character in raw byte string literal error: non-ASCII character in raw byte string literal
--> $DIR/unicode-control-codepoints.rs:21:29 --> $DIR/unicode-control-codepoints.rs:21:29
| |
LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); LL | println!("{:?}", br##"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only "##);
| ^ must be ASCII but is '\u{202e}' | ^ must be ASCII but is '\u{202e}'
error: non-ASCII character in raw byte string literal error: non-ASCII character in raw byte string literal
--> $DIR/unicode-control-codepoints.rs:21:33 --> $DIR/unicode-control-codepoints.rs:21:33
| |
LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); LL | println!("{:?}", br##"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only "##);
| ^ must be ASCII but is '\u{2066}' | ^ must be ASCII but is '\u{2066}'
error: non-ASCII character in raw byte string literal error: non-ASCII character in raw byte string literal
--> $DIR/unicode-control-codepoints.rs:21:44 --> $DIR/unicode-control-codepoints.rs:21:44
| |
LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); LL | println!("{:?}", br##"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only "##);
| ^ must be ASCII but is '\u{2069}' | ^ must be ASCII but is '\u{2069}'
error: non-ASCII character in raw byte string literal error: non-ASCII character in raw byte string literal
--> $DIR/unicode-control-codepoints.rs:21:46 --> $DIR/unicode-control-codepoints.rs:21:46
| |
LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); LL | println!("{:?}", br##"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only "##);
| ^ must be ASCII but is '\u{2066}' | ^ must be ASCII but is '\u{2066}'
error: unicode codepoint changing visible direction of text present in comment error: unicode codepoint changing visible direction of text present in comment
--> $DIR/unicode-control-codepoints.rs:2:5 --> $DIR/unicode-control-codepoints.rs:2:5
| |
LL | // if access_level != "user" { // Check if admin LL | // if access_level != "us<EFBFBD>e<EFBFBD>r" { // Check if admin
| ^^^^^^^^^^^^^^^^^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^
| | || | | | |
| | |'\u{202a}' | | | '\u{202a}'
| | '\u{202b}' | | '\u{202b}'
| this comment contains invisible unicode text flow control codepoints | this comment contains invisible unicode text flow control codepoints
| |
@ -99,12 +99,12 @@ LL | // if access_level != "user" { // Check if admin
error: unicode codepoint changing visible direction of text present in comment error: unicode codepoint changing visible direction of text present in comment
--> $DIR/unicode-control-codepoints.rs:30:1 --> $DIR/unicode-control-codepoints.rs:30:1
| |
LL | //"/* } if isAdmin begin admins only */" LL | //"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only */"
| ^^^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ | ^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^
| | | | || | | | | | |
| | | | |'\u{2066}' | | | | | '\u{2066}'
| | | | '\u{2069}' | | | | '\u{2069}'
| | | '\u{2066}' | | | '\u{2066}'
| | '\u{202e}' | | '\u{202e}'
| this comment contains invisible unicode text flow control codepoints | this comment contains invisible unicode text flow control codepoints
| |
@ -114,12 +114,12 @@ LL | //"/* } if isAdmin begin admins only */"
error: unicode codepoint changing visible direction of text present in literal error: unicode codepoint changing visible direction of text present in literal
--> $DIR/unicode-control-codepoints.rs:11:22 --> $DIR/unicode-control-codepoints.rs:11:22
| |
LL | println!("{:?}", "/* } if isAdmin begin admins only "); LL | println!("{:?}", "/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only ");
| ^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^ | ^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^
| | | | || | | | | | |
| | | | |'\u{2066}' | | | | | '\u{2066}'
| | | | '\u{2069}' | | | | '\u{2069}'
| | | '\u{2066}' | | | '\u{2066}'
| | '\u{202e}' | | '\u{202e}'
| this literal contains invisible unicode text flow control codepoints | this literal contains invisible unicode text flow control codepoints
| |
@ -134,12 +134,12 @@ LL | println!("{:?}", "/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} begi
error: unicode codepoint changing visible direction of text present in literal error: unicode codepoint changing visible direction of text present in literal
--> $DIR/unicode-control-codepoints.rs:14:22 --> $DIR/unicode-control-codepoints.rs:14:22
| |
LL | println!("{:?}", r##"/* } if isAdmin begin admins only "##); LL | println!("{:?}", r##"/*<EFBFBD> } <20>if isAdmin<69> <20> begin admins only "##);
| ^^^^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^
| | | | || | | | | | |
| | | | |'\u{2066}' | | | | | '\u{2066}'
| | | | '\u{2069}' | | | | '\u{2069}'
| | | '\u{2066}' | | | '\u{2066}'
| | '\u{202e}' | | '\u{202e}'
| this literal contains invisible unicode text flow control codepoints | this literal contains invisible unicode text flow control codepoints
| |
@ -153,8 +153,8 @@ LL | println!("{:?}", r##"/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} b
error: unicode codepoint changing visible direction of text present in literal error: unicode codepoint changing visible direction of text present in literal
--> $DIR/unicode-control-codepoints.rs:26:22 --> $DIR/unicode-control-codepoints.rs:26:22
| |
LL | println!("{:?}", ''); LL | println!("{:?}", '<EFBFBD>');
| ^- | ^-^
| || | ||
| |'\u{202e}' | |'\u{202e}'
| this literal contains an invisible unicode text flow control codepoint | this literal contains an invisible unicode text flow control codepoint
@ -169,8 +169,8 @@ LL | println!("{:?}", '\u{202e}');
error: unicode codepoint changing visible direction of text present in doc comment error: unicode codepoint changing visible direction of text present in doc comment
--> $DIR/unicode-control-codepoints.rs:33:1 --> $DIR/unicode-control-codepoints.rs:33:1
| |
LL | /** ''); */fn foo() {} LL | /** '<EFBFBD>'); */fn foo() {}
| ^^^^^^^^^^^^ this doc comment contains an invisible unicode text flow control codepoint | ^^^^^^^^^^^^^ this doc comment contains an invisible unicode text flow control codepoint
| |
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
= note: if their presence wasn't intentional, you can remove them = note: if their presence wasn't intentional, you can remove them
@ -181,8 +181,8 @@ error: unicode codepoint changing visible direction of text present in doc comme
| |
LL | / /** LL | / /**
LL | | * LL | | *
LL | | * ''); */fn bar() {} LL | | * '<EFBFBD>'); */fn bar() {}
| |___________^ this doc comment contains an invisible unicode text flow control codepoint | |____________^ this doc comment contains an invisible unicode text flow control codepoint
| |
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
= note: if their presence wasn't intentional, you can remove them = note: if their presence wasn't intentional, you can remove them

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/unmatched-delimiter-at-end-of-file.rs:11:63 --> $DIR/unmatched-delimiter-at-end-of-file.rs:11:63
| |
LL | fn foo() { LL | fn foo() {
| - unclosed delimiter ^ | - unclosed delimiter ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -5,7 +5,7 @@ LL | use foo::{bar, baz;
| - unclosed delimiter | - unclosed delimiter
... ...
LL | fn main() {} LL | fn main() {}
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,6 +1,6 @@
error: Dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX: error: Dlltool could not create import library with $DLLTOOL -d $DEF_FILE -D foo.dll -l $LIB_FILE $TARGET_MACHINE $ASM_FLAGS --no-leading-underscore $TEMP_PREFIX:
$DLLTOOL: Syntax error in def file $DEF_FILE:1 $DLLTOOL: Syntax error in def file $DEF_FILE:1
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -2,7 +2,7 @@ error[E0758]: unterminated block doc-comment
--> $DIR/unterminated-doc-comment.rs:1:1 --> $DIR/unterminated-doc-comment.rs:1:1
| |
LL | /*! LL | /*!
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:12:85 --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:12:85
| |
LL | trait C{async fn new(val: T) {} LL | trait C{async fn new(val: T) {}
| - unclosed delimiter ^ | - unclosed delimiter ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -22,9 +22,9 @@ warning: whitespace symbol '\u{c}' is not skipped
| |
LL | let s = b"a\ LL | let s = b"a\
| ________________^ | ________________^
LL | | b"; LL | | b";
| | ^- whitespace symbol '\u{c}' is not skipped | | ^ whitespace symbol '\u{c}' is not skipped
| |____| | |_____|
| |
warning: 3 warnings emitted warning: 3 warnings emitted

View file

@ -30,7 +30,7 @@ LL | (; {`
| unclosed delimiter | unclosed delimiter
... ...
LL | LL |
| ^ | ^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -11,7 +11,7 @@ error: this file contains an unclosed delimiter
--> $DIR/issue-91334.rs:7:23 --> $DIR/issue-91334.rs:7:23
| |
LL | fn f(){||yield(((){), LL | fn f(){||yield(((){),
| - - - ^ | - - - ^
| | | | | | | |
| | | missing open `(` for this delimiter | | | missing open `(` for this delimiter
| | unclosed delimiter | | unclosed delimiter