diff options
author | Chih-Hung Hsieh <chh@google.com> | 2020-05-28 00:37:17 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-28 00:37:17 +0000 |
commit | d821995c2c98e720a41476932b436209506abc51 (patch) | |
tree | b8a75f2cdcfdc32c7d48ffc696e4926f293fed2f /src/lib.rs | |
parent | 3dad3c202c288d1e90b0668ef1b7d9708c78a967 (diff) | |
parent | a45e020872ace843ccd24afc6152627eeff7bc8d (diff) | |
download | proc-macro2-d821995c2c98e720a41476932b436209506abc51.tar.gz |
Upgrade rust/crates/proc-macro2 to 1.0.17 am: a45e020872
Change-Id: Id9ef5e90a2427c9c2a43ee25f73c79a57529ca13
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 71 |
1 files changed, 46 insertions, 25 deletions
@@ -78,7 +78,7 @@ //! a different thread. // Proc-macro2 types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.13")] +#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.17")] #![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))] #![cfg_attr(super_unstable, feature(proc_macro_raw_ident, proc_macro_def_site))] @@ -317,6 +317,20 @@ pub struct LineColumn { pub column: usize, } +#[cfg(span_locations)] +impl Ord for LineColumn { + fn cmp(&self, other: &Self) -> Ordering { + self.line.cmp(&other.line).then(self.column.cmp(&other.column)) + } +} + +#[cfg(span_locations)] +impl PartialOrd for LineColumn { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + Some(self.cmp(other)) + } +} + /// A region of source code, along with macro expansion information. #[derive(Copy, Clone)] pub struct Span { @@ -348,6 +362,17 @@ impl Span { Span::_new(imp::Span::call_site()) } + /// The span located at the invocation of the procedural macro, but with + /// local variables, labels, and `$crate` resolved at the definition site + /// of the macro. This is the same hygiene behavior as `macro_rules`. + /// + /// This function requires Rust 1.45 or later. + #[cfg(procmacro2_semver_exempt)] + #[cfg(hygiene)] + pub fn mixed_site() -> Span { + Span::_new(imp::Span::mixed_site()) + } + /// A span that resolves at the macro definition site. /// /// This method is semver exempt and not exposed by default. @@ -358,8 +383,6 @@ impl Span { /// Creates a new span with the same line/column information as `self` but /// that resolves symbols as though it were at `other`. - /// - /// This method is semver exempt and not exposed by default. #[cfg(procmacro2_semver_exempt)] pub fn resolved_at(&self, other: Span) -> Span { Span::_new(self.inner.resolved_at(other.inner)) @@ -367,8 +390,6 @@ impl Span { /// Creates a new span with the same name resolution behavior as `self` but /// with the line/column information of `other`. - /// - /// This method is semver exempt and not exposed by default. #[cfg(procmacro2_semver_exempt)] pub fn located_at(&self, other: Span) -> Span { Span::_new(self.inner.located_at(other.inner)) @@ -468,11 +489,11 @@ impl TokenTree { /// Returns the span of this tree, delegating to the `span` method of /// the contained token or a delimited stream. pub fn span(&self) -> Span { - match *self { - TokenTree::Group(ref t) => t.span(), - TokenTree::Ident(ref t) => t.span(), - TokenTree::Punct(ref t) => t.span(), - TokenTree::Literal(ref t) => t.span(), + match self { + TokenTree::Group(t) => t.span(), + TokenTree::Ident(t) => t.span(), + TokenTree::Punct(t) => t.span(), + TokenTree::Literal(t) => t.span(), } } @@ -482,11 +503,11 @@ impl TokenTree { /// the span of each of the internal tokens, this will simply delegate to /// the `set_span` method of each variant. pub fn set_span(&mut self, span: Span) { - match *self { - TokenTree::Group(ref mut t) => t.set_span(span), - TokenTree::Ident(ref mut t) => t.set_span(span), - TokenTree::Punct(ref mut t) => t.set_span(span), - TokenTree::Literal(ref mut t) => t.set_span(span), + match self { + TokenTree::Group(t) => t.set_span(span), + TokenTree::Ident(t) => t.set_span(span), + TokenTree::Punct(t) => t.set_span(span), + TokenTree::Literal(t) => t.set_span(span), } } } @@ -521,11 +542,11 @@ impl From<Literal> for TokenTree { /// numeric literals. impl fmt::Display for TokenTree { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - TokenTree::Group(ref t) => t.fmt(f), - TokenTree::Ident(ref t) => t.fmt(f), - TokenTree::Punct(ref t) => t.fmt(f), - TokenTree::Literal(ref t) => t.fmt(f), + match self { + TokenTree::Group(t) => t.fmt(f), + TokenTree::Ident(t) => t.fmt(f), + TokenTree::Punct(t) => t.fmt(f), + TokenTree::Literal(t) => t.fmt(f), } } } @@ -535,16 +556,16 @@ impl fmt::Debug for TokenTree { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Each of these has the name in the struct type in the derived debug, // so don't bother with an extra layer of indirection - match *self { - TokenTree::Group(ref t) => t.fmt(f), - TokenTree::Ident(ref t) => { + match self { + TokenTree::Group(t) => t.fmt(f), + TokenTree::Ident(t) => { let mut debug = f.debug_struct("Ident"); debug.field("sym", &format_args!("{}", t)); imp::debug_span_field_if_nontrivial(&mut debug, t.span().inner); debug.finish() } - TokenTree::Punct(ref t) => t.fmt(f), - TokenTree::Literal(ref t) => t.fmt(f), + TokenTree::Punct(t) => t.fmt(f), + TokenTree::Literal(t) => t.fmt(f), } } } |