Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use std::{error, fmt};

#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
pub use diagnostic::{Diagnostic, Level, MultiSpan};
#[unstable(feature = "proc_macro_value", issue = "136652")]
#[stable(feature = "proc_macro_value", since = "CURRENT_RUSTC_VERSION")]
pub use rustc_literal_escaper::EscapeError;
Comment thread
GuillaumeGomez marked this conversation as resolved.
use rustc_literal_escaper::{
MixedUnit, unescape_byte, unescape_byte_str, unescape_c_str, unescape_char, unescape_str,
Expand All @@ -64,7 +64,7 @@ use crate::bridge::client::Methods as BridgeMethods;
use crate::escape::{EscapeOptions, escape_bytes};

/// Errors returned when trying to retrieve a literal unescaped value.
#[unstable(feature = "proc_macro_value", issue = "136652")]
#[stable(feature = "proc_macro_value", since = "CURRENT_RUSTC_VERSION")]
#[derive(Debug, PartialEq, Eq)]
pub enum ConversionErrorKind {
Comment on lines +67 to 69

@traviscross traviscross May 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make this non_exhaustive before stabilizing it?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one, not sure if it'll ever need to be updated though.

/// The literal failed to be escaped, take a look at [`EscapeError`] for more information.
Expand Down Expand Up @@ -1454,7 +1454,7 @@ impl Literal {
}

/// Returns the unescaped character value if the current literal is a byte character literal.
#[unstable(feature = "proc_macro_value", issue = "136652")]
#[stable(feature = "proc_macro_value", since = "CURRENT_RUSTC_VERSION")]
pub fn byte_character_value(&self) -> Result<u8, ConversionErrorKind> {
self.0.symbol.with(|symbol| match self.0.kind {
bridge::LitKind::Char => {
Comment on lines +1457 to 1460

@traviscross traviscross May 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we stabilize, do we mean to match on Char here or Byte? Currently byte_character(b'A').byte_character_value() leads to Err(InvalidLiteralKind).

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point, gonna fix that.

Expand All @@ -1465,7 +1465,7 @@ impl Literal {
}

/// Returns the unescaped character value if the current literal is a character literal.
#[unstable(feature = "proc_macro_value", issue = "136652")]
#[stable(feature = "proc_macro_value", since = "CURRENT_RUSTC_VERSION")]
pub fn character_value(&self) -> Result<char, ConversionErrorKind> {
self.0.symbol.with(|symbol| match self.0.kind {
bridge::LitKind::Char => {
Expand All @@ -1476,7 +1476,7 @@ 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")]
#[stable(feature = "proc_macro_value", since = "CURRENT_RUSTC_VERSION")]
pub fn str_value(&self) -> Result<String, ConversionErrorKind> {
self.0.symbol.with(|symbol| match self.0.kind {
bridge::LitKind::Str => {
Expand Down Expand Up @@ -1510,7 +1510,7 @@ impl Literal {

/// 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")]
#[stable(feature = "proc_macro_value", since = "CURRENT_RUSTC_VERSION")]
pub fn cstr_value(&self) -> Result<Vec<u8>, ConversionErrorKind> {
self.0.symbol.with(|symbol| match self.0.kind {
bridge::LitKind::CStr => {
Expand Down Expand Up @@ -1549,7 +1549,7 @@ impl Literal {

/// 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")]
#[stable(feature = "proc_macro_value", since = "CURRENT_RUSTC_VERSION")]
pub fn byte_str_value(&self) -> Result<Vec<u8>, ConversionErrorKind> {
self.0.symbol.with(|symbol| match self.0.kind {
bridge::LitKind::ByteStr => {
Expand Down
Loading