rustc_utils::source_map::span

Trait SpanExt

Source
pub trait SpanExt {
    // Required methods
    fn subtract(&self, child_spans: Vec<Span>) -> Vec<Span>;
    fn as_local(&self, outer_span: Span) -> Option<Span>;
    fn overlaps_inclusive(&self, other: Span) -> bool;
    fn trim_end(&self, other: Span) -> Option<Span>;
    fn merge_overlaps(spans: Vec<Span>) -> Vec<Span>;
    fn trim_leading_whitespace(
        &self,
        source_map: &SourceMap,
    ) -> Option<Vec<Span>>;
    fn to_string(&self, tcx: TyCtxt<'_>) -> String;
    fn size(&self) -> u32;
}
Expand description

Extension trait for Span.

Required Methods§

Source

fn subtract(&self, child_spans: Vec<Span>) -> Vec<Span>

Returns spans for regions in self not in child_spans.

For example:

self:          ---------------
child_spans:    ---      --  ---
output:        -   ------  --
Source

fn as_local(&self, outer_span: Span) -> Option<Span>

Returns the version of this span that is local to the current crate, and must be contained in outer_span.

Source

fn overlaps_inclusive(&self, other: Span) -> bool

Returns true if self overlaps with other including boundaries.

Source

fn trim_end(&self, other: Span) -> Option<Span>

Returns a new span whose end is no later than the start of other, returning None if this would return an empty span.

Source

fn merge_overlaps(spans: Vec<Span>) -> Vec<Span>

Merges all overlapping spans in the input vector into single spans.

Source

fn trim_leading_whitespace(&self, source_map: &SourceMap) -> Option<Vec<Span>>

Returns a collection of spans inside self that have leading whitespace removed.

Returns None if SourceMap::span_to_snippet fails.

Source

fn to_string(&self, tcx: TyCtxt<'_>) -> String

Returns a pretty debug representation of a span.

Source

fn size(&self) -> u32

Returns the size (in bytes) of the spanned text.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SpanExt for Span

Source§

fn trim_end(&self, other: Span) -> Option<Span>

Source§

fn subtract(&self, child_spans: Vec<Span>) -> Vec<Span>

Source§

fn as_local(&self, outer_span: Span) -> Option<Span>

Source§

fn overlaps_inclusive(&self, other: Span) -> bool

Source§

fn merge_overlaps(spans: Vec<Span>) -> Vec<Span>

Source§

fn to_string(&self, tcx: TyCtxt<'_>) -> String

Source§

fn size(&self) -> u32

Source§

fn trim_leading_whitespace(&self, source_map: &SourceMap) -> Option<Vec<Span>>

Implementors§