Run `rustfmt`
diff --git a/src/legacy.rs b/src/legacy.rs
index 5e30797..96ab482 100644
--- a/src/legacy.rs
+++ b/src/legacy.rs
@@ -78,7 +78,8 @@
}
let mut len = 0usize;
while let Some(d) = c.to_digit(10) {
- len = try!(len.checked_mul(10)
+ len = try!(len
+ .checked_mul(10)
.and_then(|len| len.checked_add(d as usize))
.ok_or(()));
c = try!(chars.next().ok_or(()));
@@ -93,10 +94,13 @@
elements += 1;
}
- Ok((Demangle {
- inner: inner,
- elements: elements,
- }, chars.as_str()))
+ Ok((
+ Demangle {
+ inner: inner,
+ elements: elements,
+ },
+ chars.as_str(),
+ ))
}
// Rust hashes are hex digits with an `h` prepended.
@@ -118,7 +122,7 @@
rest = &rest[..i];
// Skip printing the hash if alternate formatting
// was requested.
- if f.alternate() && element+1 == self.elements && is_rust_hash(&rest) {
+ if f.alternate() && element + 1 == self.elements && is_rust_hash(&rest) {
break;
}
if element != 0 {
@@ -161,7 +165,8 @@
'0'...'9' | 'a'...'f' => true,
_ => false,
});
- let c = u32::from_str_radix(digits, 16).ok()
+ let c = u32::from_str_radix(digits, 16)
+ .ok()
.and_then(char::from_u32);
if let (true, Some(c)) = (all_lower_hex, c) {
// FIXME(eddyb) do we need to filter out control codepoints?
@@ -196,23 +201,27 @@
use std::prelude::v1::*;
macro_rules! t {
- ($a:expr, $b:expr) => (assert!(ok($a, $b)))
+ ($a:expr, $b:expr) => {
+ assert!(ok($a, $b))
+ };
}
macro_rules! t_err {
- ($a:expr) => (assert!(ok_err($a)))
+ ($a:expr) => {
+ assert!(ok_err($a))
+ };
}
macro_rules! t_nohash {
- ($a:expr, $b:expr) => ({
+ ($a:expr, $b:expr) => {{
assert_eq!(format!("{:#}", ::demangle($a)), $b);
- })
+ }};
}
fn ok(sym: &str, expected: &str) -> bool {
match ::try_demangle(sym) {
Ok(s) => {
- if s.to_string() == expected {
+ if s.to_string() == expected {
true
} else {
println!("\n{}\n!=\n{}\n", s, expected);
@@ -259,10 +268,12 @@
t!("_ZN12test$BP$test4foobE", "test*test::foob");
}
-
#[test]
fn demangle_osx() {
- t!("__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E", "alloc::allocator::Layout::for_value::h02a996811f781011");
+ t!(
+ "__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E",
+ "alloc::allocator::Layout::for_value::h02a996811f781011"
+ );
t!("__ZN38_$LT$core..option..Option$LT$T$GT$$GT$6unwrap18_MSG_FILE_LINE_COL17haf7cb8d5824ee659E", "<core::option::Option<T>>::unwrap::_MSG_FILE_LINE_COL::haf7cb8d5824ee659");
t!("__ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17h450e234d27262170E", "core::slice::<impl core::iter::traits::IntoIterator for &'a [T]>::into_iter::h450e234d27262170");
}
@@ -283,8 +294,10 @@
#[test]
fn demangle_trait_impls() {
- t!("_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
- "<Test + 'static as foo::Bar<Test>>::bar");
+ t!(
+ "_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
+ "<Test + 'static as foo::Bar<Test>>::bar"
+ );
}
#[test]
@@ -317,7 +330,10 @@
// One element, no hash.
t!("_ZN3fooE.llvm.9D1C9369", "foo");
t!("_ZN3fooE.llvm.9D1C9369@@16", "foo");
- t_nohash!("_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9", "backtrace::foo");
+ t_nohash!(
+ "_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9",
+ "backtrace::foo"
+ );
}
#[test]
@@ -336,11 +352,14 @@
::demangle("_ZN2222222222222222222222EE").to_string();
::demangle("_ZN5*70527e27.ll34csaғE").to_string();
::demangle("_ZN5*70527a54.ll34_$b.1E").to_string();
- ::demangle("\
- _ZN5~saäb4e\n\
- 2734cOsbE\n\
- 5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
- ").to_string();
+ ::demangle(
+ "\
+ _ZN5~saäb4e\n\
+ 2734cOsbE\n\
+ 5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
+ ",
+ )
+ .to_string();
}
#[test]
diff --git a/src/lib.rs b/src/lib.rs
index 19778d8..1473c9b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -69,11 +69,9 @@
let llvm = ".llvm.";
if let Some(i) = s.find(llvm) {
let candidate = &s[i + llvm.len()..];
- let all_hex = candidate.chars().all(|c| {
- match c {
- 'A' ... 'F' | '0' ... '9' | '@' => true,
- _ => false,
- }
+ let all_hex = candidate.chars().all(|c| match c {
+ 'A'...'F' | '0'...'9' | '@' => true,
+ _ => false,
});
if all_hex {
@@ -162,9 +160,7 @@
// Copied from the documentation of `char::is_ascii_alphanumeric`
fn is_ascii_alphanumeric(c: char) -> bool {
match c {
- '\u{0041}' ... '\u{005A}' |
- '\u{0061}' ... '\u{007A}' |
- '\u{0030}' ... '\u{0039}' => true,
+ '\u{0041}'...'\u{005A}' | '\u{0061}'...'\u{007A}' | '\u{0030}'...'\u{0039}' => true,
_ => false,
}
}
@@ -172,10 +168,10 @@
// Copied from the documentation of `char::is_ascii_punctuation`
fn is_ascii_punctuation(c: char) -> bool {
match c {
- '\u{0021}' ... '\u{002F}' |
- '\u{003A}' ... '\u{0040}' |
- '\u{005B}' ... '\u{0060}' |
- '\u{007B}' ... '\u{007E}' => true,
+ '\u{0021}'...'\u{002F}'
+ | '\u{003A}'...'\u{0040}'
+ | '\u{005B}'...'\u{0060}'
+ | '\u{007B}'...'\u{007E}' => true,
_ => false,
}
}
@@ -184,12 +180,8 @@
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.style {
None => try!(f.write_str(self.original)),
- Some(DemangleStyle::Legacy(ref d)) => {
- try!(fmt::Display::fmt(d, f))
- }
- Some(DemangleStyle::V0(ref d)) => {
- try!(fmt::Display::fmt(d, f))
- }
+ Some(DemangleStyle::Legacy(ref d)) => try!(fmt::Display::fmt(d, f)),
+ Some(DemangleStyle::V0(ref d)) => try!(fmt::Display::fmt(d, f)),
}
f.write_str(self.suffix)
}
@@ -206,23 +198,27 @@
use std::prelude::v1::*;
macro_rules! t {
- ($a:expr, $b:expr) => (assert!(ok($a, $b)))
+ ($a:expr, $b:expr) => {
+ assert!(ok($a, $b))
+ };
}
macro_rules! t_err {
- ($a:expr) => (assert!(ok_err($a)))
+ ($a:expr) => {
+ assert!(ok_err($a))
+ };
}
macro_rules! t_nohash {
- ($a:expr, $b:expr) => ({
+ ($a:expr, $b:expr) => {{
assert_eq!(format!("{:#}", super::demangle($a)), $b);
- })
+ }};
}
fn ok(sym: &str, expected: &str) -> bool {
match super::try_demangle(sym) {
Ok(s) => {
- if s.to_string() == expected {
+ if s.to_string() == expected {
true
} else {
println!("\n{}\n!=\n{}\n", s, expected);
@@ -269,10 +265,12 @@
t!("_ZN12test$BP$test4foobE", "test*test::foob");
}
-
#[test]
fn demangle_osx() {
- t!("__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E", "alloc::allocator::Layout::for_value::h02a996811f781011");
+ t!(
+ "__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E",
+ "alloc::allocator::Layout::for_value::h02a996811f781011"
+ );
t!("__ZN38_$LT$core..option..Option$LT$T$GT$$GT$6unwrap18_MSG_FILE_LINE_COL17haf7cb8d5824ee659E", "<core::option::Option<T>>::unwrap::_MSG_FILE_LINE_COL::haf7cb8d5824ee659");
t!("__ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17h450e234d27262170E", "core::slice::<impl core::iter::traits::IntoIterator for &'a [T]>::into_iter::h450e234d27262170");
}
@@ -293,8 +291,10 @@
#[test]
fn demangle_trait_impls() {
- t!("_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
- "<Test + 'static as foo::Bar<Test>>::bar");
+ t!(
+ "_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
+ "<Test + 'static as foo::Bar<Test>>::bar"
+ );
}
#[test]
@@ -327,7 +327,10 @@
// One element, no hash.
t!("_ZN3fooE.llvm.9D1C9369", "foo");
t!("_ZN3fooE.llvm.9D1C9369@@16", "foo");
- t_nohash!("_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9", "backtrace::foo");
+ t_nohash!(
+ "_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9",
+ "backtrace::foo"
+ );
}
#[test]
@@ -346,11 +349,14 @@
super::demangle("_ZN2222222222222222222222EE").to_string();
super::demangle("_ZN5*70527e27.ll34csaғE").to_string();
super::demangle("_ZN5*70527a54.ll34_$b.1E").to_string();
- super::demangle("\
- _ZN5~saäb4e\n\
- 2734cOsbE\n\
- 5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
- ").to_string();
+ super::demangle(
+ "\
+ _ZN5~saäb4e\n\
+ 2734cOsbE\n\
+ 5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
+ ",
+ )
+ .to_string();
}
#[test]
diff --git a/src/v0.rs b/src/v0.rs
index 7a6c6a2..8afaca1 100644
--- a/src/v0.rs
+++ b/src/v0.rs
@@ -56,9 +56,7 @@
_ => {}
}
- Ok((Demangle {
- inner: inner,
- }, &parser.sym[parser.next..]))
+ Ok((Demangle { inner: inner }, &parser.sym[parser.next..]))
}
impl<'s> Display for Demangle<'s> {
@@ -91,10 +89,7 @@
/// Attempt to decode punycode on the stack (allocation-free),
/// and pass the char slice to the closure, if successful.
/// This supports up to `SMALL_PUNYCODE_LEN` characters.
- fn try_small_punycode_decode<F: FnOnce(&[char]) -> R, R>(
- &self,
- f: F,
- ) -> Option<R> {
+ fn try_small_punycode_decode<F: FnOnce(&[char]) -> R, R>(&self, f: F) -> Option<R> {
let mut out = ['\0'; SMALL_PUNYCODE_LEN];
let mut out_len = 0;
let r = self.punycode_decode(|i, c| {
@@ -158,7 +153,7 @@
let mut w = 1;
let mut k: usize = 0;
loop {
- use core::cmp::{min, max};
+ use core::cmp::{max, min};
k += base;
let t = min(max(k.saturating_sub(bias), t_min), t_max);
@@ -169,9 +164,9 @@
_ => return Err(()),
};
let d = d as usize;
- delta = try!(delta.checked_add(
- try!(d.checked_mul(w).ok_or(()))
- ).ok_or(()));
+ delta = try!(delta
+ .checked_add(try!(d.checked_mul(w).ok_or(())))
+ .ok_or(()));
if d < t {
break;
}
@@ -222,7 +217,8 @@
try!(c.fmt(f));
}
Ok(())
- }).unwrap_or_else(|| {
+ })
+ .unwrap_or_else(|| {
if !self.punycode.is_empty() {
try!(f.write_str("punycode{"));
@@ -492,9 +488,11 @@
try!(self.skip_type());
try!(self.skip_const());
}
- b'T' => while !self.eat(b'E') {
- try!(self.skip_type());
- },
+ b'T' => {
+ while !self.eat(b'E') {
+ try!(self.skip_type());
+ }
+ }
b'F' => {
let _binder = try!(self.opt_integer_62(b'G'));
let _is_unsafe = self.eat(b'U');
@@ -573,7 +571,7 @@
($printer:ident) => {{
$printer.parser = Err(Invalid);
return $printer.out.write_str("?");
- }}
+ }};
}
/// Call a parser method (if the parser hasn't errored yet),
@@ -638,7 +636,8 @@
/// printing e.g. `for<'a, 'b> ` before calling the closure,
/// and make those lifetimes visible to it (via depth level).
fn in_binder<F>(&mut self, f: F) -> fmt::Result
- where F: FnOnce(&mut Self) -> fmt::Result,
+ where
+ F: FnOnce(&mut Self) -> fmt::Result,
{
let bound_lifetimes = parse!(self, opt_integer_62(b'G'));
@@ -666,7 +665,8 @@
/// until the end of the list ('E') is found, or the parser errors.
/// Returns the number of elements printed.
fn print_sep_list<F>(&mut self, f: F, sep: &str) -> Result<usize, fmt::Error>
- where F: Fn(&mut Self) -> fmt::Result,
+ where
+ F: Fn(&mut Self) -> fmt::Result,
{
let mut i = 0;
while self.parser.is_ok() && !self.eat(b'E') {
@@ -952,14 +952,11 @@
let ty_tag = parse!(self, next);
let ty = match ty_tag {
// Unsigned integer types.
- b'h' | b't' | b'm' | b'y' | b'o' | b'j' => {
- basic_type(ty_tag).unwrap()
- }
+ b'h' | b't' | b'm' | b'y' | b'o' | b'j' => basic_type(ty_tag).unwrap(),
_ => invalid!(self),
};
-
if self.eat(b'p') {
try!(self.out.write_str("_"));
} else {
@@ -994,22 +991,19 @@
#[cfg(test)]
mod tests {
macro_rules! t_nohash {
- ($a:expr, $b:expr) => ({
+ ($a:expr, $b:expr) => {{
assert_eq!(format!("{:#}", ::demangle($a)), $b);
- })
+ }};
}
macro_rules! t_nohash_type {
- ($a:expr, $b:expr) => (
+ ($a:expr, $b:expr) => {
t_nohash!(concat!("_RMC0", $a), concat!("<", $b, ">"))
- )
+ };
}
#[test]
fn demangle_crate_with_leading_digit() {
- t_nohash!(
- "_RNvC6_123foo3bar",
- "123foo::bar"
- );
+ t_nohash!("_RNvC6_123foo3bar", "123foo::bar");
}
#[test]
@@ -1060,9 +1054,9 @@
t_nohash_type!(
concat!("TTTTTT", "p", "B8_E", "B7_E", "B6_E", "B5_E", "B4_E", "B3_E"),
"((((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), \
- ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))), \
- (((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), \
- ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))))"
+ ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))), \
+ (((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), \
+ ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))))"
);
}