review comments
This commit is contained in:
parent
105b3a0b02
commit
84e202e6b3
1 changed files with 9 additions and 12 deletions
|
@ -519,7 +519,7 @@ impl SourceMap {
|
||||||
/// extract function takes three arguments: a string slice containing the source, an index in
|
/// extract function takes three arguments: a string slice containing the source, an index in
|
||||||
/// the slice for the beginning of the span and an index in the slice for the end of the span.
|
/// the slice for the beginning of the span and an index in the slice for the end of the span.
|
||||||
fn span_to_source<F>(&self, sp: Span, extract_source: F) -> Result<String, SpanSnippetError>
|
fn span_to_source<F>(&self, sp: Span, extract_source: F) -> Result<String, SpanSnippetError>
|
||||||
where F: Fn(&str, usize, usize) -> String
|
where F: Fn(&str, usize, usize) -> Result<String, SpanSnippetError>
|
||||||
{
|
{
|
||||||
if sp.lo() > sp.hi() {
|
if sp.lo() > sp.hi() {
|
||||||
return Err(SpanSnippetError::IllFormedSpan(sp));
|
return Err(SpanSnippetError::IllFormedSpan(sp));
|
||||||
|
@ -554,15 +554,9 @@ impl SourceMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref src) = local_begin.sf.src {
|
if let Some(ref src) = local_begin.sf.src {
|
||||||
if !src.is_char_boundary(start_index) || !src.is_char_boundary(end_index) {
|
return extract_source(src, start_index, end_index);
|
||||||
return Err(SpanSnippetError::IllFormedSpan(sp));
|
|
||||||
}
|
|
||||||
return Ok(extract_source(src, start_index, end_index));
|
|
||||||
} else if let Some(src) = local_begin.sf.external_src.borrow().get_source() {
|
} else if let Some(src) = local_begin.sf.external_src.borrow().get_source() {
|
||||||
if !src.is_char_boundary(start_index) || !src.is_char_boundary(end_index) {
|
return extract_source(src, start_index, end_index);
|
||||||
return Err(SpanSnippetError::IllFormedSpan(sp));
|
|
||||||
}
|
|
||||||
return Ok(extract_source(src, start_index, end_index));
|
|
||||||
} else {
|
} else {
|
||||||
return Err(SpanSnippetError::SourceNotAvailable {
|
return Err(SpanSnippetError::SourceNotAvailable {
|
||||||
filename: local_begin.sf.name.clone()
|
filename: local_begin.sf.name.clone()
|
||||||
|
@ -573,8 +567,9 @@ impl SourceMap {
|
||||||
|
|
||||||
/// Returns the source snippet as `String` corresponding to the given `Span`
|
/// Returns the source snippet as `String` corresponding to the given `Span`
|
||||||
pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError> {
|
pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError> {
|
||||||
self.span_to_source(sp, |src, start_index, end_index| src[start_index..end_index]
|
self.span_to_source(sp, |src, start_index, end_index| src.get(start_index..end_index)
|
||||||
.to_string())
|
.map(|s| s.to_string())
|
||||||
|
.ok_or_else(|| SpanSnippetError::IllFormedSpan(sp)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_to_margin(&self, sp: Span) -> Option<usize> {
|
pub fn span_to_margin(&self, sp: Span) -> Option<usize> {
|
||||||
|
@ -588,7 +583,9 @@ impl SourceMap {
|
||||||
|
|
||||||
/// Returns the source snippet as `String` before the given `Span`
|
/// Returns the source snippet as `String` before the given `Span`
|
||||||
pub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError> {
|
pub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError> {
|
||||||
self.span_to_source(sp, |src, start_index, _| src[..start_index].to_string())
|
self.span_to_source(sp, |src, start_index, _| src.get(..start_index)
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.ok_or_else(|| SpanSnippetError::IllFormedSpan(sp)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extend the given `Span` to just after the previous occurrence of `c`. Return the same span
|
/// Extend the given `Span` to just after the previous occurrence of `c`. Return the same span
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue