summaryrefslogtreecommitdiffstats
path: root/vendor/proc-macro2/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/proc-macro2/src')
-rw-r--r--vendor/proc-macro2/src/extra.rs100
-rw-r--r--vendor/proc-macro2/src/fallback.rs50
-rw-r--r--vendor/proc-macro2/src/lib.rs47
-rw-r--r--vendor/proc-macro2/src/parse.rs14
-rw-r--r--vendor/proc-macro2/src/wrapper.rs30
5 files changed, 203 insertions, 38 deletions
diff --git a/vendor/proc-macro2/src/extra.rs b/vendor/proc-macro2/src/extra.rs
new file mode 100644
index 000000000..cbce1626c
--- /dev/null
+++ b/vendor/proc-macro2/src/extra.rs
@@ -0,0 +1,100 @@
+//! Items which do not have a correspondence to any API in the proc_macro crate,
+//! but are necessary to include in proc-macro2.
+
+use crate::fallback;
+use crate::imp;
+use crate::marker::Marker;
+use crate::Span;
+use core::fmt::{self, Debug};
+
+/// An object that holds a [`Group`]'s `span_open()` and `span_close()` together
+/// (in a more compact representation than holding those 2 spans individually.
+///
+/// [`Group`]: crate::Group
+#[derive(Copy, Clone)]
+pub struct DelimSpan {
+ inner: DelimSpanEnum,
+ _marker: Marker,
+}
+
+#[derive(Copy, Clone)]
+enum DelimSpanEnum {
+ #[cfg(wrap_proc_macro)]
+ Compiler {
+ join: proc_macro::Span,
+ #[cfg(not(no_group_open_close))]
+ open: proc_macro::Span,
+ #[cfg(not(no_group_open_close))]
+ close: proc_macro::Span,
+ },
+ Fallback(fallback::Span),
+}
+
+impl DelimSpan {
+ pub(crate) fn new(group: &imp::Group) -> Self {
+ #[cfg(wrap_proc_macro)]
+ let inner = match group {
+ imp::Group::Compiler(group) => DelimSpanEnum::Compiler {
+ join: group.span(),
+ #[cfg(not(no_group_open_close))]
+ open: group.span_open(),
+ #[cfg(not(no_group_open_close))]
+ close: group.span_close(),
+ },
+ imp::Group::Fallback(group) => DelimSpanEnum::Fallback(group.span()),
+ };
+
+ #[cfg(not(wrap_proc_macro))]
+ let inner = DelimSpanEnum::Fallback(group.span());
+
+ DelimSpan {
+ inner,
+ _marker: Marker,
+ }
+ }
+
+ /// Returns a span covering the entire delimited group.
+ pub fn join(&self) -> Span {
+ match &self.inner {
+ #[cfg(wrap_proc_macro)]
+ DelimSpanEnum::Compiler { join, .. } => Span::_new(imp::Span::Compiler(*join)),
+ DelimSpanEnum::Fallback(span) => Span::_new_fallback(*span),
+ }
+ }
+
+ /// Returns a span for the opening punctuation of the group only.
+ pub fn open(&self) -> Span {
+ match &self.inner {
+ #[cfg(wrap_proc_macro)]
+ DelimSpanEnum::Compiler {
+ #[cfg(not(no_group_open_close))]
+ open,
+ #[cfg(no_group_open_close)]
+ join: open,
+ ..
+ } => Span::_new(imp::Span::Compiler(*open)),
+ DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.first_byte()),
+ }
+ }
+
+ /// Returns a span for the closing punctuation of the group only.
+ pub fn close(&self) -> Span {
+ match &self.inner {
+ #[cfg(wrap_proc_macro)]
+ DelimSpanEnum::Compiler {
+ #[cfg(not(no_group_open_close))]
+ close,
+ #[cfg(no_group_open_close)]
+ join: close,
+ ..
+ } => Span::_new(imp::Span::Compiler(*close)),
+ DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.last_byte()),
+ }
+ }
+}
+
+impl Debug for DelimSpan {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Debug::fmt(&self.join(), f)
+ }
+}
diff --git a/vendor/proc-macro2/src/fallback.rs b/vendor/proc-macro2/src/fallback.rs
index 5a4c350d5..b0ed7b06f 100644
--- a/vendor/proc-macro2/src/fallback.rs
+++ b/vendor/proc-macro2/src/fallback.rs
@@ -94,7 +94,7 @@ fn push_token_from_proc_macro(mut vec: RcVecMut<TokenTree>, token: TokenTree) {
if literal.repr.starts_with('-') {
push_negative_literal(vec, literal);
} else {
- vec.push(TokenTree::Literal(crate::Literal::_new_stable(literal)));
+ vec.push(TokenTree::Literal(crate::Literal::_new_fallback(literal)));
}
}
_ => vec.push(token),
@@ -104,9 +104,9 @@ fn push_token_from_proc_macro(mut vec: RcVecMut<TokenTree>, token: TokenTree) {
fn push_negative_literal(mut vec: RcVecMut<TokenTree>, mut literal: Literal) {
literal.repr.remove(0);
let mut punct = crate::Punct::new('-', Spacing::Alone);
- punct.set_span(crate::Span::_new_stable(literal.span));
+ punct.set_span(crate::Span::_new_fallback(literal.span));
vec.push(TokenTree::Punct(punct));
- vec.push(TokenTree::Literal(crate::Literal::_new_stable(literal)));
+ vec.push(TokenTree::Literal(crate::Literal::_new_fallback(literal)));
}
}
@@ -234,7 +234,7 @@ impl Debug 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 {
inner
.to_string()
.parse()
@@ -244,7 +244,7 @@ impl From<proc_macro::TokenStream> for TokenStream {
#[cfg(use_proc_macro)]
impl From<TokenStream> for proc_macro::TokenStream {
- fn from(inner: TokenStream) -> proc_macro::TokenStream {
+ fn from(inner: TokenStream) -> Self {
inner
.to_string()
.parse()
@@ -253,7 +253,7 @@ impl From<TokenStream> for proc_macro::TokenStream {
}
impl From<TokenTree> for TokenStream {
- fn from(tree: TokenTree) -> TokenStream {
+ fn from(tree: TokenTree) -> Self {
let mut stream = RcVecBuilder::new();
push_token_from_proc_macro(stream.as_mut(), tree);
TokenStream {
@@ -342,6 +342,7 @@ thread_local! {
files: vec![FileInfo {
#[cfg(procmacro2_semver_exempt)]
name: "<unspecified>".to_owned(),
+ source_text: String::new(),
span: Span { lo: 0, hi: 0 },
lines: vec![0],
}],
@@ -352,6 +353,7 @@ thread_local! {
struct FileInfo {
#[cfg(procmacro2_semver_exempt)]
name: String,
+ source_text: String,
span: Span,
lines: Vec<usize>,
}
@@ -379,6 +381,12 @@ impl FileInfo {
fn span_within(&self, span: Span) -> bool {
span.lo >= self.span.lo && span.hi <= self.span.hi
}
+
+ fn source_text(&self, span: Span) -> String {
+ let lo = (span.lo - self.span.lo) as usize;
+ let hi = (span.hi - self.span.lo) as usize;
+ self.source_text[lo..hi].to_owned()
+ }
}
/// Computes the offsets of each line in the given source string
@@ -425,6 +433,7 @@ impl SourceMap {
self.files.push(FileInfo {
#[cfg(procmacro2_semver_exempt)]
name: name.to_owned(),
+ source_text: src.to_owned(),
span,
lines,
});
@@ -555,12 +564,26 @@ impl Span {
}
#[cfg(not(span_locations))]
- fn first_byte(self) -> Self {
+ pub fn source_text(&self) -> Option<String> {
+ None
+ }
+
+ #[cfg(span_locations)]
+ pub fn source_text(&self) -> Option<String> {
+ if self.is_call_site() {
+ None
+ } else {
+ Some(SOURCE_MAP.with(|cm| cm.borrow().fileinfo(*self).source_text(*self)))
+ }
+ }
+
+ #[cfg(not(span_locations))]
+ pub(crate) fn first_byte(self) -> Self {
self
}
#[cfg(span_locations)]
- fn first_byte(self) -> Self {
+ pub(crate) fn first_byte(self) -> Self {
Span {
lo: self.lo,
hi: cmp::min(self.lo.saturating_add(1), self.hi),
@@ -568,17 +591,22 @@ impl Span {
}
#[cfg(not(span_locations))]
- fn last_byte(self) -> Self {
+ pub(crate) fn last_byte(self) -> Self {
self
}
#[cfg(span_locations)]
- fn last_byte(self) -> Self {
+ pub(crate) fn last_byte(self) -> Self {
Span {
lo: cmp::max(self.hi.saturating_sub(1), self.lo),
hi: self.hi,
}
}
+
+ #[cfg(span_locations)]
+ fn is_call_site(&self) -> bool {
+ self.lo == 0 && self.hi == 0
+ }
}
impl Debug for Span {
@@ -594,7 +622,7 @@ impl Debug for Span {
pub(crate) fn debug_span_field_if_nontrivial(debug: &mut fmt::DebugStruct, span: Span) {
#[cfg(span_locations)]
{
- if span.lo == 0 && span.hi == 0 {
+ if span.is_call_site() {
return;
}
}
diff --git a/vendor/proc-macro2/src/lib.rs b/vendor/proc-macro2/src/lib.rs
index 633333ba8..138627a16 100644
--- a/vendor/proc-macro2/src/lib.rs
+++ b/vendor/proc-macro2/src/lib.rs
@@ -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.50")]
+#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.53")]
#![cfg_attr(
any(proc_macro_span, super_unstable),
feature(proc_macro_span, proc_macro_span_shrink)
@@ -98,6 +98,7 @@
clippy::cast_possible_truncation,
clippy::doc_markdown,
clippy::items_after_statements,
+ clippy::let_underscore_untyped,
clippy::manual_assert,
clippy::must_use_candidate,
clippy::needless_doctest_main,
@@ -133,6 +134,8 @@ mod detection;
#[doc(hidden)]
pub mod fallback;
+pub mod extra;
+
#[cfg(not(wrap_proc_macro))]
use crate::fallback as imp;
#[path = "wrapper.rs"]
@@ -142,6 +145,7 @@ mod imp;
#[cfg(span_locations)]
mod location;
+use crate::extra::DelimSpan;
use crate::marker::Marker;
use core::cmp::Ordering;
use core::fmt::{self, Debug, Display};
@@ -183,7 +187,7 @@ impl TokenStream {
}
}
- fn _new_stable(inner: fallback::TokenStream) -> Self {
+ fn _new_fallback(inner: fallback::TokenStream) -> Self {
TokenStream {
inner: inner.into(),
_marker: Marker,
@@ -231,14 +235,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()
}
}
@@ -377,7 +381,7 @@ impl Span {
}
}
- fn _new_stable(inner: fallback::Span) -> Self {
+ fn _new_fallback(inner: fallback::Span) -> Self {
Span {
inner: inner.into(),
_marker: Marker,
@@ -524,6 +528,17 @@ impl Span {
pub fn eq(&self, other: &Span) -> bool {
self.inner.eq(&other.inner)
}
+
+ /// Returns the source text behind a span. This preserves the original
+ /// source code, including spaces and comments. It only returns a result if
+ /// the span corresponds to real source code.
+ ///
+ /// Note: The observable result of a macro should only rely on the tokens
+ /// and not on this source text. The result of this function is a best
+ /// effort to be used for diagnostics only.
+ pub fn source_text(&self) -> Option<String> {
+ self.inner.source_text()
+ }
}
/// Prints a span in a form convenient for debugging.
@@ -574,25 +589,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)
}
}
@@ -664,7 +679,7 @@ impl Group {
Group { inner }
}
- fn _new_stable(inner: fallback::Group) -> Self {
+ fn _new_fallback(inner: fallback::Group) -> Self {
Group {
inner: inner.into(),
}
@@ -681,7 +696,8 @@ impl Group {
}
}
- /// Returns the delimiter of this `Group`
+ /// Returns the punctuation used as the delimiter for this group: a set of
+ /// parentheses, square brackets, or curly braces.
pub fn delimiter(&self) -> Delimiter {
self.inner.delimiter()
}
@@ -725,6 +741,13 @@ impl Group {
Span::_new(self.inner.span_close())
}
+ /// Returns an object that holds this group's `span_open()` and
+ /// `span_close()` together (in a more compact representation than holding
+ /// those 2 spans individually).
+ pub fn delim_span(&self) -> DelimSpan {
+ DelimSpan::new(&self.inner)
+ }
+
/// Configures the span for this `Group`'s delimiters, but not its internal
/// tokens.
///
@@ -1081,7 +1104,7 @@ impl Literal {
}
}
- fn _new_stable(inner: fallback::Literal) -> Self {
+ fn _new_fallback(inner: fallback::Literal) -> Self {
Literal {
inner: inner.into(),
_marker: Marker,
diff --git a/vendor/proc-macro2/src/parse.rs b/vendor/proc-macro2/src/parse.rs
index 307e06508..82291da1b 100644
--- a/vendor/proc-macro2/src/parse.rs
+++ b/vendor/proc-macro2/src/parse.rs
@@ -217,13 +217,13 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
hi: input.off,
});
trees = outer;
- trees.push_token_from_parser(TokenTree::Group(crate::Group::_new_stable(g)));
+ trees.push_token_from_parser(TokenTree::Group(crate::Group::_new_fallback(g)));
} else {
let (rest, mut tt) = match leaf_token(input) {
Ok((rest, tt)) => (rest, tt),
Err(Reject) => return Err(lex_error(input)),
};
- tt.set_span(crate::Span::_new_stable(Span {
+ tt.set_span(crate::Span::_new_fallback(Span {
#[cfg(span_locations)]
lo,
#[cfg(span_locations)]
@@ -251,7 +251,7 @@ fn lex_error(cursor: Cursor) -> LexError {
fn leaf_token(input: Cursor) -> PResult<TokenTree> {
if let Ok((input, l)) = literal(input) {
// must be parsed before ident
- Ok((input, TokenTree::Literal(crate::Literal::_new_stable(l))))
+ Ok((input, TokenTree::Literal(crate::Literal::_new_fallback(l))))
} else if let Ok((input, p)) = punct(input) {
Ok((input, TokenTree::Punct(p)))
} else if let Ok((input, i)) = ident(input) {
@@ -472,6 +472,10 @@ fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
_ => return Err(Reject),
}
}
+ if n > 255 {
+ // https://github.com/rust-lang/rust/pull/95251
+ return Err(Reject);
+ }
while let Some((i, ch)) = chars.next() {
match ch {
'"' if input.rest[i + 1..].starts_with(&input.rest[..n]) => {
@@ -791,7 +795,7 @@ fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult
#[cfg(span_locations)]
let lo = input.off;
let (rest, (comment, inner)) = doc_comment_contents(input)?;
- let span = crate::Span::_new_stable(Span {
+ let span = crate::Span::_new_fallback(Span {
#[cfg(span_locations)]
lo,
#[cfg(span_locations)]
@@ -827,7 +831,7 @@ fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult
bracketed.push_token_from_parser(TokenTree::Punct(equal));
bracketed.push_token_from_parser(TokenTree::Literal(literal));
let group = Group::new(Delimiter::Bracket, bracketed.build());
- let mut group = crate::Group::_new_stable(group);
+ let mut group = crate::Group::_new_fallback(group);
group.set_span(span);
trees.push_token_from_parser(TokenTree::Group(group));
diff --git a/vendor/proc-macro2/src/wrapper.rs b/vendor/proc-macro2/src/wrapper.rs
index bc800d56d..00f67cd62 100644
--- a/vendor/proc-macro2/src/wrapper.rs
+++ b/vendor/proc-macro2/src/wrapper.rs
@@ -40,7 +40,7 @@ impl LexError {
}
fn mismatch() -> ! {
- panic!("stable/nightly mismatch")
+ panic!("compiler/fallback mismatch")
}
impl DeferredTokenStream {
@@ -131,13 +131,13 @@ impl Display for TokenStream {
}
impl From<proc_macro::TokenStream> for TokenStream {
- fn from(inner: proc_macro::TokenStream) -> TokenStream {
+ fn from(inner: proc_macro::TokenStream) -> Self {
TokenStream::Compiler(DeferredTokenStream::new(inner))
}
}
impl From<TokenStream> for proc_macro::TokenStream {
- fn from(inner: TokenStream) -> proc_macro::TokenStream {
+ fn from(inner: TokenStream) -> Self {
match inner {
TokenStream::Compiler(inner) => inner.into_token_stream(),
TokenStream::Fallback(inner) => inner.to_string().parse().unwrap(),
@@ -146,7 +146,7 @@ impl From<TokenStream> for proc_macro::TokenStream {
}
impl From<fallback::TokenStream> for TokenStream {
- fn from(inner: fallback::TokenStream) -> TokenStream {
+ fn from(inner: fallback::TokenStream) -> Self {
TokenStream::Fallback(inner)
}
}
@@ -170,7 +170,7 @@ fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree {
}
impl From<TokenTree> for TokenStream {
- fn from(token: TokenTree) -> TokenStream {
+ fn from(token: TokenTree) -> Self {
if inside_proc_macro() {
TokenStream::Compiler(DeferredTokenStream::new(into_compiler_token(token).into()))
} else {
@@ -263,13 +263,13 @@ impl LexError {
}
impl From<proc_macro::LexError> for LexError {
- fn from(e: proc_macro::LexError) -> LexError {
+ fn from(e: proc_macro::LexError) -> Self {
LexError::Compiler(e)
}
}
impl From<fallback::LexError> for LexError {
- fn from(e: fallback::LexError) -> LexError {
+ fn from(e: fallback::LexError) -> Self {
LexError::Fallback(e)
}
}
@@ -530,6 +530,16 @@ impl Span {
}
}
+ pub fn source_text(&self) -> Option<String> {
+ match self {
+ #[cfg(not(no_source_text))]
+ Span::Compiler(s) => s.source_text(),
+ #[cfg(no_source_text)]
+ Span::Compiler(_) => None,
+ Span::Fallback(s) => s.source_text(),
+ }
+ }
+
fn unwrap_nightly(self) -> proc_macro::Span {
match self {
Span::Compiler(s) => s,
@@ -539,13 +549,13 @@ impl Span {
}
impl From<proc_macro::Span> for crate::Span {
- fn from(proc_span: proc_macro::Span) -> crate::Span {
+ fn from(proc_span: proc_macro::Span) -> Self {
crate::Span::_new(Span::Compiler(proc_span))
}
}
impl From<fallback::Span> for Span {
- fn from(inner: fallback::Span) -> Span {
+ fn from(inner: fallback::Span) -> Self {
Span::Fallback(inner)
}
}
@@ -929,7 +939,7 @@ impl Literal {
}
impl From<fallback::Literal> for Literal {
- fn from(s: fallback::Literal) -> Literal {
+ fn from(s: fallback::Literal) -> Self {
Literal::Fallback(s)
}
}