-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support meaningful spans in the stable version of proc-macro2 #36
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f8d5f21
Initial implementation of stable meaningful spans
mystor ddea156
Add some tests for the join method
mystor 9cd13f7
Remove some unnecessary eprintln logging calls
mystor 1ecb6ce
Wrap the LineColumn struct when re-exporting from proc-macro
mystor b35a9a3
Update SourceFile::path to return the FileName struct
mystor b65b298
fixup! Wrap the LineColumn struct when re-exporting from proc-macro
mystor a9dbc18
Move the span APIs behind the procmacro2_unstable config option
mystor a0a7c3d
Remove the now-unnecessary memchr dependency
mystor 3463674
Add a section about Unstable Features to the README.md
mystor fb783e3
Move span tests behind a procmacro2_unstable feature flag
mystor 3aa5bdf
Update travis configuration
mystor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ doctest = false | |
|
||
[dependencies] | ||
unicode-xid = "0.1" | ||
memchr = "2.0" | ||
|
||
[features] | ||
unstable = [] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ | |
|
||
extern crate proc_macro; | ||
|
||
#[cfg(not(feature = "unstable"))] | ||
extern crate memchr; | ||
|
||
#[cfg(not(feature = "unstable"))] | ||
extern crate unicode_xid; | ||
|
||
|
@@ -103,6 +106,43 @@ impl TokenStream { | |
} | ||
} | ||
|
||
#[derive(Clone, PartialEq, Eq)] | ||
pub struct SourceFile(imp::SourceFile); | ||
|
||
impl SourceFile { | ||
/// Get the path to this source file as a string. | ||
pub fn as_str(&self) -> &str { | ||
self.0.as_str() | ||
} | ||
|
||
pub fn is_real(&self) -> bool { | ||
self.0.is_real() | ||
} | ||
} | ||
|
||
impl AsRef<str> for SourceFile { | ||
fn as_ref(&self) -> &str { | ||
self.0.as_ref() | ||
} | ||
} | ||
|
||
impl PartialEq<str> for SourceFile { | ||
fn eq(&self, other: &str) -> bool { | ||
self.0.eq(other) | ||
} | ||
} | ||
|
||
impl fmt::Debug for SourceFile { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} | ||
|
||
// NOTE: We can't easily wrap LineColumn right now, as the version in proc-macro | ||
// doesn't actually expose the internal `line` and `column` fields, making it | ||
// mostly useless. | ||
pub use imp::LineColumn; | ||
|
||
#[derive(Copy, Clone)] | ||
pub struct Span(imp::Span); | ||
|
||
|
@@ -121,6 +161,24 @@ impl Span { | |
pub fn def_site() -> Span { | ||
Span(imp::Span::def_site()) | ||
} | ||
|
||
pub fn source_file(&self) -> SourceFile { | ||
SourceFile(self.0.source_file()) | ||
} | ||
|
||
pub fn start(&self) -> LineColumn { | ||
// XXX(nika): We can't easily wrap LineColumn right now | ||
self.0.start() | ||
} | ||
|
||
pub fn end(&self) -> LineColumn { | ||
// XXX(nika): We can't easily wrap LineColumn right now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of rust-lang/rust#46690, the fields have been made public in the proc-macro implementation, so we can probably do a wrap of this type now. |
||
self.0.end() | ||
} | ||
|
||
pub fn join(&self, other: Span) -> Option<Span> { | ||
self.0.join(other.0).map(Span) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With @Manishearth's work on improving the performance of the find method in rust-lang/rust#46735, it probably won't be useful to have this dependency on memchr anymore, so we might want to drop it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's why you wanted this.
Sneaky, sneaky 😺