Skip to content

Commit 7e3788e

Browse files
committed
rust: fix clippy warnings
1 parent b533221 commit 7e3788e

File tree

8 files changed

+30
-24
lines changed

8 files changed

+30
-24
lines changed

rust/bear/src/bin/wrapper.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn next_in_path(target: &Path) -> Result<PathBuf> {
8787
.map(|dir| Path::new(dir).join(target))
8888
// FIXME: check if it is executable
8989
.filter(|path| path.is_file())
90-
.filter(|path| {
90+
.find(|path| {
9191
// We need to compare it with the real path of the candidate executable to avoid
9292
// calling the same executable again.
9393
let real_path = match path.canonicalize() {
@@ -96,7 +96,6 @@ fn next_in_path(target: &Path) -> Result<PathBuf> {
9696
};
9797
real_path != current_exe
9898
})
99-
.next()
10099
.ok_or_else(|| anyhow::anyhow!("Cannot find the real executable"))
101100
}
102101

rust/bear/src/ipc/tcp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Envelope {
5757

5858
/// Implements convenient methods for the `ReporterId` type.
5959
impl ReporterId {
60-
pub fn new() -> Self {
60+
pub fn generate() -> Self {
6161
let id = random::<u64>();
6262
ReporterId(id)
6363
}
@@ -160,7 +160,7 @@ impl ReporterOnTcp {
160160
/// It does not open the TCP connection yet. Stores the destination
161161
/// address and creates a unique reporter id.
162162
pub fn new(destination: String) -> Result<Self, anyhow::Error> {
163-
let reporter_id = ReporterId::new();
163+
let reporter_id = ReporterId::generate();
164164
let result = ReporterOnTcp {
165165
destination,
166166
reporter_id,
@@ -265,7 +265,7 @@ mod tests {
265265
std::sync::LazyLock::new(|| {
266266
vec![
267267
Envelope {
268-
rid: ReporterId::new(),
268+
rid: ReporterId::generate(),
269269
timestamp: timestamp(),
270270
event: Event {
271271
pid: pid(),
@@ -278,7 +278,7 @@ mod tests {
278278
},
279279
},
280280
Envelope {
281-
rid: ReporterId::new(),
281+
rid: ReporterId::generate(),
282282
timestamp: timestamp(),
283283
event: Event {
284284
pid: pid(),
@@ -300,7 +300,7 @@ mod tests {
300300
},
301301
},
302302
Envelope {
303-
rid: ReporterId::new(),
303+
rid: ReporterId::generate(),
304304
timestamp: timestamp(),
305305
event: Event {
306306
pid: pid(),

rust/bear/src/output/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ impl config::Format {
132132
} else {
133133
clang::write_with_command
134134
};
135-
let result = method(writer, entries)?;
136-
Ok(result)
135+
method(writer, entries)?;
136+
137+
Ok(())
137138
}
138139

139140
/// Convert the compiler calls into entries.
@@ -182,7 +183,7 @@ impl config::Format {
182183
file: into_fully_qualified_path(source.clone(), working_dir)?,
183184
directory: working_dir.to_path_buf(),
184185
output: self.try_convert_to_output(output, working_dir)?,
185-
arguments: Self::try_convert_into_arguments(&compiler, source, output, flags)?,
186+
arguments: Self::try_convert_into_arguments(compiler, source, output, flags)?,
186187
};
187188
Ok(entry)
188189
}

rust/bear/src/semantic/interpreters/combinators.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pub(super) struct Any {
1010
}
1111

1212
impl Any {
13-
pub(super) fn new(tools: Vec<Box<dyn Interpreter>>) -> impl Interpreter {
14-
Any {
13+
pub(super) fn new(tools: Vec<Box<dyn Interpreter>>) -> Self {
14+
Self {
1515
interpreters: tools,
1616
}
1717
}

rust/bear/src/semantic/interpreters/gcc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use internal::Argument;
1010
pub(super) struct Gcc {}
1111

1212
impl Gcc {
13-
pub(super) fn new() -> Box<dyn Interpreter> {
14-
Box::new(Gcc {})
13+
pub(super) fn new() -> Self {
14+
Gcc {}
1515
}
1616
}
1717

rust/bear/src/semantic/interpreters/generic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub(super) struct Generic {
1313
}
1414

1515
impl Generic {
16-
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Interpreter> {
16+
pub(super) fn from(compilers: &[PathBuf]) -> Self {
1717
let executables = compilers.iter().cloned().collect();
18-
Box::new(Self { executables })
18+
Self { executables }
1919
}
2020
}
2121

rust/bear/src/semantic/interpreters/ignore.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ pub(super) struct IgnoreByPath {
1111
}
1212

1313
impl IgnoreByPath {
14-
pub(super) fn new() -> Box<dyn Interpreter> {
14+
pub(super) fn new() -> Self {
1515
let executables = COREUTILS_FILES.iter().map(PathBuf::from).collect();
16-
Box::new(Self { executables })
16+
Self { executables }
1717
}
1818

19-
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Interpreter> {
19+
pub(super) fn from(compilers: &[PathBuf]) -> Self {
2020
let executables = compilers.iter().cloned().collect();
21-
Box::new(Self { executables })
21+
Self { executables }
2222
}
2323
}
2424

rust/bear/src/semantic/interpreters/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ impl Builder {
2626
Builder {
2727
interpreters: vec![
2828
// ignore executables which are not compilers,
29-
IgnoreByPath::new(),
29+
Box::new(IgnoreByPath::new()),
3030
// recognize default compiler
31-
Generic::from(&[PathBuf::from("/usr/bin/g++")]),
31+
Box::new(Generic::from(&[PathBuf::from("/usr/bin/g++")])),
3232
],
3333
}
3434
}
@@ -43,7 +43,7 @@ impl Builder {
4343
if !compilers.is_empty() {
4444
// Add the new compilers at the end of the interpreters.
4545
let tool = Generic::from(compilers);
46-
self.interpreters.push(tool);
46+
self.interpreters.push(Box::new(tool));
4747
}
4848
self
4949
}
@@ -53,12 +53,18 @@ impl Builder {
5353
if !compilers.is_empty() {
5454
// Add these new compilers at the front of the interpreters.
5555
let tool = IgnoreByPath::from(compilers);
56-
self.interpreters.insert(0, tool);
56+
self.interpreters.insert(0, Box::new(tool));
5757
}
5858
self
5959
}
6060
}
6161

62+
impl Default for Builder {
63+
fn default() -> Self {
64+
Builder::new()
65+
}
66+
}
67+
6268
#[cfg(test)]
6369
mod test {
6470
use std::collections::HashMap;

0 commit comments

Comments
 (0)