Deny bare trait objects in in src/liballoc
This commit is contained in:
parent
77117e3836
commit
296e72f11c
4 changed files with 13 additions and 12 deletions
|
@ -446,7 +446,7 @@ impl From<Box<str>> for Box<[u8]> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Box<Any> {
|
impl Box<dyn Any> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
/// Attempt to downcast the box to a concrete type.
|
/// Attempt to downcast the box to a concrete type.
|
||||||
|
@ -468,10 +468,10 @@ impl Box<Any> {
|
||||||
/// print_if_string(Box::new(0i8));
|
/// print_if_string(Box::new(0i8));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
|
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any>> {
|
||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let raw: *mut Any = Box::into_raw(self);
|
let raw: *mut dyn Any = Box::into_raw(self);
|
||||||
Ok(Box::from_raw(raw as *mut T))
|
Ok(Box::from_raw(raw as *mut T))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -480,7 +480,7 @@ impl Box<Any> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Box<Any + Send> {
|
impl Box<dyn Any + Send> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
/// Attempt to downcast the box to a concrete type.
|
/// Attempt to downcast the box to a concrete type.
|
||||||
|
@ -502,10 +502,10 @@ impl Box<Any + Send> {
|
||||||
/// print_if_string(Box::new(0i8));
|
/// print_if_string(Box::new(0i8));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>> {
|
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any + Send>> {
|
||||||
<Box<Any>>::downcast(self).map_err(|s| unsafe {
|
<Box<dyn Any>>::downcast(self).map_err(|s| unsafe {
|
||||||
// reapply the Send marker
|
// reapply the Send marker
|
||||||
Box::from_raw(Box::into_raw(s) as *mut (Any + Send))
|
Box::from_raw(Box::into_raw(s) as *mut (dyn Any + Send))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -643,7 +643,7 @@ impl<A, F> FnBox<A> for F
|
||||||
|
|
||||||
#[unstable(feature = "fnbox",
|
#[unstable(feature = "fnbox",
|
||||||
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
|
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
|
||||||
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
|
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + 'a> {
|
||||||
type Output = R;
|
type Output = R;
|
||||||
|
|
||||||
extern "rust-call" fn call_once(self, args: A) -> R {
|
extern "rust-call" fn call_once(self, args: A) -> R {
|
||||||
|
@ -653,7 +653,7 @@ impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
|
||||||
|
|
||||||
#[unstable(feature = "fnbox",
|
#[unstable(feature = "fnbox",
|
||||||
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
|
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
|
||||||
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + Send + 'a> {
|
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + 'a> {
|
||||||
type Output = R;
|
type Output = R;
|
||||||
|
|
||||||
extern "rust-call" fn call_once(self, args: A) -> R {
|
extern "rust-call" fn call_once(self, args: A) -> R {
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
|
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![needs_allocator]
|
#![needs_allocator]
|
||||||
|
#![deny(bare_trait_objects)]
|
||||||
#![deny(missing_debug_implementations)]
|
#![deny(missing_debug_implementations)]
|
||||||
|
|
||||||
#![cfg_attr(test, allow(deprecated))] // rand
|
#![cfg_attr(test, allow(deprecated))] // rand
|
||||||
|
|
|
@ -618,7 +618,7 @@ impl<T: Clone> Rc<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rc<Any> {
|
impl Rc<dyn Any> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rc_downcast", since = "1.29.0")]
|
#[stable(feature = "rc_downcast", since = "1.29.0")]
|
||||||
/// Attempt to downcast the `Rc<Any>` to a concrete type.
|
/// Attempt to downcast the `Rc<Any>` to a concrete type.
|
||||||
|
@ -641,7 +641,7 @@ impl Rc<Any> {
|
||||||
/// print_if_string(Rc::new(0i8));
|
/// print_if_string(Rc::new(0i8));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<Any>> {
|
pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<dyn Any>> {
|
||||||
if (*self).is::<T>() {
|
if (*self).is::<T>() {
|
||||||
let ptr = self.ptr.cast::<RcBox<T>>();
|
let ptr = self.ptr.cast::<RcBox<T>>();
|
||||||
forget(self);
|
forget(self);
|
||||||
|
|
|
@ -978,7 +978,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arc<Any + Send + Sync> {
|
impl Arc<dyn Any + Send + Sync> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rc_downcast", since = "1.29.0")]
|
#[stable(feature = "rc_downcast", since = "1.29.0")]
|
||||||
/// Attempt to downcast the `Arc<Any + Send + Sync>` to a concrete type.
|
/// Attempt to downcast the `Arc<Any + Send + Sync>` to a concrete type.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue