clean-up SourceFileRange::as_str (#15401)

changelog: none
This commit is contained in:
llogiq
2025-08-03 16:56:11 +00:00
committed by GitHub

View File

@@ -342,11 +342,8 @@ impl SourceFileRange {
/// Attempts to get the text from the source file. This can fail if the source text isn't
/// loaded.
pub fn as_str(&self) -> Option<&str> {
self.sf
.src
.as_ref()
.map(|src| src.as_str())
.or_else(|| self.sf.external_src.get().and_then(|src| src.get_source()))
(self.sf.src.as_ref().map(|src| src.as_str()))
.or_else(|| self.sf.external_src.get()?.get_source())
.and_then(|x| x.get(self.range.clone()))
}
}