about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/proc_macro/src/lib.rs7
-rw-r--r--tests/ui/feature-gates/feature-gate-proc_macro_byte_character.rs10
-rw-r--r--tests/ui/feature-gates/feature-gate-proc_macro_byte_character.stderr12
-rw-r--r--tests/ui/proc-macro/auxiliary/api/mod.rs1
-rw-r--r--tests/ui/proc-macro/auxiliary/api/parse.rs4
5 files changed, 34 insertions, 0 deletions
diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs
index d382fec9352..d322d882cc1 100644
--- a/library/proc_macro/src/lib.rs
+++ b/library/proc_macro/src/lib.rs
@@ -1337,6 +1337,13 @@ impl Literal {
         Literal::new(bridge::LitKind::Char, symbol, None)
     }
 
+    /// Byte character literal.
+    #[unstable(feature = "proc_macro_byte_character", issue = "115268")]
+    pub fn byte_character(byte: u8) -> Literal {
+        let string = [byte].escape_ascii().to_string();
+        Literal::new(bridge::LitKind::Byte, &string, None)
+    }
+
     /// Byte string literal.
     #[stable(feature = "proc_macro_lib2", since = "1.29.0")]
     pub fn byte_string(bytes: &[u8]) -> Literal {
diff --git a/tests/ui/feature-gates/feature-gate-proc_macro_byte_character.rs b/tests/ui/feature-gates/feature-gate-proc_macro_byte_character.rs
new file mode 100644
index 00000000000..0648ce0ee20
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-proc_macro_byte_character.rs
@@ -0,0 +1,10 @@
+// force-host
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::Literal;
+
+fn test() {
+    Literal::byte_character(b'a'); //~ ERROR use of unstable library feature 'proc_macro_byte_character'
+}
diff --git a/tests/ui/feature-gates/feature-gate-proc_macro_byte_character.stderr b/tests/ui/feature-gates/feature-gate-proc_macro_byte_character.stderr
new file mode 100644
index 00000000000..00691538938
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-proc_macro_byte_character.stderr
@@ -0,0 +1,12 @@
+error[E0658]: use of unstable library feature 'proc_macro_byte_character'
+  --> $DIR/feature-gate-proc_macro_byte_character.rs:9:5
+   |
+LL |     Literal::byte_character(b'a');
+   |     ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #115268 <https://github.com/rust-lang/rust/issues/115268> for more information
+   = help: add `#![feature(proc_macro_byte_character)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/proc-macro/auxiliary/api/mod.rs b/tests/ui/proc-macro/auxiliary/api/mod.rs
index 739c25132e7..3bea5d75779 100644
--- a/tests/ui/proc-macro/auxiliary/api/mod.rs
+++ b/tests/ui/proc-macro/auxiliary/api/mod.rs
@@ -4,6 +4,7 @@
 #![crate_type = "proc-macro"]
 #![crate_name = "proc_macro_api_tests"]
 #![feature(proc_macro_span)]
+#![feature(proc_macro_byte_character)]
 #![deny(dead_code)] // catch if a test function is never called
 
 extern crate proc_macro;
diff --git a/tests/ui/proc-macro/auxiliary/api/parse.rs b/tests/ui/proc-macro/auxiliary/api/parse.rs
index 27391f83111..07c9f464961 100644
--- a/tests/ui/proc-macro/auxiliary/api/parse.rs
+++ b/tests/ui/proc-macro/auxiliary/api/parse.rs
@@ -29,12 +29,16 @@ fn test_display_literal() {
     assert_eq!(Literal::character('\'').to_string(), "'\\''");
     assert_eq!(Literal::character('"').to_string(), "'\"'");
     assert_eq!(Literal::character('\u{1}').to_string(), "'\\u{1}'");
+
+    assert_eq!(Literal::byte_character(b'a').to_string(), "b'a'");
+    assert_eq!(Literal::byte_character(0).to_string(), "b'\\x00'");
 }
 
 fn test_parse_literal() {
     assert_eq!("1".parse::<Literal>().unwrap().to_string(), "1");
     assert_eq!("1.0".parse::<Literal>().unwrap().to_string(), "1.0");
     assert_eq!("'a'".parse::<Literal>().unwrap().to_string(), "'a'");
+    assert_eq!("b'a'".parse::<Literal>().unwrap().to_string(), "b'a'");
     assert_eq!("\"\n\"".parse::<Literal>().unwrap().to_string(), "\"\n\"");
     assert_eq!("b\"\"".parse::<Literal>().unwrap().to_string(), "b\"\"");
     assert_eq!("r##\"\"##".parse::<Literal>().unwrap().to_string(), "r##\"\"##");