Skip to content

Commit

Permalink
Add visualization of rustc span in doc
Browse files Browse the repository at this point in the history
It took me quite some time to figure out what Span::to means.
A picture is worth a thousand words.
  • Loading branch information
pickfire authored Sep 13, 2020
1 parent b6c8455 commit 5dc9790
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@ impl Span {
}

/// Returns a `Span` that would enclose both `self` and `end`.
///
/// ```text
/// ____ ___
/// self lorem ipsum end
/// ^^^^^^^^^^^^^^^^^^^^
/// ```
pub fn to(self, end: Span) -> Span {
let span_data = self.data();
let end_data = end.data();
Expand All @@ -567,6 +573,12 @@ impl Span {
}

/// Returns a `Span` between the end of `self` to the beginning of `end`.
///
/// ```text
/// ____ ___
/// self lorem ipsum end
/// ^^^^^^^^^^^^^
/// ```
pub fn between(self, end: Span) -> Span {
let span = self.data();
let end = end.data();
Expand All @@ -577,7 +589,13 @@ impl Span {
)
}

/// Returns a `Span` between the beginning of `self` to the beginning of `end`.
/// Returns a `Span` from the beginning of `self` until the beginning of `end`.
///
/// ```text
/// ____ ___
/// self lorem ipsum end
/// ^^^^^^^^^^^^^^^^^
/// ```
pub fn until(self, end: Span) -> Span {
let span = self.data();
let end = end.data();
Expand Down

0 comments on commit 5dc9790

Please sign in to comment.