Skip to content

Commit

Permalink
Replace match assertions against empty slices with is_empty assertions
Browse files Browse the repository at this point in the history
Asserting is_empty is slightly more concise.
  • Loading branch information
klinvill committed Nov 10, 2023
1 parent 98228e6 commit 30d6733
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tests/ui-fulldeps/stable-mir/projections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ use std::ops::ControlFlow;

const CRATE_NAME: &str = "input";

/// This function uses the Stable MIR APIs to get information about the test crate.
fn test_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
// Find items in the local crate.
/// Tests projections within Place objects
fn test_place_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
let items = stable_mir::all_local_items();

let body = get_item(&items, (DefKind::Fn, "projections")).unwrap().body();
assert_eq!(body.blocks.len(), 4);
// The first statement assigns `&s.c` to a local. The projections include a deref for `s`, since
Expand All @@ -47,7 +45,7 @@ fn test_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
// We can't match on vecs, only on slices. Comparing statements for equality wouldn't be
// any easier since we'd then have to add in the expected local and region values
// instead of matching on wildcards.
assert_matches!(local_proj[..], []);
assert!(local_proj.is_empty());
match &r_proj[..] {
// Similarly we can't match against a type, only against its kind.
[ProjectionElem::Deref, ProjectionElem::Field(2, ty)] => assert_matches!(
Expand Down Expand Up @@ -80,7 +78,7 @@ fn test_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
// We can't match on vecs, only on slices. Comparing for equality wouldn't be any easier
// since we'd then have to add in the expected local values instead of matching on
// wildcards.
assert_matches!(local_proj[..], []);
assert!(local_proj.is_empty());
assert_matches!(r_proj[..], [ProjectionElem::Deref, ProjectionElem::Index(_)]);
}
other => panic!(
Expand Down Expand Up @@ -108,8 +106,8 @@ fn test_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
projection: arg2_proj,
}),
] => {
assert_matches!(arg1_proj[..], []);
assert_matches!(arg2_proj[..], []);
assert!(arg1_proj.is_empty());
assert!(arg2_proj.is_empty());
}
other => {
panic!(
Expand Down

0 comments on commit 30d6733

Please sign in to comment.