Rollup merge of #99140 - TaKO8Ki:implement-is-accessible-span, r=fee1-dead
Implement `SourceMap::is_span_accessible` This patch adds `SourceMap::is_span_accessible` and replaces `span_to_snippet(span).is_ok()` and `span_to_snippet(span).is_err()` with it. This removes a `&str` to `String` conversion.
This commit is contained in:
commit
9fc297a2ae
9 changed files with 16 additions and 16 deletions
|
@ -597,6 +597,13 @@ impl SourceMap {
|
|||
local_begin.sf.src.is_some() && local_end.sf.src.is_some()
|
||||
}
|
||||
|
||||
pub fn is_span_accessible(&self, sp: Span) -> bool {
|
||||
self.span_to_source(sp, |src, start_index, end_index| {
|
||||
Ok(src.get(start_index..end_index).is_some())
|
||||
})
|
||||
.map_or(false, |is_accessible| is_accessible)
|
||||
}
|
||||
|
||||
/// Returns the source snippet as `String` corresponding to the given `Span`.
|
||||
pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError> {
|
||||
self.span_to_source(sp, |src, start_index, end_index| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue