Skip to content

add codegen test for equivalent slice implementations #116314

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

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 23 additions & 0 deletions tests/codegen/equivalent-slice-impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This test checks that two equivalent implementations produce the same number of `if` instructions.

#![crate_type = "lib"]

// CHECK-LABEL: @f1
// CHECK: if
pub fn f1(input: &mut &[u64]) -> Option<u64> {
match input {
[] => None,
[first, rest @ ..] => {
*input = rest;
Some(*first)
}
}
}

// CHECK-LABEL: @f2
// CHECK: if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not have expected this to be enough to check that there are equal numbers of if instructions... don't need something that checks there's not a subsequent if too?

pub fn f2(input: &mut &[u64]) -> Option<u64> {
let (first, rest) = input.split_first()?;
*input = rest;
Some(*first)
}