about summary refs log tree commit diff
path: root/library/proc_macro
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-03-18 13:28:56 +0100
committerRalf Jung <post@ralfj.de>2025-03-18 13:28:56 +0100
commit20d04d8a4029a2b0d07c7b41a64e420c493def0c (patch)
tree54cc9b6e3fde104e70bad7f9269eea7e27a80047 /library/proc_macro
parent75530e9f72a1990ed2305e16fd51d02f47048f12 (diff)
downloadrust-20d04d8a4029a2b0d07c7b41a64e420c493def0c.tar.gz
rust-20d04d8a4029a2b0d07c7b41a64e420c493def0c.zip
Revert "Rollup merge of #136355 - GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu"
This reverts commit 08dfbf49e30d917c89e49eb14cb3f1e8b8a1c9ef, reversing
changes made to 10bcdad7df0de3cfb95c7bdb7b16908e73cafc09.
Diffstat (limited to 'library/proc_macro')
-rw-r--r--library/proc_macro/Cargo.toml1
-rw-r--r--library/proc_macro/src/lib.rs115
2 files changed, 0 insertions, 116 deletions
diff --git a/library/proc_macro/Cargo.toml b/library/proc_macro/Cargo.toml
index f2ac530dfd2..72cb4e4166f 100644
--- a/library/proc_macro/Cargo.toml
+++ b/library/proc_macro/Cargo.toml
@@ -4,7 +4,6 @@ version = "0.0.0"
 edition = "2024"
 
 [dependencies]
-literal-escaper = { path = "../literal-escaper", features = ["rustc-dep-of-std"] }
 std = { path = "../std" }
 # Workaround: when documenting this crate rustdoc will try to load crate named
 # `core` when resolving doc links. Without this line a different `core` will be
diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs
index bd08d59daa8..d9141eab591 100644
--- a/library/proc_macro/src/lib.rs
+++ b/library/proc_macro/src/lib.rs
@@ -28,7 +28,6 @@
 #![feature(restricted_std)]
 #![feature(rustc_attrs)]
 #![feature(extend_one)]
-#![feature(stmt_expr_attributes)]
 #![recursion_limit = "256"]
 #![allow(internal_features)]
 #![deny(ffi_unwind_calls)]
@@ -52,24 +51,11 @@ use std::{error, fmt};
 
 #[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
 pub use diagnostic::{Diagnostic, Level, MultiSpan};
-#[unstable(feature = "proc_macro_value", issue = "136652")]
-pub use literal_escaper::EscapeError;
-use literal_escaper::{MixedUnit, Mode, byte_from_char, unescape_mixed, unescape_unicode};
 #[unstable(feature = "proc_macro_totokens", issue = "130977")]
 pub use to_tokens::ToTokens;
 
 use crate::escape::{EscapeOptions, escape_bytes};
 
-/// Errors returned when trying to retrieve a literal unescaped value.
-#[unstable(feature = "proc_macro_value", issue = "136652")]
-#[derive(Debug, PartialEq, Eq)]
-pub enum ConversionErrorKind {
-    /// The literal failed to be escaped, take a look at [`EscapeError`] for more information.
-    FailedToUnescape(EscapeError),
-    /// Trying to convert a literal with the wrong type.
-    InvalidLiteralKind,
-}
-
 /// Determines whether proc_macro has been made accessible to the currently
 /// running program.
 ///
@@ -1465,107 +1451,6 @@ impl Literal {
             }
         })
     }
-
-    /// Returns the unescaped string value if the current literal is a string or a string literal.
-    #[unstable(feature = "proc_macro_value", issue = "136652")]
-    pub fn str_value(&self) -> Result<String, ConversionErrorKind> {
-        self.0.symbol.with(|symbol| match self.0.kind {
-            bridge::LitKind::Str => {
-                if symbol.contains('\\') {
-                    let mut buf = String::with_capacity(symbol.len());
-                    let mut error = None;
-                    // Force-inlining here is aggressive but the closure is
-                    // called on every char in the string, so it can be hot in
-                    // programs with many long strings containing escapes.
-                    unescape_unicode(
-                        symbol,
-                        Mode::Str,
-                        &mut #[inline(always)]
-                        |_, c| match c {
-                            Ok(c) => buf.push(c),
-                            Err(err) => {
-                                if err.is_fatal() {
-                                    error = Some(ConversionErrorKind::FailedToUnescape(err));
-                                }
-                            }
-                        },
-                    );
-                    if let Some(error) = error { Err(error) } else { Ok(buf) }
-                } else {
-                    Ok(symbol.to_string())
-                }
-            }
-            bridge::LitKind::StrRaw(_) => Ok(symbol.to_string()),
-            _ => Err(ConversionErrorKind::InvalidLiteralKind),
-        })
-    }
-
-    /// Returns the unescaped string value if the current literal is a c-string or a c-string
-    /// literal.
-    #[unstable(feature = "proc_macro_value", issue = "136652")]
-    pub fn cstr_value(&self) -> Result<Vec<u8>, ConversionErrorKind> {
-        self.0.symbol.with(|symbol| match self.0.kind {
-            bridge::LitKind::CStr => {
-                let mut error = None;
-                let mut buf = Vec::with_capacity(symbol.len());
-
-                unescape_mixed(symbol, Mode::CStr, &mut |_span, c| match c {
-                    Ok(MixedUnit::Char(c)) => {
-                        buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes())
-                    }
-                    Ok(MixedUnit::HighByte(b)) => buf.push(b),
-                    Err(err) => {
-                        if err.is_fatal() {
-                            error = Some(ConversionErrorKind::FailedToUnescape(err));
-                        }
-                    }
-                });
-                if let Some(error) = error {
-                    Err(error)
-                } else {
-                    buf.push(0);
-                    Ok(buf)
-                }
-            }
-            bridge::LitKind::CStrRaw(_) => {
-                // Raw strings have no escapes so we can convert the symbol
-                // directly to a `Lrc<u8>` after appending the terminating NUL
-                // char.
-                let mut buf = symbol.to_owned().into_bytes();
-                buf.push(0);
-                Ok(buf)
-            }
-            _ => Err(ConversionErrorKind::InvalidLiteralKind),
-        })
-    }
-
-    /// Returns the unescaped string value if the current literal is a byte string or a byte string
-    /// literal.
-    #[unstable(feature = "proc_macro_value", issue = "136652")]
-    pub fn byte_str_value(&self) -> Result<Vec<u8>, ConversionErrorKind> {
-        self.0.symbol.with(|symbol| match self.0.kind {
-            bridge::LitKind::ByteStr => {
-                let mut buf = Vec::with_capacity(symbol.len());
-                let mut error = None;
-
-                unescape_unicode(symbol, Mode::ByteStr, &mut |_, c| match c {
-                    Ok(c) => buf.push(byte_from_char(c)),
-                    Err(err) => {
-                        if err.is_fatal() {
-                            error = Some(ConversionErrorKind::FailedToUnescape(err));
-                        }
-                    }
-                });
-                if let Some(error) = error { Err(error) } else { Ok(buf) }
-            }
-            bridge::LitKind::ByteStrRaw(_) => {
-                // Raw strings have no escapes so we can convert the symbol
-                // directly to a `Lrc<u8>`.
-                Ok(symbol.to_owned().into_bytes())
-            }
-            _ => Err(ConversionErrorKind::InvalidLiteralKind),
-        })
-    }
 }
 
 /// Parse a single literal from its stringified representation.