Skip to content

Commit

Permalink
rust: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rizsotto committed Nov 17, 2024
1 parent bced180 commit e67a40d
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 26 deletions.
3 changes: 1 addition & 2 deletions rust/bear/src/bin/bear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bear::modes::transformation::Transformation;
use bear::modes::{All, Intercept, Mode, Semantic};
use bear::output::OutputWriter;
use bear::{args, config};
use log;
use std::env;
use std::process::ExitCode;

Expand Down Expand Up @@ -86,6 +85,6 @@ impl Application {
Application::All(all) => all.run(),
};
// TODO: log the status
status.unwrap_or_else(|_| ExitCode::FAILURE)
status.unwrap_or(ExitCode::FAILURE)
}
}
6 changes: 3 additions & 3 deletions rust/bear/src/bin/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,21 @@ fn next_in_path(target: &Path) -> Result<PathBuf> {
};
real_path != current_exe
})
.nth(0)
.next()
.ok_or_else(|| anyhow::anyhow!("Cannot find the real executable"))
}

fn report(execution: Execution) -> Result<()> {
let event = Event {
pid: ProcessId(std::process::id() as u32),
pid: ProcessId(std::process::id()),
execution,
};

// Get the reporter address from the environment
std::env::var(KEY_DESTINATION)
.with_context(|| format!("${} is missing from the environment", KEY_DESTINATION))
// Create a new reporter
.and_then(|reporter_address| TcpReporter::new(reporter_address))
.and_then(TcpReporter::new)
.with_context(|| "Cannot create TCP execution reporter")
// Report the execution
.and_then(|reporter| reporter.report(event))
Expand Down
6 changes: 3 additions & 3 deletions rust/bear/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Validate for Intercept {
/// Allow to customize the output format of the compiler calls.
///
/// - Clang: Output the compiler calls in the clang project defined "JSON compilation database"
/// format. (The format is used by clang tooling and other tools based on that library.)
/// format. (The format is used by clang tooling and other tools based on that library.)
/// - Semantic: Output the compiler calls in the semantic format. (The format is not defined yet.)
#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "specification")]
Expand Down Expand Up @@ -484,8 +484,8 @@ impl Validate for DuplicateFilter {
fn validate(self) -> Result<Self> {
let result = Self {
by_fields: (&self.by_fields)
.into_iter()
.map(|field| field.clone())
.iter()
.cloned()
.collect::<HashSet<_>>()
.into_iter()
.collect(),
Expand Down
2 changes: 1 addition & 1 deletion rust/bear/src/modes/intercept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl InterceptEnvironment {
// Create a temporary directory and populate it with the executables.
let bin_dir = tempfile::TempDir::with_prefix_in(directory, "bear-")?;
for executable in executables {
std::fs::hard_link(&executable, &path)?;
std::fs::hard_link(executable, path)?;
}
InterceptEnvironment::Wrapper { bin_dir, address }
}
Expand Down
2 changes: 1 addition & 1 deletion rust/bear/src/modes/recognition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl TryFrom<&config::Main> for Recognition {
};
let compilers_to_exclude = match &config.output {
config::Output::Clang { compilers, .. } => compilers
.into_iter()
.iter()
.filter(|compiler| compiler.ignore == config::Ignore::Always)
.map(|compiler| compiler.path.clone())
.collect(),
Expand Down
2 changes: 1 addition & 1 deletion rust/bear/src/modes/transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Transformation {
passes,
working_dir,
} = &input;
match self.lookup(&compiler) {
match self.lookup(compiler) {
Some(config::Compiler {
ignore: config::Ignore::Always,
..
Expand Down
4 changes: 2 additions & 2 deletions rust/bear/src/output/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ mod builder {
if paths.is_empty() {
Self::new()
} else {
let owned_paths: Vec<PathBuf> = paths.iter().cloned().collect();
let owned_paths: Vec<PathBuf> = paths.to_vec();
Self::from(move |entry| owned_paths.iter().any(|path| entry.file.starts_with(path)))
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ mod builder {
// FIXME: write unit tests for the hash function.
/// Create a hash function that is using the given fields to calculate the hash of an entry.
pub(super) fn create_hash(fields: &[config::OutputFields]) -> impl Fn(&Entry) -> u64 + 'static {
let owned_fields: Vec<config::OutputFields> = fields.iter().cloned().collect();
let owned_fields: Vec<config::OutputFields> = fields.to_vec();
move |entry: &Entry| {
let mut hasher = DefaultHasher::new();
for field in &owned_fields {
Expand Down
6 changes: 3 additions & 3 deletions rust/bear/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ pub fn into_entries(value: semantic::CompilerCall) -> Result<Vec<Entry>, anyhow:
}

fn into_arguments(
compiler: &PathBuf,
source: &PathBuf,
compiler: &Path,
source: &Path,
output: &Option<PathBuf>,
flags: &Vec<String>,
) -> Result<Vec<String>, anyhow::Error> {
let mut arguments: Vec<String> = vec![];
// Assemble the arguments as it would be for a single source file.
arguments.push(into_string(&compiler)?);
arguments.push(into_string(compiler)?);
for flag in flags {
arguments.push(flag.clone());
}
Expand Down
16 changes: 8 additions & 8 deletions rust/bear/src/semantic/interpreters/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ mod internal {
}

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

impl<'a> Argument<'a> {
pub(crate) fn passes(flags: &[Argument]) -> Vec<CompilerPass> {
pub(super) fn passes(flags: &[Argument]) -> Vec<CompilerPass> {
let mut pass: Pass = Pass::Linker;
let mut inputs: Vec<String> = vec![];
let mut output: Option<String> = None;
Expand All @@ -106,13 +106,13 @@ mod internal {
stop_before: Some(Pass::Compiler),
} => {
pass = Pass::Preprocessor;
args.extend(flag.arguments.into_iter().map(String::to_owned));
args.extend(flag.arguments.iter().map(String::to_owned));
}
Meaning::ControlKindOfOutput {
stop_before: Some(Pass::Linker),
} => {
pass = Pass::Compiler;
args.extend(flag.arguments.into_iter().map(String::to_owned));
args.extend(flag.arguments.iter().map(String::to_owned));
}
Meaning::ControlKindOfOutput { .. }
| Meaning::ControlLanguage(_)
Expand All @@ -123,7 +123,7 @@ mod internal {
| Meaning::Optimize
| Meaning::Instrumentation
| Meaning::DirectorySearch(None) => {
args.extend(flag.arguments.into_iter().map(String::to_owned));
args.extend(flag.arguments.iter().map(String::to_owned));
}
Meaning::Input(_) => {
assert_eq!(flag.arguments.len(), 1);
Expand Down Expand Up @@ -156,7 +156,7 @@ mod internal {
}
}

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion rust/bear/src/semantic/interpreters/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(super) struct Generic {

impl Generic {
pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Interpreter> {
let executables = compilers.iter().map(|compiler| compiler.clone()).collect();
let executables = compilers.iter().cloned().collect();
Box::new(Self { executables })
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/bear/src/semantic/interpreters/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl IgnoreByPath {
}

pub(super) fn from(compilers: &[PathBuf]) -> Box<dyn Interpreter> {
let executables = compilers.iter().map(|compiler| compiler.clone()).collect();
let executables = compilers.iter().cloned().collect();
Box::new(Self { executables })
}
}
Expand Down

0 comments on commit e67a40d

Please sign in to comment.