Use C string literals not cstr!
Since Rust 1.77.0 the language has supported C string literals, so the
`cstr!` macro is no longer needed. Replace existing usages with the
equivalent literal.
See https://doc.rust-lang.org/reference/tokens.html#c-string-literals.
I believe that the two are equivalent:
- Escapes are handled the same way;
- Both allow arbitrary Unicode, which is mapped to UTF-8 (I don't
think we made any use of this);
- Both treat any embedded NUL character as a compile time error.
This is of no significance whatsoever, but it does make the code a
tiny bit simpler. It should not change the compiled code at all, so
no flagging should be needed.
I'm not deleting the macro in this CL; I'll do a follow-up for that,
since there may be usages I can't see, and it has greater chance of
accidental conflict.
Test: TH
Change-Id: I4354b3b0a0c53fbec0c2d78b4182786e4e2d0ce8
diff --git a/guest/pvmfw/src/bootargs.rs b/guest/pvmfw/src/bootargs.rs
index aacd8e0..0a5697f 100644
--- a/guest/pvmfw/src/bootargs.rs
+++ b/guest/pvmfw/src/bootargs.rs
@@ -108,7 +108,6 @@
#[cfg(test)]
mod tests {
use super::*;
- use cstr::cstr;
fn check(raw: &CStr, expected: Result<&[(&str, Option<&str>)], ()>) {
let actual = BootArgsIterator::new(raw);
@@ -136,35 +135,35 @@
#[test]
fn empty() {
- check(cstr!(""), Ok(&[]));
- check(cstr!(" "), Ok(&[]));
- check(cstr!(" \n "), Ok(&[]));
+ check(c"", Ok(&[]));
+ check(c" ", Ok(&[]));
+ check(c" \n ", Ok(&[]));
}
#[test]
fn single() {
- check(cstr!("foo"), Ok(&[("foo", None)]));
- check(cstr!(" foo"), Ok(&[("foo", None)]));
- check(cstr!("foo "), Ok(&[("foo", None)]));
- check(cstr!(" foo "), Ok(&[("foo", None)]));
+ check(c"foo", Ok(&[("foo", None)]));
+ check(c" foo", Ok(&[("foo", None)]));
+ check(c"foo ", Ok(&[("foo", None)]));
+ check(c" foo ", Ok(&[("foo", None)]));
}
#[test]
fn single_with_value() {
- check(cstr!("foo=bar"), Ok(&[("foo", Some("=bar"))]));
- check(cstr!(" foo=bar"), Ok(&[("foo", Some("=bar"))]));
- check(cstr!("foo=bar "), Ok(&[("foo", Some("=bar"))]));
- check(cstr!(" foo=bar "), Ok(&[("foo", Some("=bar"))]));
+ check(c"foo=bar", Ok(&[("foo", Some("=bar"))]));
+ check(c" foo=bar", Ok(&[("foo", Some("=bar"))]));
+ check(c"foo=bar ", Ok(&[("foo", Some("=bar"))]));
+ check(c" foo=bar ", Ok(&[("foo", Some("=bar"))]));
- check(cstr!("foo="), Ok(&[("foo", Some("="))]));
- check(cstr!(" foo="), Ok(&[("foo", Some("="))]));
- check(cstr!("foo= "), Ok(&[("foo", Some("="))]));
- check(cstr!(" foo= "), Ok(&[("foo", Some("="))]));
+ check(c"foo=", Ok(&[("foo", Some("="))]));
+ check(c" foo=", Ok(&[("foo", Some("="))]));
+ check(c"foo= ", Ok(&[("foo", Some("="))]));
+ check(c" foo= ", Ok(&[("foo", Some("="))]));
}
#[test]
fn single_with_quote() {
- check(cstr!("foo=hello\" \"world"), Ok(&[("foo", Some("=hello\" \"world"))]));
+ check(c"foo=hello\" \"world", Ok(&[("foo", Some("=hello\" \"world"))]));
}
#[test]
@@ -175,32 +174,32 @@
#[test]
fn multiple() {
check(
- cstr!(" a=b c=d e= f g "),
+ c" a=b c=d e= f g ",
Ok(&[("a", Some("=b")), ("c", Some("=d")), ("e", Some("=")), ("f", None), ("g", None)]),
);
check(
- cstr!(" a=b \n c=d e= f g"),
+ c" a=b \n c=d e= f g",
Ok(&[("a", Some("=b")), ("c", Some("=d")), ("e", Some("=")), ("f", None), ("g", None)]),
);
}
#[test]
fn incomplete_quote() {
- check(
- cstr!("foo=incomplete\" quote bar=y"),
- Ok(&[("foo", Some("=incomplete\" quote bar=y"))]),
- );
+ check(c"foo=incomplete\" quote bar=y", Ok(&[("foo", Some("=incomplete\" quote bar=y"))]));
}
#[test]
fn complex() {
- check(cstr!(" a a1= b=c d=e,f,g x=\"value with quote\" y=val\"ue with \"multiple\" quo\"te "), Ok(&[
- ("a", None),
- ("a1", Some("=")),
- ("b", Some("=c")),
- ("d", Some("=e,f,g")),
- ("x", Some("=\"value with quote\"")),
- ("y", Some("=val\"ue with \"multiple\" quo\"te")),
- ]));
+ check(
+ c" a a1= b=c d=e,f,g x=\"value with quote\" y=val\"ue with \"multiple\" quo\"te ",
+ Ok(&[
+ ("a", None),
+ ("a1", Some("=")),
+ ("b", Some("=c")),
+ ("d", Some("=e,f,g")),
+ ("x", Some("=\"value with quote\"")),
+ ("y", Some("=val\"ue with \"multiple\" quo\"te")),
+ ]),
+ );
}
}