diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 57 |
1 files changed, 15 insertions, 42 deletions
@@ -86,7 +86,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.47")] +#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.51")] #![cfg_attr( any(proc_macro_span, super_unstable), feature(proc_macro_span, proc_macro_span_shrink) @@ -139,6 +139,9 @@ use crate::fallback as imp; #[cfg(wrap_proc_macro)] mod imp; +#[cfg(span_locations)] +mod location; + use crate::marker::Marker; use core::cmp::Ordering; use core::fmt::{self, Debug, Display}; @@ -150,6 +153,9 @@ use std::error::Error; #[cfg(procmacro2_semver_exempt)] use std::path::PathBuf; +#[cfg(span_locations)] +pub use crate::location::LineColumn; + /// An abstract stream of tokens, or more concretely a sequence of token trees. /// /// This type provides interfaces for iterating over token trees and for @@ -225,14 +231,14 @@ impl FromStr for TokenStream { #[cfg(use_proc_macro)] impl From<proc_macro::TokenStream> for TokenStream { - fn from(inner: proc_macro::TokenStream) -> TokenStream { + fn from(inner: proc_macro::TokenStream) -> Self { TokenStream::_new(inner.into()) } } #[cfg(use_proc_macro)] impl From<TokenStream> for proc_macro::TokenStream { - fn from(inner: TokenStream) -> proc_macro::TokenStream { + fn from(inner: TokenStream) -> Self { inner.inner.into() } } @@ -356,37 +362,6 @@ impl Debug for SourceFile { } } -/// A line-column pair representing the start or end of a `Span`. -/// -/// This type is semver exempt and not exposed by default. -#[cfg(span_locations)] -#[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct LineColumn { - /// The 1-indexed line in the source file on which the span starts or ends - /// (inclusive). - pub line: usize, - /// The 0-indexed column (in UTF-8 characters) in the source file on which - /// the span starts or ends (inclusive). - 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 { @@ -492,8 +467,7 @@ impl Span { #[cfg(span_locations)] #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] pub fn start(&self) -> LineColumn { - let imp::LineColumn { line, column } = self.inner.start(); - LineColumn { line, column } + self.inner.start() } /// Get the ending line/column in the source file for this span. @@ -508,8 +482,7 @@ impl Span { #[cfg(span_locations)] #[cfg_attr(doc_cfg, doc(cfg(feature = "span-locations")))] pub fn end(&self) -> LineColumn { - let imp::LineColumn { line, column } = self.inner.end(); - LineColumn { line, column } + self.inner.end() } /// Creates an empty span pointing to directly before this span. @@ -601,25 +574,25 @@ impl TokenTree { } impl From<Group> for TokenTree { - fn from(g: Group) -> TokenTree { + fn from(g: Group) -> Self { TokenTree::Group(g) } } impl From<Ident> for TokenTree { - fn from(g: Ident) -> TokenTree { + fn from(g: Ident) -> Self { TokenTree::Ident(g) } } impl From<Punct> for TokenTree { - fn from(g: Punct) -> TokenTree { + fn from(g: Punct) -> Self { TokenTree::Punct(g) } } impl From<Literal> for TokenTree { - fn from(g: Literal) -> TokenTree { + fn from(g: Literal) -> Self { TokenTree::Literal(g) } } |