docs: update some comments

This commit is contained in:
Tobias Schmitz 2025-05-20 15:23:21 +02:00
parent 7dc3bcd8eb
commit 8e9e8a753c
No known key found for this signature in database

View File

@ -622,6 +622,7 @@ impl<T> LoadedAt<T> for Result<T, LoadError> {
} }
impl Loaded { impl Loaded {
/// Report an error, possibly in an external file.
pub fn err_in_text( pub fn err_in_text(
&self, &self,
pos: impl Into<ReportPos>, pos: impl Into<ReportPos>,
@ -629,10 +630,11 @@ impl Loaded {
error: impl std::fmt::Display, error: impl std::fmt::Display,
) -> EcoVec<SourceDiagnostic> { ) -> EcoVec<SourceDiagnostic> {
let pos = pos.into(); let pos = pos.into();
// This also does utf-8 validation. Only report an error in an external
// file if it is human readable (valid utf-8), otherwise fall back to
// `err_in_invalid_text`.
let lines = Lines::from_bytes(&self.bytes); let lines = Lines::from_bytes(&self.bytes);
match (self.source.v, lines) { match (self.source.v, lines) {
// Only report an error in an external file,
// if it is human readable (valid utf-8).
(LoadSource::Path(file_id), Ok(lines)) => { (LoadSource::Path(file_id), Ok(lines)) => {
if let Some(range) = pos.range(&lines) { if let Some(range) = pos.range(&lines) {
let span = Span::from_range(file_id, range); let span = Span::from_range(file_id, range);
@ -664,7 +666,7 @@ impl Loaded {
} }
} }
/// Report an error, possibly in an external file. /// Report an error (possibly from an external file) that isn't valid utf-8.
pub fn err_in_invalid_text( pub fn err_in_invalid_text(
&self, &self,
pos: impl Into<ReportPos>, pos: impl Into<ReportPos>,