aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-21 12:35:42 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:32 +0200
commit09b2be24391d7543fe76c24c3cf790e915e0ff1a (patch)
tree63ffb7702c13c8f9566a13abeaf02c90758af27e
parent77216f03f283f1f2e36319a68f6cf248e6d4acb3 (diff)
downloadgcc-09b2be24391d7543fe76c24c3cf790e915e0ff1a.zip
gcc-09b2be24391d7543fe76c24c3cf790e915e0ff1a.tar.gz
gcc-09b2be24391d7543fe76c24c3cf790e915e0ff1a.tar.bz2
libproc_macro: Minor refactor
Change some bits to make the code more idiomatic/clearer. ChangeLog: * librust/proc_macro/rust/bridge/literal.rs: Make byte range clearer. * librust/proc_macro/rust/bridge/token_stream.rs: Remove old comment. * librust/proc_macro/rust/token_stream.rs: Remove useless return statement. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/bridge/literal.rs2
-rw-r--r--librust/proc_macro/rust/bridge/token_stream.rs4
-rw-r--r--librust/proc_macro/rust/token_stream.rs2
3 files changed, 2 insertions, 6 deletions
diff --git a/librust/proc_macro/rust/bridge/literal.rs b/librust/proc_macro/rust/bridge/literal.rs
index 3251403..c2017ac 100644
--- a/librust/proc_macro/rust/bridge/literal.rs
+++ b/librust/proc_macro/rust/bridge/literal.rs
@@ -252,7 +252,7 @@ impl fmt::Display for Literal {
let slice =
unsafe { std::slice::from_raw_parts(*data, (*size).try_into().unwrap()) };
for &byte in slice {
- if byte != b'"' && byte >= b' ' && byte <= b'z' {
+ if byte != b'"' && (b' '..=b'z').contains(&byte) {
char::try_from(byte).unwrap().fmt(f)?;
} else {
write!(f, "\\x{byte:02x}")?;
diff --git a/librust/proc_macro/rust/bridge/token_stream.rs b/librust/proc_macro/rust/bridge/token_stream.rs
index 1c9825f..56f6679 100644
--- a/librust/proc_macro/rust/bridge/token_stream.rs
+++ b/librust/proc_macro/rust/bridge/token_stream.rs
@@ -17,10 +17,6 @@ extern "C" {
fn TokenStream__clone(ts: *const TokenStream) -> TokenStream;
}
-// TODO: There surely is a better way to achieve this. I don't like this
-// "duplication" of the TokenTree enumeration. But I cannot use the public
-// one since it's underlying types (public Group, Ident...) are not ffi safe.
-// Flattening all those struct might be a solution.
#[repr(C)]
#[derive(Clone)]
pub enum TokenTree {
diff --git a/librust/proc_macro/rust/token_stream.rs b/librust/proc_macro/rust/token_stream.rs
index c4caf9f..9333e3e 100644
--- a/librust/proc_macro/rust/token_stream.rs
+++ b/librust/proc_macro/rust/token_stream.rs
@@ -17,7 +17,7 @@ impl Iterator for IntoIter {
fn next(&mut self) -> Option<TokenTree> {
if self.current == self.end {
- return None;
+ None
} else {
let result = self.current;
self.current = unsafe { self.current.add(1) };