summaryrefslogtreecommitdiffstats
path: root/vendor/proc-macro2/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
commit023939b627b7dc93b01471f7d41fb8553ddb4ffa (patch)
tree60fc59477c605c72b0a1051409062ddecc43f877 /vendor/proc-macro2/src
parentAdding debian version 1.72.1+dfsg1-1. (diff)
downloadrustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.tar.xz
rustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/proc-macro2/src')
-rw-r--r--vendor/proc-macro2/src/convert.rs19
-rw-r--r--vendor/proc-macro2/src/extra.rs20
-rw-r--r--vendor/proc-macro2/src/fallback.rs28
-rw-r--r--vendor/proc-macro2/src/lib.rs13
-rw-r--r--vendor/proc-macro2/src/marker.rs4
-rw-r--r--vendor/proc-macro2/src/parse.rs41
-rw-r--r--vendor/proc-macro2/src/rcvec.rs8
-rw-r--r--vendor/proc-macro2/src/wrapper.rs71
8 files changed, 36 insertions, 168 deletions
diff --git a/vendor/proc-macro2/src/convert.rs b/vendor/proc-macro2/src/convert.rs
deleted file mode 100644
index afc5faf53..000000000
--- a/vendor/proc-macro2/src/convert.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-pub(crate) fn usize_to_u32(u: usize) -> Option<u32> {
- #[cfg(not(no_try_from))]
- {
- use core::convert::TryFrom;
-
- u32::try_from(u).ok()
- }
-
- #[cfg(no_try_from)]
- {
- use core::mem;
-
- if mem::size_of::<usize>() <= mem::size_of::<u32>() || u <= u32::max_value() as usize {
- Some(u as u32)
- } else {
- None
- }
- }
-}
diff --git a/vendor/proc-macro2/src/extra.rs b/vendor/proc-macro2/src/extra.rs
index cbce1626c..4a69d4657 100644
--- a/vendor/proc-macro2/src/extra.rs
+++ b/vendor/proc-macro2/src/extra.rs
@@ -22,9 +22,7 @@ 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),
@@ -36,9 +34,7 @@ impl DelimSpan {
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()),
@@ -66,13 +62,7 @@ impl DelimSpan {
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::Compiler { open, .. } => Span::_new(imp::Span::Compiler(*open)),
DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.first_byte()),
}
}
@@ -81,13 +71,7 @@ impl DelimSpan {
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::Compiler { close, .. } => Span::_new(imp::Span::Compiler(*close)),
DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.last_byte()),
}
}
diff --git a/vendor/proc-macro2/src/fallback.rs b/vendor/proc-macro2/src/fallback.rs
index 1b8b12574..daa1e1708 100644
--- a/vendor/proc-macro2/src/fallback.rs
+++ b/vendor/proc-macro2/src/fallback.rs
@@ -8,7 +8,6 @@ use core::cell::RefCell;
#[cfg(span_locations)]
use core::cmp;
use core::fmt::{self, Debug, Display, Write};
-use core::iter::FromIterator;
use core::mem::ManuallyDrop;
use core::ops::RangeBounds;
use core::ptr;
@@ -71,7 +70,6 @@ impl TokenStream {
fn push_token_from_proc_macro(mut vec: RcVecMut<TokenTree>, token: TokenTree) {
// https://github.com/dtolnay/proc-macro2/issues/235
match token {
- #[cfg(not(no_bind_by_move_pattern_guard))]
TokenTree::Literal(crate::Literal {
#[cfg(wrap_proc_macro)]
inner: crate::imp::Literal::Fallback(literal),
@@ -81,20 +79,6 @@ fn push_token_from_proc_macro(mut vec: RcVecMut<TokenTree>, token: TokenTree) {
}) if literal.repr.starts_with('-') => {
push_negative_literal(vec, literal);
}
- #[cfg(no_bind_by_move_pattern_guard)]
- TokenTree::Literal(crate::Literal {
- #[cfg(wrap_proc_macro)]
- inner: crate::imp::Literal::Fallback(literal),
- #[cfg(not(wrap_proc_macro))]
- inner: literal,
- ..
- }) => {
- if literal.repr.starts_with('-') {
- push_negative_literal(vec, literal);
- } else {
- vec.push(TokenTree::Literal(crate::Literal::_new_fallback(literal)));
- }
- }
_ => vec.push(token),
}
@@ -479,7 +463,6 @@ impl Span {
Span { lo: 0, hi: 0 }
}
- #[cfg(not(no_hygiene))]
pub fn mixed_site() -> Self {
Span::call_site()
}
@@ -769,7 +752,7 @@ fn validate_ident(string: &str, raw: bool) {
panic!("Ident is not allowed to be empty; use Option<Ident>");
}
- if string.bytes().all(|digit| digit >= b'0' && digit <= b'9') {
+ if string.bytes().all(|digit| b'0' <= digit && digit <= b'9') {
panic!("Ident cannot be a number; use Literal instead");
}
@@ -1020,27 +1003,26 @@ impl Literal {
#[cfg(span_locations)]
{
- use crate::convert::usize_to_u32;
use core::ops::Bound;
let lo = match range.start_bound() {
Bound::Included(start) => {
- let start = usize_to_u32(*start)?;
+ let start = u32::try_from(*start).ok()?;
self.span.lo.checked_add(start)?
}
Bound::Excluded(start) => {
- let start = usize_to_u32(*start)?;
+ let start = u32::try_from(*start).ok()?;
self.span.lo.checked_add(start)?.checked_add(1)?
}
Bound::Unbounded => self.span.lo,
};
let hi = match range.end_bound() {
Bound::Included(end) => {
- let end = usize_to_u32(*end)?;
+ let end = u32::try_from(*end).ok()?;
self.span.lo.checked_add(end)?.checked_add(1)?
}
Bound::Excluded(end) => {
- let end = usize_to_u32(*end)?;
+ let end = u32::try_from(*end).ok()?;
self.span.lo.checked_add(end)?
}
Bound::Unbounded => self.span.hi,
diff --git a/vendor/proc-macro2/src/lib.rs b/vendor/proc-macro2/src/lib.rs
index 11d1ede26..910d47b3b 100644
--- a/vendor/proc-macro2/src/lib.rs
+++ b/vendor/proc-macro2/src/lib.rs
@@ -65,7 +65,7 @@
//!
//! To opt into the additional APIs available in the most recent nightly
//! compiler, the `procmacro2_semver_exempt` config flag must be passed to
-//! rustc. We will polyfill those nightly-only APIs back to Rust 1.31.0. As
+//! rustc. We will polyfill those nightly-only APIs back to Rust 1.56.0. As
//! these are unstable APIs that track the nightly compiler, minor versions of
//! proc-macro2 may make breaking changes to them at any time.
//!
@@ -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.63")]
+#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.66")]
#![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
#![cfg_attr(super_unstable, feature(proc_macro_def_site))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
@@ -97,6 +97,7 @@
clippy::items_after_statements,
clippy::let_underscore_untyped,
clippy::manual_assert,
+ clippy::manual_range_contains,
clippy::must_use_candidate,
clippy::needless_doctest_main,
clippy::new_without_default,
@@ -117,6 +118,8 @@ compile_error! {"\
build script as well.
"}
+extern crate alloc;
+
#[cfg(feature = "proc-macro")]
extern crate proc_macro;
@@ -141,8 +144,6 @@ use crate::fallback as imp;
mod imp;
#[cfg(span_locations)]
-mod convert;
-#[cfg(span_locations)]
mod location;
use crate::extra::DelimSpan;
@@ -150,7 +151,6 @@ use crate::marker::Marker;
use core::cmp::Ordering;
use core::fmt::{self, Debug, Display};
use core::hash::{Hash, Hasher};
-use core::iter::FromIterator;
use core::ops::RangeBounds;
use core::str::FromStr;
use std::error::Error;
@@ -402,9 +402,6 @@ impl Span {
/// 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(not(no_hygiene))]
pub fn mixed_site() -> Self {
Span::_new(imp::Span::mixed_site())
}
diff --git a/vendor/proc-macro2/src/marker.rs b/vendor/proc-macro2/src/marker.rs
index 59fd09630..e648dd21a 100644
--- a/vendor/proc-macro2/src/marker.rs
+++ b/vendor/proc-macro2/src/marker.rs
@@ -1,6 +1,6 @@
+use alloc::rc::Rc;
use core::marker::PhantomData;
-use std::panic::{RefUnwindSafe, UnwindSafe};
-use std::rc::Rc;
+use core::panic::{RefUnwindSafe, UnwindSafe};
// Zero sized marker with the correct set of autotrait impls we want all proc
// macro types to have.
diff --git a/vendor/proc-macro2/src/parse.rs b/vendor/proc-macro2/src/parse.rs
index 6c5cb414a..c084e4cb3 100644
--- a/vendor/proc-macro2/src/parse.rs
+++ b/vendor/proc-macro2/src/parse.rs
@@ -104,15 +104,11 @@ fn skip_whitespace(input: Cursor) -> Cursor {
}
}
match byte {
- b' ' | 0x09..=0x0c => {
+ b' ' | 0x09..=0x0d => {
s = s.advance(1);
continue;
}
- b'\r' if s.as_bytes().get(1) == Some(&b'\n') => {
- s = s.advance(2);
- continue;
- }
- b if b <= 0x7f => {}
+ b if b.is_ascii() => {}
_ => {
let ch = s.chars().next().unwrap();
if is_whitespace(ch) {
@@ -388,12 +384,11 @@ fn cooked_string(mut input: Cursor) -> Result<Cursor, Reject> {
Some((_, 'x')) => {
backslash_x_char(&mut chars)?;
}
- Some((_, 'n')) | Some((_, 'r')) | Some((_, 't')) | Some((_, '\\'))
- | Some((_, '\'')) | Some((_, '"')) | Some((_, '0')) => {}
+ Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"' | '0')) => {}
Some((_, 'u')) => {
backslash_u(&mut chars)?;
}
- Some((newline, ch @ '\n')) | Some((newline, ch @ '\r')) => {
+ Some((newline, ch @ ('\n' | '\r'))) => {
input = input.advance(newline + 1);
trailing_backslash(&mut input, ch as u8)?;
chars = input.char_indices();
@@ -451,16 +446,15 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
Some((_, b'x')) => {
backslash_x_byte(&mut bytes)?;
}
- Some((_, b'n')) | Some((_, b'r')) | Some((_, b't')) | Some((_, b'\\'))
- | Some((_, b'0')) | Some((_, b'\'')) | Some((_, b'"')) => {}
- Some((newline, b @ b'\n')) | Some((newline, b @ b'\r')) => {
+ Some((_, b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"')) => {}
+ Some((newline, b @ (b'\n' | b'\r'))) => {
input = input.advance(newline + 1);
trailing_backslash(&mut input, b)?;
bytes = input.bytes().enumerate();
}
_ => break,
},
- b if b < 0x80 => {}
+ b if b.is_ascii() => {}
_ => break,
}
}
@@ -554,14 +548,13 @@ fn cooked_c_string(mut input: Cursor) -> Result<Cursor, Reject> {
Some((_, 'x')) => {
backslash_x_nonzero(&mut chars)?;
}
- Some((_, 'n')) | Some((_, 'r')) | Some((_, 't')) | Some((_, '\\'))
- | Some((_, '\'')) | Some((_, '"')) => {}
+ Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"')) => {}
Some((_, 'u')) => {
if backslash_u(&mut chars)? == '\0' {
break;
}
}
- Some((newline, ch @ '\n')) | Some((newline, ch @ '\r')) => {
+ Some((newline, ch @ ('\n' | '\r'))) => {
input = input.advance(newline + 1);
trailing_backslash(&mut input, ch as u8)?;
chars = input.char_indices();
@@ -581,8 +574,7 @@ fn byte(input: Cursor) -> Result<Cursor, Reject> {
let ok = match bytes.next().map(|(_, b)| b) {
Some(b'\\') => match bytes.next().map(|(_, b)| b) {
Some(b'x') => backslash_x_byte(&mut bytes).is_ok(),
- Some(b'n') | Some(b'r') | Some(b't') | Some(b'\\') | Some(b'0') | Some(b'\'')
- | Some(b'"') => true,
+ Some(b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"') => true,
_ => false,
},
b => b.is_some(),
@@ -605,9 +597,7 @@ fn character(input: Cursor) -> Result<Cursor, Reject> {
Some('\\') => match chars.next().map(|(_, ch)| ch) {
Some('x') => backslash_x_char(&mut chars).is_ok(),
Some('u') => backslash_u(&mut chars).is_ok(),
- Some('n') | Some('r') | Some('t') | Some('\\') | Some('0') | Some('\'') | Some('"') => {
- true
- }
+ Some('n' | 'r' | 't' | '\\' | '0' | '\'' | '"') => true,
_ => false,
},
ch => ch.is_some(),
@@ -621,10 +611,10 @@ fn character(input: Cursor) -> Result<Cursor, Reject> {
}
macro_rules! next_ch {
- ($chars:ident @ $pat:pat $(| $rest:pat)*) => {
+ ($chars:ident @ $pat:pat) => {
match $chars.next() {
Some((_, ch)) => match ch {
- $pat $(| $rest)* => ch,
+ $pat => ch,
_ => return Err(Reject),
},
None => return Err(Reject),
@@ -696,8 +686,7 @@ fn trailing_backslash(input: &mut Cursor, mut last: u8) -> Result<(), Reject> {
return Err(Reject);
}
match whitespace.next() {
- Some((_, b @ b' ')) | Some((_, b @ b'\t')) | Some((_, b @ b'\n'))
- | Some((_, b @ b'\r')) => {
+ Some((_, b @ (b' ' | b'\t' | b'\n' | b'\r'))) => {
last = b;
}
Some((offset, _)) => {
@@ -722,7 +711,7 @@ fn float(input: Cursor) -> Result<Cursor, Reject> {
fn float_digits(input: Cursor) -> Result<Cursor, Reject> {
let mut chars = input.chars().peekable();
match chars.next() {
- Some(ch) if ch >= '0' && ch <= '9' => {}
+ Some(ch) if '0' <= ch && ch <= '9' => {}
_ => return Err(Reject),
}
diff --git a/vendor/proc-macro2/src/rcvec.rs b/vendor/proc-macro2/src/rcvec.rs
index 62298b42f..37955afb1 100644
--- a/vendor/proc-macro2/src/rcvec.rs
+++ b/vendor/proc-macro2/src/rcvec.rs
@@ -1,8 +1,8 @@
+use alloc::rc::Rc;
+use alloc::vec;
use core::mem;
+use core::panic::RefUnwindSafe;
use core::slice;
-use std::panic::RefUnwindSafe;
-use std::rc::Rc;
-use std::vec;
pub(crate) struct RcVec<T> {
inner: Rc<Vec<T>>,
@@ -53,7 +53,7 @@ impl<T> RcVec<T> {
T: Clone,
{
let vec = if let Some(owned) = Rc::get_mut(&mut self.inner) {
- mem::replace(owned, Vec::new())
+ mem::take(owned)
} else {
Vec::clone(&self.inner)
};
diff --git a/vendor/proc-macro2/src/wrapper.rs b/vendor/proc-macro2/src/wrapper.rs
index c422e4f0c..860b6b775 100644
--- a/vendor/proc-macro2/src/wrapper.rs
+++ b/vendor/proc-macro2/src/wrapper.rs
@@ -3,7 +3,6 @@ use crate::detection::inside_proc_macro;
use crate::location::LineColumn;
use crate::{fallback, Delimiter, Punct, Spacing, TokenTree};
use core::fmt::{self, Debug, Display};
-use core::iter::FromIterator;
use core::ops::RangeBounds;
use core::str::FromStr;
use std::panic;
@@ -286,15 +285,7 @@ impl Debug for LexError {
impl Display for LexError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- #[cfg(not(no_lexerror_display))]
LexError::Compiler(e) => Display::fmt(e, f),
- #[cfg(no_lexerror_display)]
- LexError::Compiler(_e) => Display::fmt(
- &fallback::LexError {
- span: fallback::Span::call_site(),
- },
- f,
- ),
LexError::Fallback(e) => Display::fmt(e, f),
}
}
@@ -406,7 +397,6 @@ impl Span {
}
}
- #[cfg(not(no_hygiene))]
pub fn mixed_site() -> Self {
if inside_proc_macro() {
Span::Compiler(proc_macro::Span::mixed_site())
@@ -426,13 +416,7 @@ impl Span {
pub fn resolved_at(&self, other: Span) -> Span {
match (self, other) {
- #[cfg(not(no_hygiene))]
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.resolved_at(b)),
-
- // Name resolution affects semantics, but location is only cosmetic
- #[cfg(no_hygiene)]
- (Span::Compiler(_), Span::Compiler(_)) => other,
-
(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.resolved_at(b)),
_ => mismatch(),
}
@@ -440,13 +424,7 @@ impl Span {
pub fn located_at(&self, other: Span) -> Span {
match (self, other) {
- #[cfg(not(no_hygiene))]
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.located_at(b)),
-
- // Name resolution affects semantics, but location is only cosmetic
- #[cfg(no_hygiene)]
- (Span::Compiler(_), Span::Compiler(_)) => *self,
-
(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.located_at(b)),
_ => mismatch(),
}
@@ -602,20 +580,14 @@ impl Group {
pub fn span_open(&self) -> Span {
match self {
- #[cfg(not(no_group_open_close))]
Group::Compiler(g) => Span::Compiler(g.span_open()),
- #[cfg(no_group_open_close)]
- Group::Compiler(g) => Span::Compiler(g.span()),
Group::Fallback(g) => Span::Fallback(g.span_open()),
}
}
pub fn span_close(&self) -> Span {
match self {
- #[cfg(not(no_group_open_close))]
Group::Compiler(g) => Span::Compiler(g.span_close()),
- #[cfg(no_group_open_close)]
- Group::Compiler(g) => Span::Compiler(g.span()),
Group::Fallback(g) => Span::Fallback(g.span_close()),
}
}
@@ -676,27 +648,7 @@ impl Ident {
pub fn new_raw(string: &str, span: Span) -> Self {
match span {
- #[cfg(not(no_ident_new_raw))]
Span::Compiler(s) => Ident::Compiler(proc_macro::Ident::new_raw(string, s)),
- #[cfg(no_ident_new_raw)]
- Span::Compiler(s) => {
- let _ = proc_macro::Ident::new(string, s);
- // At this point the un-r#-prefixed string is known to be a
- // valid identifier. Try to produce a valid raw identifier by
- // running the `TokenStream` parser, and unwrapping the first
- // token as an `Ident`.
- let raw_prefixed = format!("r#{}", string);
- if let Ok(ts) = raw_prefixed.parse::<proc_macro::TokenStream>() {
- let mut iter = ts.into_iter();
- if let (Some(proc_macro::TokenTree::Ident(mut id)), None) =
- (iter.next(), iter.next())
- {
- id.set_span(s);
- return Ident::Compiler(id);
- }
- }
- panic!("not allowed as a raw identifier: `{}`", raw_prefixed)
- }
Span::Fallback(s) => Ident::Fallback(fallback::Ident::new_raw(string, s)),
}
}
@@ -798,7 +750,7 @@ macro_rules! unsuffixed_integers {
impl Literal {
pub unsafe fn from_str_unchecked(repr: &str) -> Self {
if inside_proc_macro() {
- Literal::Compiler(compiler_literal_from_str(repr).expect("invalid literal"))
+ Literal::Compiler(proc_macro::Literal::from_str(repr).expect("invalid literal"))
} else {
Literal::Fallback(fallback::Literal::from_str_unchecked(repr))
}
@@ -921,7 +873,8 @@ impl FromStr for Literal {
fn from_str(repr: &str) -> Result<Self, Self::Err> {
if inside_proc_macro() {
- compiler_literal_from_str(repr).map(Literal::Compiler)
+ let literal = proc_macro::Literal::from_str(repr)?;
+ Ok(Literal::Compiler(literal))
} else {
let literal = fallback::Literal::from_str(repr)?;
Ok(Literal::Fallback(literal))
@@ -929,24 +882,6 @@ impl FromStr for Literal {
}
}
-fn compiler_literal_from_str(repr: &str) -> Result<proc_macro::Literal, LexError> {
- #[cfg(not(no_literal_from_str))]
- {
- proc_macro::Literal::from_str(repr).map_err(LexError::Compiler)
- }
- #[cfg(no_literal_from_str)]
- {
- let tokens = proc_macro_parse(repr)?;
- let mut iter = tokens.into_iter();
- if let (Some(proc_macro::TokenTree::Literal(literal)), None) = (iter.next(), iter.next()) {
- if literal.to_string().len() == repr.len() {
- return Ok(literal);
- }
- }
- Err(LexError::call_site())
- }
-}
-
impl Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {