Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Add test showing how downcasting to CFArray is unsound #158

Merged
merged 1 commit into from May 7, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add test showing how downcasting to CFArray with generic is prohibited

  • Loading branch information
faern committed Mar 20, 2018
commit 6c63acc55a51f1df5e9154df616f326c872fc076
@@ -64,6 +64,21 @@ impl CFType {
/// assert!(cf_type.downcast::<CFBoolean>().is_none());
/// ```
///
/// ```compile_fail
/// # use core_foundation::array::CFArray;
/// # use core_foundation::base::TCFType;
/// # use core_foundation::boolean::CFBoolean;
/// # use core_foundation::string::CFString;
/// #
/// let boolean_array = CFArray::from_CFTypes(&[CFBoolean::true_value()]).into_CFType();
///
/// // This downcast is not allowed and causes compiler error, since it would cause undefined
/// // behavior to access the elements of the array as a CFString:
/// let invalid_string_array = boolean_array
/// .downcast_into::<CFArray<CFString>>()
/// .unwrap();
/// ```
///
/// [`Box::downcast`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.downcast
/// [`CFPropertyList::downcast`]: ../propertylist/struct.CFPropertyList.html#method.downcast
#[inline]
@@ -82,7 +97,7 @@ impl CFType {
///
/// [`downcast`]: #method.downcast
#[inline]
pub fn downcast_into<T: TCFType>(self) -> Option<T> {
pub fn downcast_into<T: ConcreteCFType>(self) -> Option<T> {
if self.instance_of::<T>() {
unsafe {
let reference = T::Ref::from_void_ptr(self.0);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.