Skip to content

Commit 987f9a0

Browse files
committed
Run rustfmt
1 parent f4fdee0 commit 987f9a0

File tree

3 files changed

+107
-88
lines changed

3 files changed

+107
-88
lines changed

src/legacy.rs

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ pub fn demangle(s: &str) -> Result<(Demangle, &str), ()> {
7878
}
7979
let mut len = 0usize;
8080
while let Some(d) = c.to_digit(10) {
81-
len = try!(len.checked_mul(10)
81+
len = try!(len
82+
.checked_mul(10)
8283
.and_then(|len| len.checked_add(d as usize))
8384
.ok_or(()));
8485
c = try!(chars.next().ok_or(()));
@@ -93,10 +94,13 @@ pub fn demangle(s: &str) -> Result<(Demangle, &str), ()> {
9394
elements += 1;
9495
}
9596

96-
Ok((Demangle {
97-
inner: inner,
98-
elements: elements,
99-
}, chars.as_str()))
97+
Ok((
98+
Demangle {
99+
inner: inner,
100+
elements: elements,
101+
},
102+
chars.as_str(),
103+
))
100104
}
101105

102106
// Rust hashes are hex digits with an `h` prepended.
@@ -118,7 +122,7 @@ impl<'a> fmt::Display for Demangle<'a> {
118122
rest = &rest[..i];
119123
// Skip printing the hash if alternate formatting
120124
// was requested.
121-
if f.alternate() && element+1 == self.elements && is_rust_hash(&rest) {
125+
if f.alternate() && element + 1 == self.elements && is_rust_hash(&rest) {
122126
break;
123127
}
124128
if element != 0 {
@@ -161,7 +165,8 @@ impl<'a> fmt::Display for Demangle<'a> {
161165
'0'...'9' | 'a'...'f' => true,
162166
_ => false,
163167
});
164-
let c = u32::from_str_radix(digits, 16).ok()
168+
let c = u32::from_str_radix(digits, 16)
169+
.ok()
165170
.and_then(char::from_u32);
166171
if let (true, Some(c)) = (all_lower_hex, c) {
167172
// FIXME(eddyb) do we need to filter out control codepoints?
@@ -196,23 +201,27 @@ mod tests {
196201
use std::prelude::v1::*;
197202

198203
macro_rules! t {
199-
($a:expr, $b:expr) => (assert!(ok($a, $b)))
204+
($a:expr, $b:expr) => {
205+
assert!(ok($a, $b))
206+
};
200207
}
201208

202209
macro_rules! t_err {
203-
($a:expr) => (assert!(ok_err($a)))
210+
($a:expr) => {
211+
assert!(ok_err($a))
212+
};
204213
}
205214

206215
macro_rules! t_nohash {
207-
($a:expr, $b:expr) => ({
216+
($a:expr, $b:expr) => {{
208217
assert_eq!(format!("{:#}", ::demangle($a)), $b);
209-
})
218+
}};
210219
}
211220

212221
fn ok(sym: &str, expected: &str) -> bool {
213222
match ::try_demangle(sym) {
214223
Ok(s) => {
215-
if s.to_string() == expected {
224+
if s.to_string() == expected {
216225
true
217226
} else {
218227
println!("\n{}\n!=\n{}\n", s, expected);
@@ -259,10 +268,12 @@ mod tests {
259268
t!("_ZN12test$BP$test4foobE", "test*test::foob");
260269
}
261270

262-
263271
#[test]
264272
fn demangle_osx() {
265-
t!("__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E", "alloc::allocator::Layout::for_value::h02a996811f781011");
273+
t!(
274+
"__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E",
275+
"alloc::allocator::Layout::for_value::h02a996811f781011"
276+
);
266277
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");
267278
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");
268279
}
@@ -283,8 +294,10 @@ mod tests {
283294

284295
#[test]
285296
fn demangle_trait_impls() {
286-
t!("_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
287-
"<Test + 'static as foo::Bar<Test>>::bar");
297+
t!(
298+
"_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
299+
"<Test + 'static as foo::Bar<Test>>::bar"
300+
);
288301
}
289302

290303
#[test]
@@ -317,7 +330,10 @@ mod tests {
317330
// One element, no hash.
318331
t!("_ZN3fooE.llvm.9D1C9369", "foo");
319332
t!("_ZN3fooE.llvm.9D1C9369@@16", "foo");
320-
t_nohash!("_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9", "backtrace::foo");
333+
t_nohash!(
334+
"_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9",
335+
"backtrace::foo"
336+
);
321337
}
322338

323339
#[test]
@@ -336,11 +352,14 @@ mod tests {
336352
::demangle("_ZN2222222222222222222222EE").to_string();
337353
::demangle("_ZN5*70527e27.ll34csaғE").to_string();
338354
::demangle("_ZN5*70527a54.ll34_$b.1E").to_string();
339-
::demangle("\
340-
_ZN5~saäb4e\n\
341-
2734cOsbE\n\
342-
5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
343-
").to_string();
355+
::demangle(
356+
"\
357+
_ZN5~saäb4e\n\
358+
2734cOsbE\n\
359+
5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
360+
",
361+
)
362+
.to_string();
344363
}
345364

346365
#[test]

src/lib.rs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ pub fn demangle(mut s: &str) -> Demangle {
6969
let llvm = ".llvm.";
7070
if let Some(i) = s.find(llvm) {
7171
let candidate = &s[i + llvm.len()..];
72-
let all_hex = candidate.chars().all(|c| {
73-
match c {
74-
'A' ... 'F' | '0' ... '9' | '@' => true,
75-
_ => false,
76-
}
72+
let all_hex = candidate.chars().all(|c| match c {
73+
'A'...'F' | '0'...'9' | '@' => true,
74+
_ => false,
7775
});
7876

7977
if all_hex {
@@ -162,20 +160,18 @@ fn is_symbol_like(s: &str) -> bool {
162160
// Copied from the documentation of `char::is_ascii_alphanumeric`
163161
fn is_ascii_alphanumeric(c: char) -> bool {
164162
match c {
165-
'\u{0041}' ... '\u{005A}' |
166-
'\u{0061}' ... '\u{007A}' |
167-
'\u{0030}' ... '\u{0039}' => true,
163+
'\u{0041}'...'\u{005A}' | '\u{0061}'...'\u{007A}' | '\u{0030}'...'\u{0039}' => true,
168164
_ => false,
169165
}
170166
}
171167

172168
// Copied from the documentation of `char::is_ascii_punctuation`
173169
fn is_ascii_punctuation(c: char) -> bool {
174170
match c {
175-
'\u{0021}' ... '\u{002F}' |
176-
'\u{003A}' ... '\u{0040}' |
177-
'\u{005B}' ... '\u{0060}' |
178-
'\u{007B}' ... '\u{007E}' => true,
171+
'\u{0021}'...'\u{002F}'
172+
| '\u{003A}'...'\u{0040}'
173+
| '\u{005B}'...'\u{0060}'
174+
| '\u{007B}'...'\u{007E}' => true,
179175
_ => false,
180176
}
181177
}
@@ -184,12 +180,8 @@ impl<'a> fmt::Display for Demangle<'a> {
184180
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
185181
match self.style {
186182
None => try!(f.write_str(self.original)),
187-
Some(DemangleStyle::Legacy(ref d)) => {
188-
try!(fmt::Display::fmt(d, f))
189-
}
190-
Some(DemangleStyle::V0(ref d)) => {
191-
try!(fmt::Display::fmt(d, f))
192-
}
183+
Some(DemangleStyle::Legacy(ref d)) => try!(fmt::Display::fmt(d, f)),
184+
Some(DemangleStyle::V0(ref d)) => try!(fmt::Display::fmt(d, f)),
193185
}
194186
f.write_str(self.suffix)
195187
}
@@ -206,23 +198,27 @@ mod tests {
206198
use std::prelude::v1::*;
207199

208200
macro_rules! t {
209-
($a:expr, $b:expr) => (assert!(ok($a, $b)))
201+
($a:expr, $b:expr) => {
202+
assert!(ok($a, $b))
203+
};
210204
}
211205

212206
macro_rules! t_err {
213-
($a:expr) => (assert!(ok_err($a)))
207+
($a:expr) => {
208+
assert!(ok_err($a))
209+
};
214210
}
215211

216212
macro_rules! t_nohash {
217-
($a:expr, $b:expr) => ({
213+
($a:expr, $b:expr) => {{
218214
assert_eq!(format!("{:#}", super::demangle($a)), $b);
219-
})
215+
}};
220216
}
221217

222218
fn ok(sym: &str, expected: &str) -> bool {
223219
match super::try_demangle(sym) {
224220
Ok(s) => {
225-
if s.to_string() == expected {
221+
if s.to_string() == expected {
226222
true
227223
} else {
228224
println!("\n{}\n!=\n{}\n", s, expected);
@@ -269,10 +265,12 @@ mod tests {
269265
t!("_ZN12test$BP$test4foobE", "test*test::foob");
270266
}
271267

272-
273268
#[test]
274269
fn demangle_osx() {
275-
t!("__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E", "alloc::allocator::Layout::for_value::h02a996811f781011");
270+
t!(
271+
"__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E",
272+
"alloc::allocator::Layout::for_value::h02a996811f781011"
273+
);
276274
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");
277275
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");
278276
}
@@ -293,8 +291,10 @@ mod tests {
293291

294292
#[test]
295293
fn demangle_trait_impls() {
296-
t!("_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
297-
"<Test + 'static as foo::Bar<Test>>::bar");
294+
t!(
295+
"_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
296+
"<Test + 'static as foo::Bar<Test>>::bar"
297+
);
298298
}
299299

300300
#[test]
@@ -327,7 +327,10 @@ mod tests {
327327
// One element, no hash.
328328
t!("_ZN3fooE.llvm.9D1C9369", "foo");
329329
t!("_ZN3fooE.llvm.9D1C9369@@16", "foo");
330-
t_nohash!("_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9", "backtrace::foo");
330+
t_nohash!(
331+
"_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9",
332+
"backtrace::foo"
333+
);
331334
}
332335

333336
#[test]
@@ -346,11 +349,14 @@ mod tests {
346349
super::demangle("_ZN2222222222222222222222EE").to_string();
347350
super::demangle("_ZN5*70527e27.ll34csaғE").to_string();
348351
super::demangle("_ZN5*70527a54.ll34_$b.1E").to_string();
349-
super::demangle("\
350-
_ZN5~saäb4e\n\
351-
2734cOsbE\n\
352-
5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
353-
").to_string();
352+
super::demangle(
353+
"\
354+
_ZN5~saäb4e\n\
355+
2734cOsbE\n\
356+
5usage20h)3\0\0\0\0\0\0\07e2734cOsbE\
357+
",
358+
)
359+
.to_string();
354360
}
355361

356362
#[test]

0 commit comments

Comments
 (0)