Skip to content

Commit

Permalink
Appease clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Imberflur committed Feb 25, 2023
1 parent 8eea70d commit ab967bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
msrv = "1.56.1"
msrv = "1.65.0"
disallowed-types = ["std::collections::HashMap"]
1 change: 1 addition & 0 deletions src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ where
{
type Item = Ref<'a, T>;

#[allow(clippy::borrowed_box)] // variant of https://github.com/rust-lang/rust-clippy/issues/5770
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
loop {
let resource_id = match self.tys.get(self.index) {
Expand Down
17 changes: 9 additions & 8 deletions tests/meta_table_safety_113.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ impl PointsToU64 for Box<u64> {

struct MultipleData {
_number: u64,
pointer: Box<u64>,
_pointer: Box<u64>,
}

unsafe impl CastFrom<MultipleData> for dyn PointsToU64 {
fn cast(t: *mut MultipleData) -> *mut Self {
// note, this also assumes the pointer is non-null and probably other things which we can't
// assume in an implementation of `CastFrom`.

// this is wrong and will cause a panic
unsafe { core::ptr::addr_of_mut!((*t).pointer) }
fn cast(_t: *mut MultipleData) -> *mut Self {
// This is wrong and will cause a panic
//
// NOTE: we use this instead of constructing a pointer to the field since
// there is no way to easily and safely do that currently! (this can be
// changed if offset_of macro is added to std).
core::ptr::NonNull::<Box<u64>>::dangling().as_ptr()
}
}

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

0 comments on commit ab967bc

Please sign in to comment.