Skip to content

Commit 48fb959

Browse files
jan-auerkhuey
authored andcommitted
Fix warnings and clippy lints
1 parent c00188f commit 48fb959

File tree

7 files changed

+46
-43
lines changed

7 files changed

+46
-43
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use std::io::Read;
7373
let entry = entry?;
7474

7575
let path = entry.path();
76-
let file_name = path.file_name().ok_or(io::Error::new(
76+
let file_name = path.file_name().ok_or_else(|| io::Error::new(
7777
io::ErrorKind::Other,
7878
"no file name for AFL.rs seed test case",
7979
))?;

examples/cppfilt.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::process;
1414

1515
/// Find the index of the first (potential) occurrence of a mangled C++ symbol
1616
/// in the given `haystack`.
17-
#[allow(needless_range_loop)]
1817
fn find_mangled(haystack: &[u8]) -> Option<usize> {
1918
if haystack.is_empty() {
2019
return None;
@@ -34,7 +33,7 @@ fn find_mangled(haystack: &[u8]) -> Option<usize> {
3433

3534
/// Print the given `line` to `out`, with all mangled C++ symbols replaced with
3635
/// their demangled form.
37-
fn demangle_line<W>(out: &mut W, line: &[u8], options: &DemangleOptions) -> io::Result<()>
36+
fn demangle_line<W>(out: &mut W, line: &[u8], options: DemangleOptions) -> io::Result<()>
3837
where
3938
W: Write,
4039
{
@@ -44,7 +43,7 @@ where
4443
write!(out, "{}", String::from_utf8_lossy(&line[..idx]))?;
4544

4645
if let Ok((sym, tail)) = BorrowedSymbol::with_tail(&line[idx..]) {
47-
let demangled = sym.demangle(options).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
46+
let demangled = sym.demangle(&options).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
4847
write!(out, "{}", demangled)?;
4948
line = tail;
5049
} else {
@@ -58,7 +57,7 @@ where
5857

5958
/// Print all the lines from the given `input` to `out`, with all mangled C++
6059
/// symbols replaced with their demangled form.
61-
fn demangle_all<R, W>(input: &mut R, out: &mut W, options: &DemangleOptions) -> io::Result<()>
60+
fn demangle_all<R, W>(input: &mut R, out: &mut W, options: DemangleOptions) -> io::Result<()>
6261
where
6362
R: BufRead,
6463
W: Write,
@@ -110,9 +109,9 @@ fn main() {
110109
accumulated.push_str("\n");
111110
accumulated
112111
}));
113-
demangle_all(&mut input, &mut stdout, &options)
112+
demangle_all(&mut input, &mut stdout, options)
114113
} else {
115-
demangle_all(&mut stdin, &mut stdout, &options)
114+
demangle_all(&mut stdin, &mut stdout, options)
116115
};
117116

118117
let code = match demangle_result {

src/ast.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use std::cell::Cell;
77
#[cfg(feature = "logging")]
88
use std::cell::RefCell;
99
use std::fmt::{self, Write};
10-
#[cfg(feature = "logging")]
11-
use std::error::Error;
1210
use std::hash::{Hash, Hasher};
1311
use std::mem;
1412
use std::ops;
@@ -27,10 +25,10 @@ thread_local! {
2725

2826
impl AutoLogParse {
2927
#[cfg(feature = "logging")]
30-
fn new<'a>(production: &'static str, input: IndexStr<'a>) -> AutoLogParse {
28+
fn new(production: &'static str, input: IndexStr<'_>) -> AutoLogParse {
3129
LOG_DEPTH.with(|depth| {
3230
if *depth.borrow() == 0 {
33-
println!("");
31+
println!();
3432
}
3533

3634
let indent: String = (0..*depth.borrow() * 4).map(|_| ' ').collect();
@@ -93,7 +91,7 @@ impl AutoLogDemangle {
9391
{
9492
LOG_DEPTH.with(|depth| {
9593
if *depth.borrow() == 0 {
96-
println!("");
94+
println!();
9795
}
9896

9997
let indent: String = (0..*depth.borrow() * 4).map(|_| ' ').collect();
@@ -575,7 +573,7 @@ where
575573
pub fn new(
576574
subs: &'a SubstitutionTable,
577575
input: &'a [u8],
578-
options: &DemangleOptions,
576+
options: DemangleOptions,
579577
out: &'a mut W,
580578
) -> DemangleContext<'a, W> {
581579
DemangleContext {
@@ -656,13 +654,12 @@ where
656654

657655
#[inline]
658656
fn pop_inner_if(&mut self, inner: &'a dyn DemangleAsInner<'a, W>) -> bool {
659-
if {
660-
let last = match self.inner.last() {
661-
None => return false,
662-
Some(last) => *last,
663-
};
664-
ptr::eq(last, inner)
665-
} {
657+
let last = match self.inner.last() {
658+
None => return false,
659+
Some(last) => *last,
660+
};
661+
662+
if ptr::eq(last, inner) {
666663
self.inner.pop();
667664
true
668665
} else {
@@ -890,7 +887,7 @@ macro_rules! reference_newtype {
890887
struct $newtype_name($oldtype);
891888

892889
impl $newtype_name {
893-
#[allow(ptr_arg)]
890+
#[allow(clippy::ptr_arg)]
894891
#[allow(unsafe_code)]
895892
fn new(types: &$oldtype) -> &$newtype_name {
896893
unsafe {
@@ -899,7 +896,7 @@ macro_rules! reference_newtype {
899896
// requirements. An immutable reference does not allow
900897
// dropping the referent, so no worries about double-free
901898
// (additionally, see the assertion inside `Drop` below).
902-
mem::transmute(types)
899+
&*(types as *const $oldtype as *const $newtype_name)
903900
}
904901
}
905902
}
@@ -997,7 +994,7 @@ where
997994
ctx.demangle_inner_prefixes(scope)?;
998995

999996
if needs_paren {
1000-
write!(ctx, "{}", ')')?;
997+
write!(ctx, ")")?;
1001998
}
1002999

10031000
write!(ctx, "(")?;
@@ -1424,7 +1421,7 @@ where
14241421
Encoding::Function(ref name, ref fun_ty) => {
14251422
// Even if this function takes no args and doesn't have a return
14261423
// value (see below), it will have the void parameter.
1427-
debug_assert!(fun_ty.0.len() >= 1);
1424+
debug_assert!(!fun_ty.0.is_empty());
14281425

14291426
let scope = if let Some(leaf) = name.get_leaf_name(ctx.subs) {
14301427
match leaf {
@@ -1938,7 +1935,7 @@ impl Parse for NestedName {
19381935
NestedName::Template(cv_qualifiers, ref_qualifier, prefix),
19391936
tail,
19401937
)),
1941-
_ => return Err(error::Error::UnexpectedText),
1938+
_ => Err(error::Error::UnexpectedText),
19421939
}
19431940
}
19441941
}
@@ -2109,10 +2106,10 @@ impl Parse for PrefixHandle {
21092106
try_begin_parse!("PrefixHandle", ctx, input);
21102107

21112108
#[inline]
2112-
fn save<'a, 'b>(
2113-
subs: &'a mut SubstitutionTable,
2109+
fn save(
2110+
subs: &mut SubstitutionTable,
21142111
prefix: Prefix,
2115-
tail_tail: IndexStr<'b>,
2112+
tail_tail: IndexStr<'_>,
21162113
) -> PrefixHandle {
21172114
if let Some(b'E') = tail_tail.peek() {
21182115
// An `E` means that we just finished parsing a `<nested-name>`
@@ -3385,6 +3382,7 @@ impl CtorDtorName {
33853382
/// ::= <substitution>
33863383
/// ```
33873384
#[derive(Clone, Debug, PartialEq, Eq)]
3385+
#[allow(clippy::large_enum_variant)]
33883386
pub enum Type {
33893387
/// A function type.
33903388
Function(FunctionType),
@@ -5058,7 +5056,9 @@ where
50585056
if need_comma {
50595057
write!(ctx, ", ")?;
50605058
}
5061-
scope.as_mut().map(|scope| scope.in_arg = Some((arg_index, self)));
5059+
if let Some(ref mut scope) = scope {
5060+
scope.in_arg = Some((arg_index, self));
5061+
}
50625062
self.0[arg_index].demangle(ctx, scope)?;
50635063
need_comma = true;
50645064
}
@@ -7628,7 +7628,7 @@ mod tests {
76287628
String::from_utf8_lossy(expected_tail)
76297629
);
76307630
}
7631-
if &subs[..] != &expected_subs[..] {
7631+
if subs[..] != expected_subs[..] {
76327632
panic!(
76337633
"Parsing {:?} as {} produced a substitutions table of\n\n\
76347634
{:#?}\n\n\

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
// Clippy stuff.
3535
#![allow(unknown_lints)]
36-
#![allow(inline_always)]
36+
#![allow(clippy::inline_always)]
37+
#![allow(clippy::redundant_field_names)]
3738

3839
#![cfg_attr(all(not(feature = "std"), feature = "alloc"), no_std)]
3940
#![cfg_attr(all(not(feature = "std"), feature = "alloc"), feature(alloc))]
@@ -153,7 +154,7 @@ where
153154
if tail.is_empty() {
154155
parsed
155156
} else {
156-
return Err(Error::UnexpectedText.into());
157+
return Err(Error::UnexpectedText);
157158
}
158159
};
159160

@@ -196,13 +197,14 @@ substitutions = {:#?}",
196197
/// let demangled_again = sym.demangle(&options).unwrap();
197198
/// assert_eq!(demangled_again, demangled);
198199
/// ```
200+
#[allow(clippy::trivially_copy_pass_by_ref)]
199201
pub fn demangle(&self, options: &DemangleOptions) -> ::std::result::Result<String, fmt::Error> {
200202
let mut out = String::new();
201203
{
202204
let mut ctx = ast::DemangleContext::new(
203205
&self.substitutions,
204206
self.raw.as_ref(),
205-
options,
207+
*options,
206208
&mut out,
207209
);
208210
self.parsed.demangle(&mut ctx, None)?;
@@ -213,11 +215,12 @@ substitutions = {:#?}",
213215

214216
/// Demangle the symbol to a DemangleWrite, which lets the consumer be informed about
215217
/// syntactic structure.
218+
#[allow(clippy::trivially_copy_pass_by_ref)]
216219
pub fn structured_demangle<W: DemangleWrite>(&self, out: &mut W, options: &DemangleOptions) -> fmt::Result {
217220
let mut ctx = ast::DemangleContext::new(
218221
&self.substitutions,
219222
self.raw.as_ref(),
220-
options,
223+
*options,
221224
out,
222225
);
223226
self.parsed.demangle(&mut ctx, None)
@@ -307,7 +310,7 @@ impl<'a, T> Symbol<&'a T>
307310
AST = {:#?}
308311
309312
substitutions = {:#?}",
310-
String::from_utf8_lossy(symbol.raw.as_ref()),
313+
String::from_utf8_lossy(symbol.raw),
311314
symbol.parsed,
312315
symbol.substitutions
313316
);
@@ -327,7 +330,7 @@ where
327330
let mut ctx = ast::DemangleContext::new(
328331
&self.substitutions,
329332
self.raw.as_ref(),
330-
&options,
333+
options,
331334
&mut out,
332335
);
333336
self.parsed.demangle(&mut ctx, None).map_err(|err| {

src/subs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use vec::Vec;
1111
/// table.
1212
#[doc(hidden)]
1313
#[derive(Clone, Debug, PartialEq, Eq)]
14+
#[allow(clippy::large_enum_variant)]
1415
pub enum Substitutable {
1516
/// An `<unscoped-template-name>` production.
1617
UnscopedTemplateName(ast::UnscopedTemplateName),

tests/libxul.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::fs;
55
use std::io::{BufRead, BufReader, BufWriter, Write};
66
use std::process;
77

8-
const NUMBER_OF_LIBXUL_SYMBOLS: usize = 274346;
8+
const NUMBER_OF_LIBXUL_SYMBOLS: usize = 274_346;
99

1010
// These counts should only go up!
11-
const NUMBER_OF_LIBXUL_SYMBOLS_THAT_PARSE: usize = 274346;
12-
const NUMBER_OF_LIBXUL_SYMBOLS_THAT_DEMANGLE: usize = 274346;
11+
const NUMBER_OF_LIBXUL_SYMBOLS_THAT_PARSE: usize = 274_346;
12+
const NUMBER_OF_LIBXUL_SYMBOLS_THAT_DEMANGLE: usize = 274_346;
1313

1414
fn get_cppfilt() -> &'static str {
1515
if cfg!(not(target_os = "macos")) {
@@ -87,7 +87,7 @@ fn libxul_symbols_demangle() {
8787

8888
// Demangle the symbol.
8989
demangled.clear();
90-
if let Ok(_) = write!(&mut demangled, "{}", sym) {
90+
if write!(&mut demangled, "{}", sym).is_ok() {
9191
num_demangled += 1;
9292

9393
// Finally, we are going to have `c++filt` demangle the
@@ -96,7 +96,7 @@ fn libxul_symbols_demangle() {
9696
.write_all(&line)
9797
.expect("should write line contents into c++filt");
9898
cppfilt_stdin
99-
.write(b"\n")
99+
.write_all(b"\n")
100100
.expect("should write newline into c++filt");
101101
cppfilt_stdin.flush().expect("should flush c++filt stdin");
102102

tests/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn assert_demangles_as(mangled: &str, expected: &str, options: Option<DemangleOp
2020
};
2121

2222
if expected != actual {
23-
println!("");
23+
println!();
2424
println!("Diff:");
2525
println!("--- expected");
2626
print!("+++ actual");
@@ -43,7 +43,7 @@ fn assert_demangles_as(mangled: &str, expected: &str, options: Option<DemangleOp
4343
}
4444
last = Some(cmp);
4545
}
46-
println!("");
46+
println!();
4747
}
4848

4949
assert_eq!(expected, actual);

0 commit comments

Comments
 (0)