From fb546587a54c4463005e8b951c1a9c44e9ed63e7 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Sat, 10 Jul 2021 11:43:09 +0100 Subject: [PATCH 1/4] bump from raw::TraitObject to ptr_metadata to fix on nightly --- azure-pipelines.yml | 2 +- src/lib.rs | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c2fbdfe..2dbc42a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,7 +14,7 @@ jobs: endpoint: alecmocatta default: rust_toolchain: nightly - rust_lint_toolchain: nightly-2019-10-17 + rust_lint_toolchain: nightly-2021-07-09 rust_flags: '' rust_features: '' rust_target_check: '' diff --git a/src/lib.rs b/src/lib.rs index 1310277..2b03ec0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,8 +32,7 @@ #![doc(html_root_url = "https://docs.rs/metatype/0.2.0")] #![feature(arbitrary_self_types)] -#![feature(raw)] -#![feature(slice_from_raw_parts)] +#![feature(ptr_metadata)] #![feature(specialization)] #![warn( missing_copy_implementations, @@ -53,7 +52,7 @@ )] use std::{ - any::{type_name, TypeId}, hash::{Hash, Hasher}, marker::PhantomData, mem::{align_of, align_of_val, forget, size_of, size_of_val, transmute_copy}, ptr::{slice_from_raw_parts_mut, NonNull}, raw + any::{type_name, TypeId}, hash::{Hash, Hasher}, marker::PhantomData, mem::{align_of, align_of_val, forget, size_of, size_of_val, transmute_copy}, ptr::{slice_from_raw_parts_mut, NonNull} }; /// Implemented on all types, it provides helper methods to determine whether a type is `TraitObject`, `Slice` or `Concrete`, and work with them respectively. @@ -111,23 +110,17 @@ impl Type for T { default type Meta = TraitObject; #[inline] default fn meta(self: *const Self) -> Self::Meta { - let trait_object = unsafe { transmute_coerce::<*const Self, raw::TraitObject>(self) }; - assert_eq!(self as *const (), trait_object.data); let ret = TraitObject { - vtable: unsafe { &*trait_object.vtable }, + vtable: unsafe { transmute_coerce(std::ptr::metadata(self)) }, }; type_coerce(ret) } #[inline] default fn data(self: *const Self) -> *const () { - let trait_object = unsafe { transmute_coerce::<*const Self, raw::TraitObject>(self) }; - assert_eq!(self as *const (), trait_object.data); self as *const () } #[inline] default fn data_mut(self: *mut Self) -> *mut () { - let trait_object = unsafe { transmute_coerce::<*const Self, raw::TraitObject>(self) }; - assert_eq!(self as *mut (), trait_object.data); self as *mut () } #[inline] @@ -153,8 +146,7 @@ impl Type for T { let t: TraitObject = type_coerce(t); let vtable: *const () = t.vtable; let vtable = vtable as *mut (); - let ret = raw::TraitObject { data: thin, vtable }; - unsafe { transmute_coerce::(ret) } + std::ptr::from_raw_parts_mut(thin, unsafe { transmute_coerce(vtable) }) } } #[doc(hidden)] From b681264447034c21903b55ff902513f2a6be3d94 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Sat, 10 Jul 2021 11:45:26 +0100 Subject: [PATCH 2/4] bump CI OSs --- azure-pipelines.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2dbc42a..068f553 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -22,11 +22,11 @@ jobs: rust_target_run: '' matrix: windows: - imageName: 'vs2017-win2016' - rust_target_run: 'x86_64-pc-windows-msvc i686-pc-windows-msvc' # currently broken building crate-type=lib: x86_64-pc-windows-gnu i686-pc-windows-gnu + imageName: 'windows-latest' + rust_target_run: 'x86_64-pc-windows-msvc i686-pc-windows-msvc x86_64-pc-windows-gnu' mac: - imageName: 'macos-10.13' - rust_target_run: 'x86_64-apple-darwin i686-apple-darwin' + imageName: 'macos-latest' + rust_target_run: 'x86_64-apple-darwin' linux: - imageName: 'ubuntu-16.04' + imageName: 'ubuntu-latest' rust_target_run: 'x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl' From 33d11665d0d11f076a57e82ce28171ab47385ff2 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Sat, 10 Jul 2021 11:55:40 +0100 Subject: [PATCH 3/4] fix CI --- src/lib.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b03ec0..1ffee45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,9 @@ #![allow( clippy::must_use_candidate, clippy::not_unsafe_ptr_arg_deref, - clippy::use_self + clippy::use_self, + clippy::missing_panics_doc, + incomplete_features )] use std::{ @@ -117,11 +119,11 @@ impl Type for T { } #[inline] default fn data(self: *const Self) -> *const () { - self as *const () + self.cast() } #[inline] default fn data_mut(self: *mut Self) -> *mut () { - self as *mut () + self.cast() } #[inline] default fn dangling(t: Self::Meta) -> NonNull { @@ -159,11 +161,11 @@ impl Type for T { } #[inline] fn data(self: *const Self) -> *const () { - self as *const () + self.cast() } #[inline] fn data_mut(self: *mut Self) -> *mut () { - self as *mut () + self.cast() } fn dangling(_t: Self::Meta) -> NonNull { NonNull::dangling() @@ -187,11 +189,11 @@ impl Type for [T] { } #[inline] fn data(self: *const Self) -> *const () { - self as *const () + self.cast() } #[inline] fn data_mut(self: *mut Self) -> *mut () { - self as *mut () + self.cast() } fn dangling(t: Self::Meta) -> NonNull { let slice = slice_from_raw_parts_mut(NonNull::::dangling().as_ptr(), t.len); @@ -213,11 +215,11 @@ impl Type for str { } #[inline] fn data(self: *const Self) -> *const () { - self as *const () + self.cast() } #[inline] fn data_mut(self: *mut Self) -> *mut () { - self as *mut () + self.cast() } fn dangling(t: Self::Meta) -> NonNull { let bytes: *mut [u8] = <[u8]>::dangling(t).as_ptr(); @@ -303,11 +305,11 @@ mod tests { assert_eq!(Type::meta_type(&a), MetaType::Concrete); let meta: TraitObject = type_coerce(Type::meta(&*a)); let dangling = ::dangling(type_coerce(meta)); - let _fat = ::fatten(dangling.as_ptr() as *mut (), type_coerce(meta)); + let _fat = ::fatten(dangling.as_ptr().cast(), type_coerce(meta)); let mut x: usize = 0; let x_ptr: *mut usize = &mut x; let mut x_ptr: NonNull = NonNull::new(::fatten( - x_ptr as *mut (), + x_ptr.cast(), type_coerce(meta), )) .unwrap(); @@ -319,7 +321,7 @@ mod tests { let a: &[usize] = &[1, 2, 3]; assert_eq!(Type::meta_type(a), MetaType::Slice); let dangling = <[String] as Type>::dangling(Slice { len: 100 }); - let _fat = <[String] as Type>::fatten(dangling.as_ptr() as *mut (), Slice { len: 100 }); + let _fat = <[String] as Type>::fatten(dangling.as_ptr().cast(), Slice { len: 100 }); let a: Box<[usize]> = vec![1_usize, 2, 3].into_boxed_slice(); assert_eq!(Type::meta_type(&*a), MetaType::Slice); @@ -329,6 +331,6 @@ mod tests { assert_eq!(Type::meta_type(a), MetaType::Slice); assert_eq!(Type::meta_type(&a), MetaType::Concrete); let dangling = ::dangling(Slice { len: 100 }); - let _fat = ::fatten(dangling.as_ptr() as *mut (), Slice { len: 100 }); + let _fat = ::fatten(dangling.as_ptr().cast(), Slice { len: 100 }); } } From 389514b1209cd74c48f4095ae95a91c6db00ceb1 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Sat, 10 Jul 2021 12:21:40 +0100 Subject: [PATCH 4/4] v0.2.1 --- Cargo.toml | 4 ++-- README.md | 5 +++-- src/lib.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f1e7a6..82559bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "metatype" -version = "0.2.0" +version = "0.2.1" license = "MIT OR Apache-2.0" authors = ["Alec Mocatta "] categories = ["development-tools","rust-patterns"] @@ -10,7 +10,7 @@ Helper methods to determine whether a type is `TraitObject`, `Slice` or `Concret """ repository = "https://github.com/alecmocatta/metatype" homepage = "https://github.com/alecmocatta/metatype" -documentation = "https://docs.rs/metatype/0.2.0" +documentation = "https://docs.rs/metatype/0.2.1" readme = "README.md" edition = "2018" diff --git a/README.md b/README.md index 64bde3c..eb28dcc 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ [![Crates.io](https://img.shields.io/crates/v/metatype.svg?maxAge=86400)](https://crates.io/crates/metatype) [![MIT / Apache 2.0 licensed](https://img.shields.io/crates/l/metatype.svg?maxAge=2592000)](#License) -[![Build Status](https://dev.azure.com/alecmocatta/metatype/_apis/build/status/tests?branchName=master)](https://dev.azure.com/alecmocatta/metatype/_build/latest?branchName=master) +[![Build Status](https://dev.azure.com/alecmocatta/metatype/_apis/build/status/tests?branchName=master)](https://dev.azure.com/alecmocatta/metatype/_build?definitionId=7) -[Docs](https://docs.rs/metatype/0.2.0) +[📖 Docs](https://docs.rs/metatype/0.2) | [💬 Chat](https://constellation.zulipchat.com/#narrow/stream/213236-subprojects) Helper methods to determine whether a type is `TraitObject`, `Slice` or `Concrete`, and work with them respectively. @@ -35,6 +35,7 @@ println!("vtable: {:?}", meta.vtable); This currently requires Rust nightly for the `raw`, `specialization` and `arbitrary_self_types` features. ## License + Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE.txt](LICENSE-APACHE.txt) or http://www.apache.org/licenses/LICENSE-2.0) diff --git a/src/lib.rs b/src/lib.rs index 1ffee45..1083f17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ //! This currently requires Rust nightly for the `raw`, `specialization` and //! `arbitrary_self_types` features. -#![doc(html_root_url = "https://docs.rs/metatype/0.2.0")] +#![doc(html_root_url = "https://docs.rs/metatype/0.2.1")] #![feature(arbitrary_self_types)] #![feature(ptr_metadata)] #![feature(specialization)]