Skip to content

Commit e67a40d

Browse files
committed
rust: fix clippy warnings
1 parent bced180 commit e67a40d

File tree

11 files changed

+25
-26
lines changed

11 files changed

+25
-26
lines changed

rust/bear/src/bin/bear.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use bear::modes::transformation::Transformation;
66
use bear::modes::{All, Intercept, Mode, Semantic};
77
use bear::output::OutputWriter;
88
use bear::{args, config};
9-
use log;
109
use std::env;
1110
use std::process::ExitCode;
1211

@@ -86,6 +85,6 @@ impl Application {
8685
Application::All(all) => all.run(),
8786
};
8887
// TODO: log the status
89-
status.unwrap_or_else(|_| ExitCode::FAILURE)
88+
status.unwrap_or(ExitCode::FAILURE)
9089
}
9190
}

rust/bear/src/bin/wrapper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,21 @@ fn next_in_path(target: &Path) -> Result<PathBuf> {
9494
};
9595
real_path != current_exe
9696
})
97-
.nth(0)
97+
.next()
9898
.ok_or_else(|| anyhow::anyhow!("Cannot find the real executable"))
9999
}
100100

101101
fn report(execution: Execution) -> Result<()> {
102102
let event = Event {
103-
pid: ProcessId(std::process::id() as u32),
103+
pid: ProcessId(std::process::id()),
104104
execution,
105105
};
106106

107107
// Get the reporter address from the environment
108108
std::env::var(KEY_DESTINATION)
109109
.with_context(|| format!("${} is missing from the environment", KEY_DESTINATION))
110110
// Create a new reporter
111-
.and_then(|reporter_address| TcpReporter::new(reporter_address))
111+
.and_then(TcpReporter::new)
112112
.with_context(|| "Cannot create TCP execution reporter")
113113
// Report the execution
114114
.and_then(|reporter| reporter.report(event))

rust/bear/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl Validate for Intercept {
287287
/// Allow to customize the output format of the compiler calls.
288288
///
289289
/// - Clang: Output the compiler calls in the clang project defined "JSON compilation database"
290-
/// format. (The format is used by clang tooling and other tools based on that library.)
290+
/// format. (The format is used by clang tooling and other tools based on that library.)
291291
/// - Semantic: Output the compiler calls in the semantic format. (The format is not defined yet.)
292292
#[derive(Debug, PartialEq, Deserialize, Serialize)]
293293
#[serde(tag = "specification")]
@@ -484,8 +484,8 @@ impl Validate for DuplicateFilter {
484484
fn validate(self) -> Result<Self> {
485485
let result = Self {
486486
by_fields: (&self.by_fields)
487-
.into_iter()
488-
.map(|field| field.clone())
487+
.iter()
488+
.cloned()
489489
.collect::<HashSet<_>>()
490490
.into_iter()
491491
.collect(),

rust/bear/src/modes/intercept.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl InterceptEnvironment {
115115
// Create a temporary directory and populate it with the executables.
116116
let bin_dir = tempfile::TempDir::with_prefix_in(directory, "bear-")?;
117117
for executable in executables {
118-
std::fs::hard_link(&executable, &path)?;
118+
std::fs::hard_link(executable, path)?;
119119
}
120120
InterceptEnvironment::Wrapper { bin_dir, address }
121121
}

rust/bear/src/modes/recognition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl TryFrom<&config::Main> for Recognition {
3232
};
3333
let compilers_to_exclude = match &config.output {
3434
config::Output::Clang { compilers, .. } => compilers
35-
.into_iter()
35+
.iter()
3636
.filter(|compiler| compiler.ignore == config::Ignore::Always)
3737
.map(|compiler| compiler.path.clone())
3838
.collect(),

rust/bear/src/modes/transformation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Transformation {
3737
passes,
3838
working_dir,
3939
} = &input;
40-
match self.lookup(&compiler) {
40+
match self.lookup(compiler) {
4141
Some(config::Compiler {
4242
ignore: config::Ignore::Always,
4343
..

rust/bear/src/output/filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mod builder {
7878
if paths.is_empty() {
7979
Self::new()
8080
} else {
81-
let owned_paths: Vec<PathBuf> = paths.iter().cloned().collect();
81+
let owned_paths: Vec<PathBuf> = paths.to_vec();
8282
Self::from(move |entry| owned_paths.iter().any(|path| entry.file.starts_with(path)))
8383
}
8484
}
@@ -153,7 +153,7 @@ mod builder {
153153
// FIXME: write unit tests for the hash function.
154154
/// Create a hash function that is using the given fields to calculate the hash of an entry.
155155
pub(super) fn create_hash(fields: &[config::OutputFields]) -> impl Fn(&Entry) -> u64 + 'static {
156-
let owned_fields: Vec<config::OutputFields> = fields.iter().cloned().collect();
156+
let owned_fields: Vec<config::OutputFields> = fields.to_vec();
157157
move |entry: &Entry| {
158158
let mut hasher = DefaultHasher::new();
159159
for field in &owned_fields {

rust/bear/src/output/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ pub fn into_entries(value: semantic::CompilerCall) -> Result<Vec<Entry>, anyhow:
161161
}
162162

163163
fn into_arguments(
164-
compiler: &PathBuf,
165-
source: &PathBuf,
164+
compiler: &Path,
165+
source: &Path,
166166
output: &Option<PathBuf>,
167167
flags: &Vec<String>,
168168
) -> Result<Vec<String>, anyhow::Error> {
169169
let mut arguments: Vec<String> = vec![];
170170
// Assemble the arguments as it would be for a single source file.
171-
arguments.push(into_string(&compiler)?);
171+
arguments.push(into_string(compiler)?);
172172
for flag in flags {
173173
arguments.push(flag.clone());
174174
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ mod internal {
8888
}
8989

9090
/// Compiler flags are varies the number of arguments, but means one thing.
91-
pub(crate) struct Argument<'a> {
91+
pub(super) struct Argument<'a> {
9292
arguments: &'a [String],
9393
meaning: Meaning,
9494
}
9595

9696
impl<'a> Argument<'a> {
97-
pub(crate) fn passes(flags: &[Argument]) -> Vec<CompilerPass> {
97+
pub(super) fn passes(flags: &[Argument]) -> Vec<CompilerPass> {
9898
let mut pass: Pass = Pass::Linker;
9999
let mut inputs: Vec<String> = vec![];
100100
let mut output: Option<String> = None;
@@ -106,13 +106,13 @@ mod internal {
106106
stop_before: Some(Pass::Compiler),
107107
} => {
108108
pass = Pass::Preprocessor;
109-
args.extend(flag.arguments.into_iter().map(String::to_owned));
109+
args.extend(flag.arguments.iter().map(String::to_owned));
110110
}
111111
Meaning::ControlKindOfOutput {
112112
stop_before: Some(Pass::Linker),
113113
} => {
114114
pass = Pass::Compiler;
115-
args.extend(flag.arguments.into_iter().map(String::to_owned));
115+
args.extend(flag.arguments.iter().map(String::to_owned));
116116
}
117117
Meaning::ControlKindOfOutput { .. }
118118
| Meaning::ControlLanguage(_)
@@ -123,7 +123,7 @@ mod internal {
123123
| Meaning::Optimize
124124
| Meaning::Instrumentation
125125
| Meaning::DirectorySearch(None) => {
126-
args.extend(flag.arguments.into_iter().map(String::to_owned));
126+
args.extend(flag.arguments.iter().map(String::to_owned));
127127
}
128128
Meaning::Input(_) => {
129129
assert_eq!(flag.arguments.len(), 1);
@@ -156,7 +156,7 @@ mod internal {
156156
}
157157
}
158158

159-
pub(crate) fn compiler(i: &[String]) -> IResult<&[String], Argument> {
159+
pub(super) fn compiler(i: &[String]) -> IResult<&[String], Argument> {
160160
let candidate = &i[0];
161161
if COMPILER_REGEX.is_match(candidate) {
162162
const MEANING: Meaning = Meaning::Compiler;
@@ -173,7 +173,7 @@ mod internal {
173173
}
174174
}
175175

176-
pub(crate) fn source(i: &[String]) -> IResult<&[String], Argument> {
176+
pub(super) fn source(i: &[String]) -> IResult<&[String], Argument> {
177177
let candidate = &i[0];
178178
if looks_like_a_source_file(candidate.as_str()) {
179179
const MEANING: Meaning = Meaning::Input(Pass::Preprocessor);
@@ -189,7 +189,7 @@ mod internal {
189189
}
190190
}
191191

192-
pub(crate) fn flag(i: &[String]) -> IResult<&[String], Argument> {
192+
pub(super) fn flag(_i: &[String]) -> IResult<&[String], Argument> {
193193
todo!()
194194
}
195195

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) struct Generic {
1414

1515
impl Generic {
1616
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Interpreter> {
17-
let executables = compilers.iter().map(|compiler| compiler.clone()).collect();
17+
let executables = compilers.iter().cloned().collect();
1818
Box::new(Self { executables })
1919
}
2020
}

0 commit comments

Comments
 (0)