Add some utilities to libsyntax#50192
Merged
bors merged 4 commits intorust-lang:masterfrom Apr 27, 2018
Merged
Conversation
... and reimplement proc_macro::Span::parent using it. This function turns out to be useful in the compiler as well
This is useful when trying to compute when something is lexically before something else, but they aren't necessarily in the same SyntaxContext
jseyfried
reviewed
Apr 26, 2018
Contributor
jseyfried
left a comment
There was a problem hiding this comment.
Nice! r=me modulo comments (nits optional)
src/libproc_macro/lib.rs
Outdated
| #[unstable(feature = "proc_macro", issue = "38356")] | ||
| pub fn parent(&self) -> Option<Span> { | ||
| self.0.ctxt().outer().expn_info().map(|i| Span(i.call_site)) | ||
| self.0.parent().map(|x| { Span(x) }) |
src/libsyntax_pos/hygiene.rs
Outdated
| /// assert!(a.is_descendant_of(lub)) | ||
| /// assert!(b.is_descendant_of(lub)) | ||
| /// ``` | ||
| pub fn lub(mut a: Mark, mut b: Mark) -> Mark { |
Contributor
There was a problem hiding this comment.
Maybe least_ancestor for clarity and symmetry with the is_descendant_of? (I'd probably call this join if it were math)
| pub fn lub(mut a: Mark, mut b: Mark) -> Mark { | ||
| HygieneData::with(|data| { | ||
| // Compute the path from a to the root | ||
| let mut a_path = FxHashSet::<Mark>(); |
src/libsyntax_pos/hygiene.rs
Outdated
|
|
||
| // While the path from b to the root hasn't intersected, move up the tree | ||
| while !a_path.contains(&b) { | ||
| b = data.marks[b.0 as usize].parent; |
| /// and we have a SyntaxContext that is referring to something declared by an invocation | ||
| /// of g (call it g1), calling remove_mark will result in the SyntaxContext for the | ||
| /// invocation of f that created g1. | ||
| /// Returns the mark that was removed. |
src/libsyntax_pos/lib.rs
Outdated
| self.ctxt().outer().expn_info().map(|info| info.call_site.source_callsite()).unwrap_or(self) | ||
| } | ||
|
|
||
| /// The `Span for the tokens in the previous macro expansion from which `self` was generated, |
Contributor
Author
|
@jseyfried I've pushed fixes for the nits, and changed the name of |
Contributor
|
Thanks! @bors r+ |
Collaborator
|
📌 Commit 73e0c1e has been approved by |
kennytm
added a commit
to kennytm/rust
that referenced
this pull request
Apr 27, 2018
…=jseyfried Add some utilities to `libsyntax` Adds a few functions to `Mark` and `Span` that I found useful in an upcoming refactor of NLL region error reporting. Also includes some new documentation based on my discussion with @jseyfried on IRC. r? @jseyfried
bors
added a commit
that referenced
this pull request
Apr 27, 2018
Rollup of 9 pull requests Successful merges: - #49858 (std: Mark `ptr::Unique` with `#[doc(hidden)]`) - #49968 (Stabilize dyn trait) - #50192 (Add some utilities to `libsyntax`) - #50251 (rustc: Disable threads in LLD for wasm) - #50263 (rustc: Emit `uwtable` for allocator shims) - #50269 (Update `parking_lot` dependencies) - #50273 (Allow #[inline] on closures) - #50284 (fix search load page failure) - #50257 (Don't ICE on tuple struct ctor with incorrect arg count) Failed merges:
This was referenced Apr 16, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a few functions to
MarkandSpanthat I found useful in an upcoming refactor of NLL region error reporting. Also includes some new documentation based on my discussion with @jseyfried on IRC.r? @jseyfried