summaryrefslogtreecommitdiffstats
path: root/third_party/rust/naga/src/span.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/naga/src/span.rs')
-rw-r--r--third_party/rust/naga/src/span.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/third_party/rust/naga/src/span.rs b/third_party/rust/naga/src/span.rs
index 10744647e9..82cfbe5a4b 100644
--- a/third_party/rust/naga/src/span.rs
+++ b/third_party/rust/naga/src/span.rs
@@ -72,8 +72,8 @@ impl Span {
pub fn location(&self, source: &str) -> SourceLocation {
let prefix = &source[..self.start as usize];
let line_number = prefix.matches('\n').count() as u32 + 1;
- let line_start = prefix.rfind('\n').map(|pos| pos + 1).unwrap_or(0);
- let line_position = source[line_start..self.start as usize].chars().count() as u32 + 1;
+ let line_start = prefix.rfind('\n').map(|pos| pos + 1).unwrap_or(0) as u32;
+ let line_position = self.start - line_start + 1;
SourceLocation {
line_number,
@@ -107,14 +107,14 @@ impl std::ops::Index<Span> for str {
/// Roughly corresponds to the positional members of [`GPUCompilationMessage`][gcm] from
/// the WebGPU specification, except
/// - `offset` and `length` are in bytes (UTF-8 code units), instead of UTF-16 code units.
-/// - `line_position` counts entire Unicode code points, instead of UTF-16 code units.
+/// - `line_position` is in bytes (UTF-8 code units), instead of UTF-16 code units.
///
/// [gcm]: https://www.w3.org/TR/webgpu/#gpucompilationmessage
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct SourceLocation {
/// 1-based line number.
pub line_number: u32,
- /// 1-based column of the start of this span, counted in Unicode code points.
+ /// 1-based column in code units (in bytes) of the start of the span.
pub line_position: u32,
/// 0-based Offset in code units (in bytes) of the start of the span.
pub offset: u32,
@@ -136,7 +136,7 @@ impl<E> fmt::Display for WithSpan<E>
where
E: fmt::Display,
{
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
@@ -304,7 +304,7 @@ impl<E> WithSpan<E> {
use term::termcolor::NoColor;
let files = files::SimpleFile::new(path, source);
- let config = codespan_reporting::term::Config::default();
+ let config = term::Config::default();
let mut writer = NoColor::new(Vec::new());
term::emit(&mut writer, &config, &files, &self.diagnostic()).expect("cannot write error");
String::from_utf8(writer.into_inner()).unwrap()