Skip to content

Commit

Permalink
Doc tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy committed May 26, 2022
1 parent f9dfc38 commit f035854
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,7 @@ impl ParseError {
writer.into_string()
}

/// Returns the 1-based line number and column of the first label in the
/// error message.
/// Returns a [`SourceLocation`] for the first label in the error message.
pub fn location(&self, source: &str) -> Option<SourceLocation> {
self.labels
.get(0)
Expand Down
14 changes: 9 additions & 5 deletions src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ impl Span {
*self != Self::default()
}

/// Returns the 1-based line number and column of the this span in
/// the provided source.
/// Return a [`SourceLocation`] for this span in the provided source.
pub fn location(&self, source: &str) -> SourceLocation {
let prefix = &source[..self.start as usize];
let line_number = prefix.matches('\n').count() as u32 + 1;
Expand All @@ -86,10 +85,13 @@ impl From<Range<usize>> for Span {
}
}

/// A human-readable representation for span, tailored for text source.
/// A human-readable representation for a span, tailored for text source.
///
/// Corresponds to the positional members of `GPUCompilationMessage` from the WebGPU specification,
/// using utf8 instead of utf16 as reference encoding.
/// Corresponds to the positional members of [`GPUCompilationMessage`][gcm] from
/// the WebGPU specification, except that `offset` and `length` are 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.
Expand Down Expand Up @@ -220,6 +222,7 @@ impl<E> WithSpan<E> {
}

#[cfg(feature = "span")]
/// Return a [`SourceLocation`] for our first span, if we have one.
pub fn location(&self, source: &str) -> Option<SourceLocation> {
if self.spans.is_empty() {
return None;
Expand All @@ -229,6 +232,7 @@ impl<E> WithSpan<E> {
}

#[cfg(not(feature = "span"))]
/// Return a [`SourceLocation`] for our first span, if we have one.
pub fn location(&self, _source: &str) -> Option<SourceLocation> {
None
}
Expand Down

0 comments on commit f035854

Please sign in to comment.