Skip to content

Commit 811f9e5

Browse files
committed
Appease clippy
1 parent 56d9c21 commit 811f9e5

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
msrv = "1.56.1"
1+
msrv = "1.65.0"
22
disallowed-types = ["std::collections::HashMap"]

src/meta.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ where
6464
{
6565
type Item = AtomicRef<'a, T>;
6666

67+
#[allow(clippy::borrowed_box)] // variant of https://github.com/rust-lang/rust-clippy/issues/5770
6768
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
6869
loop {
6970
let resource_id = match self.tys.get(self.index) {

tests/meta_table_safety_113.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ impl PointsToU64 for Box<u64> {
1414

1515
struct MultipleData {
1616
_number: u64,
17-
pointer: Box<u64>,
17+
_pointer: Box<u64>,
1818
}
1919

2020
unsafe impl CastFrom<MultipleData> for dyn PointsToU64 {
21-
fn cast(t: *mut MultipleData) -> *mut Self {
22-
// note, this also assumes the pointer is non-null and probably other things which we can't
23-
// assume in an implementation of `CastFrom`.
24-
25-
// this is wrong and will cause a panic
26-
unsafe { core::ptr::addr_of_mut!((*t).pointer) }
21+
fn cast(_t: *mut MultipleData) -> *mut Self {
22+
// This is wrong and will cause a panic
23+
//
24+
// NOTE: we use this instead of constructing a pointer to the field since
25+
// there is no way to easily and safely do that currently! (this can be
26+
// changed if offset_of macro is added to std).
27+
core::ptr::NonNull::<Box<u64>>::dangling().as_ptr()
2728
}
2829
}
2930

@@ -33,7 +34,7 @@ fn test_panics() {
3334
let mut table: MetaTable<dyn PointsToU64> = MetaTable::new();
3435
let md = MultipleData {
3536
_number: 0x0, // this will be casted to a pointer, then dereferenced
36-
pointer: Box::new(42),
37+
_pointer: Box::new(42),
3738
};
3839
table.register::<MultipleData>();
3940
if let Some(t) = table.get(&md) {

0 commit comments

Comments
 (0)