Skip to content

Commit

Permalink
Merge pull request #25 from Zenithsiz/master
Browse files Browse the repository at this point in the history
Fixed single-argument `{mut_}array_refs` returning wrong type.
  • Loading branch information
droundy committed Mar 20, 2023
2 parents 827857d + feab803 commit d41c73a
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ macro_rules! array_refs {
let aref = & *(p as *const [T; $pre]);
p = p.add($pre);
aref
} ),* , {
}, )* {
let sl = slice::from_raw_parts(p as *const T, var_len);
p = p.add(var_len);
sl
}, $( {
let aref = & *(p as *const [T; $post]);
p = p.add($post);
aref
} ),*)
}, )*)
}
let input = $arr;
#[allow(unused_unsafe)]
Expand All @@ -146,7 +146,7 @@ macro_rules! array_refs {
let aref = &*(p as *const [T; $len]);
p = p.offset($len as isize);
aref
} ),* )
}, )* )
}
let input = $arr;
#[allow(unused_unsafe)]
Expand Down Expand Up @@ -215,15 +215,15 @@ macro_rules! mut_array_refs {
let aref = &mut *(p as *mut [T; $pre]);
p = p.add($pre);
aref
} ),* , {
}, )* {
let sl = slice::from_raw_parts_mut(p as *mut T, var_len);
p = p.add(var_len);
sl
}, $( {
let aref = &mut *(p as *mut [T; $post]);
p = p.add($post);
aref
} ),*)
}, )*)
}
let input = $arr;
#[allow(unused_unsafe)]
Expand All @@ -243,7 +243,7 @@ macro_rules! mut_array_refs {
let aref = &mut *(p as *mut [T; $len]);
p = p.add($len);
aref
} ),* )
}, )* )
}
let input = $arr;
#[allow(unused_unsafe)]
Expand Down Expand Up @@ -482,5 +482,21 @@ fn forbidden_clippy_lints_do_not_fire() {
let _ = mut_array_refs![&mut data, 8; .. ; 10];
}

#[test]
fn single_arg_refs() {
let mut data = [0u8; 8];
let (_, ) = array_refs![&data, 8];
let (_, ) = mut_array_refs![&mut data, 8];

let (_, _) = array_refs![&data, 4; ..;];
let (_, _) = mut_array_refs![&mut data, 4; ..;];

let (_, _) = array_refs![&data,; ..; 4];
let (_, _) = mut_array_refs![&mut data,; ..; 4];

let (_,) = array_refs![&data,; ..;];
let (_,) = mut_array_refs![&mut data,; ..;];
}

} // mod test

0 comments on commit d41c73a

Please sign in to comment.