Skip to content

Commit e602611

Browse files
authored
Unrolled build for #157338
Rollup merge of #157338 - GuillaumeGomez:byte_character_value, r=traviscross,Mark-Simulacrum Make `Literal::byte_character_value` work with bytes as well As noted in [this comment](#151973 (comment)), `byte_character_value` should work for bytes, so this PR fixes it. r? @traviscross
2 parents d56483a + e27598e commit e602611

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

library/proc_macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ impl Literal {
16481648
#[unstable(feature = "proc_macro_value", issue = "136652")]
16491649
pub fn byte_character_value(&self) -> Result<u8, ConversionErrorKind> {
16501650
self.0.symbol.with(|symbol| match self.0.kind {
1651-
bridge::LitKind::Char => unescape_byte(symbol)
1651+
bridge::LitKind::Byte => unescape_byte(symbol)
16521652
.map_err(|err| ConversionErrorKind::FailedToUnescape(err.into())),
16531653
_ => Err(ConversionErrorKind::InvalidLiteralKind),
16541654
})

tests/ui/proc-macro/auxiliary/api/literal.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ignore-tidy-linelength
22

3-
use proc_macro::Literal;
3+
use proc_macro::{EscapeError, Literal, ConversionErrorKind};
44

55
pub fn test() {
66
test_display_literal();
@@ -111,4 +111,17 @@ fn test_literal_value() {
111111
{
112112
assert_eq!(Literal::f32_unsuffixed(15.).f16_value().map(|f| f.to_string()), Ok("15".to_string()));
113113
}
114+
115+
assert_eq!(
116+
Literal::character('A').byte_character_value(),
117+
Err(ConversionErrorKind::InvalidLiteralKind),
118+
);
119+
assert_eq!(
120+
Literal::character('é').byte_character_value(),
121+
Err(ConversionErrorKind::InvalidLiteralKind),
122+
);
123+
assert_eq!(
124+
Literal::byte_character(b'B').byte_character_value(),
125+
Ok(b'B')
126+
);
114127
}

tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(proc_macro_value)]
55
#![feature(f16)]
66
#![feature(cfg_target_has_reliable_f16_f128)]
7+
#![feature(rustc_private)]
78
#![deny(dead_code)] // catch if a test function is never called
89

910
extern crate proc_macro;

0 commit comments

Comments
 (0)