proc_macro_c_str_literals: Implement Literal::c_string constructor
This commit is contained in:
@@ -45,6 +45,7 @@ mod diagnostic;
|
||||
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
|
||||
pub use diagnostic::{Diagnostic, Level, MultiSpan};
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::ops::{Range, RangeBounds};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
@@ -1351,6 +1352,13 @@ impl Literal {
|
||||
Literal::new(bridge::LitKind::ByteStr, &string, None)
|
||||
}
|
||||
|
||||
/// C string literal.
|
||||
#[unstable(feature = "proc_macro_c_str_literals", issue = "119750")]
|
||||
pub fn c_string(string: &CStr) -> Literal {
|
||||
let string = string.to_bytes().escape_ascii().to_string();
|
||||
Literal::new(bridge::LitKind::CStr, &string, None)
|
||||
}
|
||||
|
||||
/// Returns the span encompassing this literal.
|
||||
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
|
||||
pub fn span(&self) -> Span {
|
||||
|
||||
Reference in New Issue
Block a user