Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remaining cargo warnings #331

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/collapse/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,9 @@ impl Folder {
} else if self.opt.annotate_jit
&& ((module.starts_with("/tmp/perf-") && module.ends_with(".map"))
|| (module.contains("/jitted-") && module.ends_with(".so")))
&& !func.contains("_[j]")
{
if !func.contains("_[j]") {
func.push_str("_[j]"); // jitted
}
func.push_str("_[j]"); // jitted
}

self.cache_line.push(func);
Expand Down
6 changes: 3 additions & 3 deletions src/flamegraph/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod test {

#[test]
fn func_frame_attrs_map_from_reader() {
let foo = vec![
let foo = [
"foo",
// Without quotes
"title=foo title",
Expand All @@ -201,7 +201,7 @@ mod test {
]
.join("\t");

let bar = vec![
let bar = [
"bar",
"class=bar class",
"href=bar href",
Expand All @@ -211,7 +211,7 @@ mod test {
]
.join("\t");

let s = vec![foo, bar].join("\n");
let s = [foo, bar].join("\n");
let r = s.as_bytes();

let mut expected_inner = AHashMap::default();
Expand Down
8 changes: 4 additions & 4 deletions src/flamegraph/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ pub(super) fn color(
hash ^= *byte as u64;
hash = hash.wrapping_mul(0x100000001b3);
}
let hash1 = (hash as f64 / std::u64::MAX as f64) as f32;
let hash1 = (hash as f64 / u64::MAX as f64) as f32;

// Rotate hash so we get two more distinct numbers
hash ^= 0;
hash = hash.wrapping_mul(0x100000001b3);
let hash2 = (hash as f64 / std::u64::MAX as f64) as f32;
let hash2 = (hash as f64 / u64::MAX as f64) as f32;
hash ^= 0;
hash = hash.wrapping_mul(0x100000001b3);
let hash3 = (hash as f64 / std::u64::MAX as f64) as f32;
let hash3 = (hash as f64 / u64::MAX as f64) as f32;

(hash1, hash2, hash3)
} else {
Expand Down Expand Up @@ -489,7 +489,7 @@ mod tests {

macro_rules! test_hash {
($name:expr, $expected:expr) => {
assert!((dbg!(namehash($name.bytes())) - $expected).abs() < std::f32::EPSILON);
assert!((dbg!(namehash($name.bytes())) - $expected).abs() < f32::EPSILON);
};
}

Expand Down
6 changes: 5 additions & 1 deletion src/flamegraph/color/palette_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ impl PaletteMap {
///
/// The file content will follow the format described in [`from_reader`](Self::from_reader).
pub fn save_to_file(&self, path: &dyn AsRef<Path>) -> io::Result<()> {
let mut file = OpenOptions::new().write(true).create(true).open(path)?;
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(path)?;
self.to_writer(&mut file)
}

Expand Down
10 changes: 5 additions & 5 deletions src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ where
function, samples_txt, opt.count_name, pct
),
// Special case delta == 0 so we don't format percentage with a + sign.
Some(delta) if delta == 0 => write!(
Some(0) => write!(
buffer,
"{} ({} {}, {:.2}%; 0.00%)",
function, samples_txt, opt.count_name, pct,
Expand Down Expand Up @@ -755,18 +755,18 @@ fn write_container_start<'a, W: Write>(
if let Some(frame_attributes) = frame_attributes {
if frame_attributes.attrs.contains_key("xlink:href") {
write_container_attributes(cache_a, frame_attributes);
svg.write_event(&cache_a)?;
svg.write_event(cache_a)?;
has_href = true;
} else {
write_container_attributes(cache_g, frame_attributes);
svg.write_event(&cache_g)?;
svg.write_event(cache_g)?;
}
if let Some(ref t) = frame_attributes.title {
title = t.as_str();
}
} else if let Event::Start(ref mut c) = cache_g {
c.clear_attributes();
svg.write_event(&cache_g)?;
svg.write_event(cache_g)?;
}

Ok((has_href, title))
Expand Down Expand Up @@ -916,7 +916,7 @@ fn filled_rectangle<W: Write>(
} else {
unreachable!("cache wrapper was of wrong type: {:?}", cache_rect);
}
svg.write_event(&cache_rect)
svg.write_event(cache_rect)
}

fn write_usize(buffer: &mut StrStack, value: usize) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion tests/collapse-ghcprof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ fn collapse_ghcprof_cli() {
.arg("--bytes")
.output()
.expect("failed to execute process");
assert_eq!(output.status.success(), false);
assert!(!output.status.success());
}
Loading