Rollup merge of #63667 - petrochenkov:deriveholders, r=matthewjasper
resolve: Properly integrate derives and `macro_rules` scopes
So,
```rust
#[derive(A, B)]
struct S;
m!();
```
turns into something like
```rust
struct S;
A_placeholder!( struct S; );
B_placeholder!( struct S; );
m!();
```
during expansion.
And for `m!()` its "`macro_rules` scope" (aka "legacy scope") should point to the `B_placeholder` call rather than to the derive container `#[derive(A, B)]`.
`fn build_reduced_graph` now makes sure the legacy scope points to the right thing.
(It's still a mystery for me why this worked before https://github.com/rust-lang/rust/pull/63535.)
Unfortunately, placeholders from derives are currently treated separately from placeholders from other macros and need to be passed as `extra_placeholders` rather than a part of the AST fragment.
That's fixable, but I wanted to keep this PR more minimal to close the regression faster.
Fixes https://github.com/rust-lang/rust/issues/63651
r? @matthewjasper
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index c92db51..c61e318 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -91,8 +91,10 @@
CoerceUnsized, DispatchFromDyn, Deref, DerefMut, Receiver, Generator, GeneratorState
};
use core::ptr::{self, NonNull, Unique};
+use core::slice;
use core::task::{Context, Poll};
+use crate::alloc::{self, Global, Alloc};
use crate::vec::Vec;
use crate::raw_vec::RawVec;
use crate::str::from_boxed_utf8_unchecked;
@@ -121,6 +123,34 @@
box x
}
+ /// Constructs a new box with uninitialized contents.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ ///
+ /// let mut five = Box::<u32>::new_uninit();
+ ///
+ /// let five = unsafe {
+ /// // Deferred initialization:
+ /// five.as_mut_ptr().write(5);
+ ///
+ /// five.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*five, 5)
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
+ let layout = alloc::Layout::new::<mem::MaybeUninit<T>>();
+ let ptr = unsafe {
+ Global.alloc(layout)
+ .unwrap_or_else(|_| alloc::handle_alloc_error(layout))
+ };
+ Box(ptr.cast().into())
+ }
+
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
/// `x` will be pinned in memory and unable to be moved.
#[stable(feature = "pin", since = "1.33.0")]
@@ -130,6 +160,111 @@
}
}
+impl<T> Box<[T]> {
+ /// Constructs a new boxed slice with uninitialized contents.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ ///
+ /// let mut values = Box::<[u32]>::new_uninit_slice(3);
+ ///
+ /// let values = unsafe {
+ /// // Deferred initialization:
+ /// values[0].as_mut_ptr().write(1);
+ /// values[1].as_mut_ptr().write(2);
+ /// values[2].as_mut_ptr().write(3);
+ ///
+ /// values.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*values, [1, 2, 3])
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
+ let layout = alloc::Layout::array::<mem::MaybeUninit<T>>(len).unwrap();
+ let ptr = unsafe { alloc::alloc(layout) };
+ let unique = Unique::new(ptr).unwrap_or_else(|| alloc::handle_alloc_error(layout));
+ let slice = unsafe { slice::from_raw_parts_mut(unique.cast().as_ptr(), len) };
+ Box(Unique::from(slice))
+ }
+}
+
+impl<T> Box<mem::MaybeUninit<T>> {
+ /// Converts to `Box<T>`.
+ ///
+ /// # Safety
+ ///
+ /// As with [`MaybeUninit::assume_init`],
+ /// it is up to the caller to guarantee that the value
+ /// really is in an initialized state.
+ /// Calling this when the content is not yet fully initialized
+ /// causes immediate undefined behavior.
+ ///
+ /// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ ///
+ /// let mut five = Box::<u32>::new_uninit();
+ ///
+ /// let five: Box<u32> = unsafe {
+ /// // Deferred initialization:
+ /// five.as_mut_ptr().write(5);
+ ///
+ /// five.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*five, 5)
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ #[inline]
+ pub unsafe fn assume_init(self) -> Box<T> {
+ Box(Box::into_unique(self).cast())
+ }
+}
+
+impl<T> Box<[mem::MaybeUninit<T>]> {
+ /// Converts to `Box<[T]>`.
+ ///
+ /// # Safety
+ ///
+ /// As with [`MaybeUninit::assume_init`],
+ /// it is up to the caller to guarantee that the values
+ /// really are in an initialized state.
+ /// Calling this when the content is not yet fully initialized
+ /// causes immediate undefined behavior.
+ ///
+ /// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ ///
+ /// let mut values = Box::<[u32]>::new_uninit_slice(3);
+ ///
+ /// let values = unsafe {
+ /// // Deferred initialization:
+ /// values[0].as_mut_ptr().write(1);
+ /// values[1].as_mut_ptr().write(2);
+ /// values[2].as_mut_ptr().write(3);
+ ///
+ /// values.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*values, [1, 2, 3])
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ #[inline]
+ pub unsafe fn assume_init(self) -> Box<[T]> {
+ Box(Unique::new_unchecked(Box::into_raw(self) as _))
+ }
+}
+
impl<T: ?Sized> Box<T> {
/// Constructs a box from a raw pointer.
///
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 0c406a9..2b222ca 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -327,6 +327,37 @@
}))
}
+ /// Constructs a new `Rc` with uninitialized contents.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::rc::Rc;
+ ///
+ /// let mut five = Rc::<u32>::new_uninit();
+ ///
+ /// let five = unsafe {
+ /// // Deferred initialization:
+ /// Rc::get_mut_unchecked(&mut five).as_mut_ptr().write(5);
+ ///
+ /// five.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*five, 5)
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ pub fn new_uninit() -> Rc<mem::MaybeUninit<T>> {
+ unsafe {
+ Rc::from_ptr(Rc::allocate_for_layout(
+ Layout::new::<T>(),
+ |mem| mem as *mut RcBox<mem::MaybeUninit<T>>,
+ ))
+ }
+ }
+
/// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
/// `value` will be pinned in memory and unable to be moved.
#[stable(feature = "pin", since = "1.33.0")]
@@ -377,6 +408,118 @@
}
}
+impl<T> Rc<[T]> {
+ /// Constructs a new reference-counted slice with uninitialized contents.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::rc::Rc;
+ ///
+ /// let mut values = Rc::<[u32]>::new_uninit_slice(3);
+ ///
+ /// let values = unsafe {
+ /// // Deferred initialization:
+ /// Rc::get_mut_unchecked(&mut values)[0].as_mut_ptr().write(1);
+ /// Rc::get_mut_unchecked(&mut values)[1].as_mut_ptr().write(2);
+ /// Rc::get_mut_unchecked(&mut values)[2].as_mut_ptr().write(3);
+ ///
+ /// values.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*values, [1, 2, 3])
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ pub fn new_uninit_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
+ unsafe {
+ Rc::from_ptr(Rc::allocate_for_slice(len))
+ }
+ }
+}
+
+impl<T> Rc<mem::MaybeUninit<T>> {
+ /// Converts to `Rc<T>`.
+ ///
+ /// # Safety
+ ///
+ /// As with [`MaybeUninit::assume_init`],
+ /// it is up to the caller to guarantee that the value
+ /// really is in an initialized state.
+ /// Calling this when the content is not yet fully initialized
+ /// causes immediate undefined behavior.
+ ///
+ /// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::rc::Rc;
+ ///
+ /// let mut five = Rc::<u32>::new_uninit();
+ ///
+ /// let five = unsafe {
+ /// // Deferred initialization:
+ /// Rc::get_mut_unchecked(&mut five).as_mut_ptr().write(5);
+ ///
+ /// five.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*five, 5)
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ #[inline]
+ pub unsafe fn assume_init(self) -> Rc<T> {
+ Rc::from_inner(mem::ManuallyDrop::new(self).ptr.cast())
+ }
+}
+
+impl<T> Rc<[mem::MaybeUninit<T>]> {
+ /// Converts to `Rc<[T]>`.
+ ///
+ /// # Safety
+ ///
+ /// As with [`MaybeUninit::assume_init`],
+ /// it is up to the caller to guarantee that the value
+ /// really is in an initialized state.
+ /// Calling this when the content is not yet fully initialized
+ /// causes immediate undefined behavior.
+ ///
+ /// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::rc::Rc;
+ ///
+ /// let mut values = Rc::<[u32]>::new_uninit_slice(3);
+ ///
+ /// let values = unsafe {
+ /// // Deferred initialization:
+ /// Rc::get_mut_unchecked(&mut values)[0].as_mut_ptr().write(1);
+ /// Rc::get_mut_unchecked(&mut values)[1].as_mut_ptr().write(2);
+ /// Rc::get_mut_unchecked(&mut values)[2].as_mut_ptr().write(3);
+ ///
+ /// values.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*values, [1, 2, 3])
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ #[inline]
+ pub unsafe fn assume_init(self) -> Rc<[T]> {
+ Rc::from_ptr(mem::ManuallyDrop::new(self).ptr.as_ptr() as _)
+ }
+}
+
impl<T: ?Sized> Rc<T> {
/// Consumes the `Rc`, returning the wrapped pointer.
///
@@ -560,13 +703,46 @@
pub fn get_mut(this: &mut Self) -> Option<&mut T> {
if Rc::is_unique(this) {
unsafe {
- Some(&mut this.ptr.as_mut().value)
+ Some(Rc::get_mut_unchecked(this))
}
} else {
None
}
}
+ /// Returns a mutable reference to the inner value,
+ /// without any check.
+ ///
+ /// See also [`get_mut`], which is safe and does appropriate checks.
+ ///
+ /// [`get_mut`]: struct.Rc.html#method.get_mut
+ ///
+ /// # Safety
+ ///
+ /// Any other `Rc` or [`Weak`] pointers to the same value must not be dereferenced
+ /// for the duration of the returned borrow.
+ /// This is trivially the case if no such pointers exist,
+ /// for example immediately after `Rc::new`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::rc::Rc;
+ ///
+ /// let mut x = Rc::new(String::new());
+ /// unsafe {
+ /// Rc::get_mut_unchecked(&mut x).push_str("foo")
+ /// }
+ /// assert_eq!(*x, "foo");
+ /// ```
+ #[inline]
+ #[unstable(feature = "get_mut_unchecked", issue = "63292")]
+ pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {
+ &mut this.ptr.as_mut().value
+ }
+
#[inline]
#[stable(feature = "ptr_eq", since = "1.17.0")]
/// Returns `true` if the two `Rc`s point to the same value (not
@@ -704,11 +880,11 @@
impl<T: ?Sized> Rc<T> {
/// Allocates an `RcBox<T>` with sufficient space for
- /// an unsized value where the value has the layout provided.
+ /// a possibly-unsized value where the value has the layout provided.
///
/// The function `mem_to_rcbox` is called with the data pointer
/// and must return back a (potentially fat)-pointer for the `RcBox<T>`.
- unsafe fn allocate_for_unsized(
+ unsafe fn allocate_for_layout(
value_layout: Layout,
mem_to_rcbox: impl FnOnce(*mut u8) -> *mut RcBox<T>
) -> *mut RcBox<T> {
@@ -737,7 +913,7 @@
/// Allocates an `RcBox<T>` with sufficient space for an unsized value
unsafe fn allocate_for_ptr(ptr: *const T) -> *mut RcBox<T> {
// Allocate for the `RcBox<T>` using the given value.
- Self::allocate_for_unsized(
+ Self::allocate_for_layout(
Layout::for_value(&*ptr),
|mem| set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>,
)
@@ -768,7 +944,7 @@
impl<T> Rc<[T]> {
/// Allocates an `RcBox<[T]>` with the given length.
unsafe fn allocate_for_slice(len: usize) -> *mut RcBox<[T]> {
- Self::allocate_for_unsized(
+ Self::allocate_for_layout(
Layout::array::<T>(len).unwrap(),
|mem| ptr::slice_from_raw_parts_mut(mem as *mut T, len) as *mut RcBox<[T]>,
)
diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs
index 7d3b265..3411721 100644
--- a/src/liballoc/sync.rs
+++ b/src/liballoc/sync.rs
@@ -311,6 +311,37 @@
Self::from_inner(Box::into_raw_non_null(x))
}
+ /// Constructs a new `Arc` with uninitialized contents.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::sync::Arc;
+ ///
+ /// let mut five = Arc::<u32>::new_uninit();
+ ///
+ /// let five = unsafe {
+ /// // Deferred initialization:
+ /// Arc::get_mut_unchecked(&mut five).as_mut_ptr().write(5);
+ ///
+ /// five.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*five, 5)
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ pub fn new_uninit() -> Arc<mem::MaybeUninit<T>> {
+ unsafe {
+ Arc::from_ptr(Arc::allocate_for_layout(
+ Layout::new::<T>(),
+ |mem| mem as *mut ArcInner<mem::MaybeUninit<T>>,
+ ))
+ }
+ }
+
/// Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then
/// `data` will be pinned in memory and unable to be moved.
#[stable(feature = "pin", since = "1.33.0")]
@@ -361,6 +392,118 @@
}
}
+impl<T> Arc<[T]> {
+ /// Constructs a new reference-counted slice with uninitialized contents.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::sync::Arc;
+ ///
+ /// let mut values = Arc::<[u32]>::new_uninit_slice(3);
+ ///
+ /// let values = unsafe {
+ /// // Deferred initialization:
+ /// Arc::get_mut_unchecked(&mut values)[0].as_mut_ptr().write(1);
+ /// Arc::get_mut_unchecked(&mut values)[1].as_mut_ptr().write(2);
+ /// Arc::get_mut_unchecked(&mut values)[2].as_mut_ptr().write(3);
+ ///
+ /// values.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*values, [1, 2, 3])
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ pub fn new_uninit_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
+ unsafe {
+ Arc::from_ptr(Arc::allocate_for_slice(len))
+ }
+ }
+}
+
+impl<T> Arc<mem::MaybeUninit<T>> {
+ /// Converts to `Arc<T>`.
+ ///
+ /// # Safety
+ ///
+ /// As with [`MaybeUninit::assume_init`],
+ /// it is up to the caller to guarantee that the value
+ /// really is in an initialized state.
+ /// Calling this when the content is not yet fully initialized
+ /// causes immediate undefined behavior.
+ ///
+ /// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::sync::Arc;
+ ///
+ /// let mut five = Arc::<u32>::new_uninit();
+ ///
+ /// let five = unsafe {
+ /// // Deferred initialization:
+ /// Arc::get_mut_unchecked(&mut five).as_mut_ptr().write(5);
+ ///
+ /// five.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*five, 5)
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ #[inline]
+ pub unsafe fn assume_init(self) -> Arc<T> {
+ Arc::from_inner(mem::ManuallyDrop::new(self).ptr.cast())
+ }
+}
+
+impl<T> Arc<[mem::MaybeUninit<T>]> {
+ /// Converts to `Arc<[T]>`.
+ ///
+ /// # Safety
+ ///
+ /// As with [`MaybeUninit::assume_init`],
+ /// it is up to the caller to guarantee that the value
+ /// really is in an initialized state.
+ /// Calling this when the content is not yet fully initialized
+ /// causes immediate undefined behavior.
+ ///
+ /// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(new_uninit)]
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::sync::Arc;
+ ///
+ /// let mut values = Arc::<[u32]>::new_uninit_slice(3);
+ ///
+ /// let values = unsafe {
+ /// // Deferred initialization:
+ /// Arc::get_mut_unchecked(&mut values)[0].as_mut_ptr().write(1);
+ /// Arc::get_mut_unchecked(&mut values)[1].as_mut_ptr().write(2);
+ /// Arc::get_mut_unchecked(&mut values)[2].as_mut_ptr().write(3);
+ ///
+ /// values.assume_init()
+ /// };
+ ///
+ /// assert_eq!(*values, [1, 2, 3])
+ /// ```
+ #[unstable(feature = "new_uninit", issue = "63291")]
+ #[inline]
+ pub unsafe fn assume_init(self) -> Arc<[T]> {
+ Arc::from_ptr(mem::ManuallyDrop::new(self).ptr.as_ptr() as _)
+ }
+}
+
impl<T: ?Sized> Arc<T> {
/// Consumes the `Arc`, returning the wrapped pointer.
///
@@ -593,11 +736,11 @@
impl<T: ?Sized> Arc<T> {
/// Allocates an `ArcInner<T>` with sufficient space for
- /// an unsized value where the value has the layout provided.
+ /// a possibly-unsized value where the value has the layout provided.
///
/// The function `mem_to_arcinner` is called with the data pointer
/// and must return back a (potentially fat)-pointer for the `ArcInner<T>`.
- unsafe fn allocate_for_unsized(
+ unsafe fn allocate_for_layout(
value_layout: Layout,
mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T>
) -> *mut ArcInner<T> {
@@ -625,7 +768,7 @@
/// Allocates an `ArcInner<T>` with sufficient space for an unsized value.
unsafe fn allocate_for_ptr(ptr: *const T) -> *mut ArcInner<T> {
// Allocate for the `ArcInner<T>` using the given value.
- Self::allocate_for_unsized(
+ Self::allocate_for_layout(
Layout::for_value(&*ptr),
|mem| set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>,
)
@@ -656,7 +799,7 @@
impl<T> Arc<[T]> {
/// Allocates an `ArcInner<[T]>` with the given length.
unsafe fn allocate_for_slice(len: usize) -> *mut ArcInner<[T]> {
- Self::allocate_for_unsized(
+ Self::allocate_for_layout(
Layout::array::<T>(len).unwrap(),
|mem| ptr::slice_from_raw_parts_mut(mem as *mut T, len) as *mut ArcInner<[T]>,
)
@@ -945,13 +1088,46 @@
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
unsafe {
- Some(&mut this.ptr.as_mut().data)
+ Some(Arc::get_mut_unchecked(this))
}
} else {
None
}
}
+ /// Returns a mutable reference to the inner value,
+ /// without any check.
+ ///
+ /// See also [`get_mut`], which is safe and does appropriate checks.
+ ///
+ /// [`get_mut`]: struct.Arc.html#method.get_mut
+ ///
+ /// # Safety
+ ///
+ /// Any other `Arc` or [`Weak`] pointers to the same value must not be dereferenced
+ /// for the duration of the returned borrow.
+ /// This is trivially the case if no such pointers exist,
+ /// for example immediately after `Arc::new`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(get_mut_unchecked)]
+ ///
+ /// use std::sync::Arc;
+ ///
+ /// let mut x = Arc::new(String::new());
+ /// unsafe {
+ /// Arc::get_mut_unchecked(&mut x).push_str("foo")
+ /// }
+ /// assert_eq!(*x, "foo");
+ /// ```
+ #[inline]
+ #[unstable(feature = "get_mut_unchecked", issue = "63292")]
+ pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {
+ &mut this.ptr.as_mut().data
+ }
+
/// Determine whether this is the unique reference (including weak refs) to
/// the underlying data.
///
diff --git a/src/libcore/ptr/unique.rs b/src/libcore/ptr/unique.rs
index f0d011f..3521dd7 100644
--- a/src/libcore/ptr/unique.rs
+++ b/src/libcore/ptr/unique.rs
@@ -122,6 +122,14 @@
pub unsafe fn as_mut(&mut self) -> &mut T {
&mut *self.as_ptr()
}
+
+ /// Casts to a pointer of another type.
+ #[inline]
+ pub const fn cast<U>(self) -> Unique<U> {
+ unsafe {
+ Unique::new_unchecked(self.as_ptr() as *mut U)
+ }
+ }
}
#[unstable(feature = "ptr_internals", issue = "0")]
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index 8216008..ce7681c 100644
--- a/src/librustc_lint/builtin.rs
+++ b/src/librustc_lint/builtin.rs
@@ -1876,16 +1876,70 @@
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &hir::Expr) {
- const ZEROED_PATH: &[Symbol] = &[sym::core, sym::mem, sym::zeroed];
- const UININIT_PATH: &[Symbol] = &[sym::core, sym::mem, sym::uninitialized];
+ #[derive(Debug, Copy, Clone, PartialEq)]
+ enum InitKind { Zeroed, Uninit };
/// Information about why a type cannot be initialized this way.
/// Contains an error message and optionally a span to point at.
type InitError = (String, Option<Span>);
+ /// Test if this constant is all-0.
+ fn is_zero(expr: &hir::Expr) -> bool {
+ use hir::ExprKind::*;
+ use syntax::ast::LitKind::*;
+ match &expr.node {
+ Lit(lit) =>
+ if let Int(i, _) = lit.node {
+ i == 0
+ } else {
+ false
+ },
+ Tup(tup) =>
+ tup.iter().all(is_zero),
+ _ =>
+ false
+ }
+ }
+
+ /// Determine if this expression is a "dangerous initialization".
+ fn is_dangerous_init(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option<InitKind> {
+ const ZEROED_PATH: &[Symbol] = &[sym::core, sym::mem, sym::zeroed];
+ const UININIT_PATH: &[Symbol] = &[sym::core, sym::mem, sym::uninitialized];
+ // `transmute` is inside an anonymous module (the `extern` block?);
+ // `Invalid` represents the empty string and matches that.
+ const TRANSMUTE_PATH: &[Symbol] =
+ &[sym::core, sym::intrinsics, kw::Invalid, sym::transmute];
+
+ if let hir::ExprKind::Call(ref path_expr, ref args) = expr.node {
+ if let hir::ExprKind::Path(ref qpath) = path_expr.node {
+ let def_id = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
+
+ if cx.match_def_path(def_id, ZEROED_PATH) {
+ return Some(InitKind::Zeroed);
+ }
+ if cx.match_def_path(def_id, UININIT_PATH) {
+ return Some(InitKind::Uninit);
+ }
+ if cx.match_def_path(def_id, TRANSMUTE_PATH) {
+ if is_zero(&args[0]) {
+ return Some(InitKind::Zeroed);
+ }
+ }
+ // FIXME: Also detect `MaybeUninit::zeroed().assume_init()` and
+ // `MaybeUninit::uninit().assume_init()`.
+ }
+ }
+
+ None
+ }
+
/// Return `Some` only if we are sure this type does *not*
/// allow zero initialization.
- fn ty_find_init_error<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<InitError> {
+ fn ty_find_init_error<'tcx>(
+ tcx: TyCtxt<'tcx>,
+ ty: Ty<'tcx>,
+ init: InitKind,
+ ) -> Option<InitError> {
use rustc::ty::TyKind::*;
match ty.sty {
// Primitive types that don't like 0 as a value.
@@ -1893,8 +1947,30 @@
Adt(..) if ty.is_box() => Some((format!("`Box` must be non-null"), None)),
FnPtr(..) => Some((format!("Function pointers must be non-null"), None)),
Never => Some((format!("The never type (`!`) has no valid value"), None)),
- // Recurse for some compound types.
+ // Primitive types with other constraints.
+ Bool if init == InitKind::Uninit =>
+ Some((format!("Booleans must be `true` or `false`"), None)),
+ Char if init == InitKind::Uninit =>
+ Some((format!("Characters must be a valid unicode codepoint"), None)),
+ // Recurse and checks for some compound types.
Adt(adt_def, substs) if !adt_def.is_union() => {
+ // First check f this ADT has a layout attribute (like `NonNull` and friends).
+ use std::ops::Bound;
+ match tcx.layout_scalar_valid_range(adt_def.did) {
+ // We exploit here that `layout_scalar_valid_range` will never
+ // return `Bound::Excluded`. (And we have tests checking that we
+ // handle the attribute correctly.)
+ (Bound::Included(lo), _) if lo > 0 =>
+ return Some((format!("{} must be non-null", ty), None)),
+ (Bound::Included(_), _) | (_, Bound::Included(_))
+ if init == InitKind::Uninit =>
+ return Some((
+ format!("{} must be initialized inside its custom valid range", ty),
+ None,
+ )),
+ _ => {}
+ }
+ // Now, recurse.
match adt_def.variants.len() {
0 => Some((format!("0-variant enums have no valid value"), None)),
1 => {
@@ -1905,6 +1981,7 @@
ty_find_init_error(
tcx,
field.ty(tcx, substs),
+ init,
).map(|(mut msg, span)| if span.is_none() {
// Point to this field, should be helpful for figuring
// out where the source of the error is.
@@ -1918,57 +1995,48 @@
})
})
}
+ // Multi-variant enums are tricky: if all but one variant are
+ // uninhabited, we might actually do layout like for a single-variant
+ // enum, and then even leaving them uninitialized could be okay.
_ => None, // Conservative fallback for multi-variant enum.
}
}
Tuple(..) => {
// Proceed recursively, check all fields.
- ty.tuple_fields().find_map(|field| ty_find_init_error(tcx, field))
+ ty.tuple_fields().find_map(|field| ty_find_init_error(tcx, field, init))
}
- // FIXME: Would be nice to also warn for `NonNull`/`NonZero*`.
- // FIXME: *Only for `mem::uninitialized`*, we could also warn for `bool`,
- // `char`, and any multivariant enum.
// Conservative fallback.
_ => None,
}
}
- if let hir::ExprKind::Call(ref path_expr, ref _args) = expr.node {
- if let hir::ExprKind::Path(ref qpath) = path_expr.node {
- if let Some(def_id) = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
- if cx.match_def_path(def_id, &ZEROED_PATH) ||
- cx.match_def_path(def_id, &UININIT_PATH)
- {
- // This conjures an instance of a type out of nothing,
- // using zeroed or uninitialized memory.
- // We are extremely conservative with what we warn about.
- let conjured_ty = cx.tables.expr_ty(expr);
- if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty) {
- let mut err = cx.struct_span_lint(
- INVALID_VALUE,
- expr.span,
- &format!(
- "the type `{}` does not permit {}",
- conjured_ty,
- if cx.match_def_path(def_id, &ZEROED_PATH) {
- "zero-initialization"
- } else {
- "being left uninitialized"
- }
- ),
- );
- err.span_label(expr.span,
- "this code causes undefined behavior when executed");
- err.span_label(expr.span, "help: use `MaybeUninit<T>` instead");
- if let Some(span) = span {
- err.span_note(span, &msg);
- } else {
- err.note(&msg);
- }
- err.emit();
- }
- }
+ if let Some(init) = is_dangerous_init(cx, expr) {
+ // This conjures an instance of a type out of nothing,
+ // using zeroed or uninitialized memory.
+ // We are extremely conservative with what we warn about.
+ let conjured_ty = cx.tables.expr_ty(expr);
+ if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) {
+ let mut err = cx.struct_span_lint(
+ INVALID_VALUE,
+ expr.span,
+ &format!(
+ "the type `{}` does not permit {}",
+ conjured_ty,
+ match init {
+ InitKind::Zeroed => "zero-initialization",
+ InitKind::Uninit => "being left uninitialized",
+ },
+ ),
+ );
+ err.span_label(expr.span,
+ "this code causes undefined behavior when executed");
+ err.span_label(expr.span, "help: use `MaybeUninit<T>` instead");
+ if let Some(span) = span {
+ err.span_note(span, &msg);
+ } else {
+ err.note(&msg);
}
+ err.emit();
}
}
}
diff --git a/src/test/pretty/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs
index 02d9323..619cce6 100644
--- a/src/test/pretty/stmt_expr_attributes.rs
+++ b/src/test/pretty/stmt_expr_attributes.rs
@@ -259,8 +259,6 @@
}
}
-/////////////////
-
fn foo() { }
fn foo3(_: i32, _: (), _: ()) { }
fn qux(_: i32) { }
diff --git a/src/test/ui/associated-type/associated-type-projection-from-supertrait.rs b/src/test/ui/associated-type/associated-type-projection-from-supertrait.rs
index 06dfe49..7e05bcd 100644
--- a/src/test/ui/associated-type/associated-type-projection-from-supertrait.rs
+++ b/src/test/ui/associated-type/associated-type-projection-from-supertrait.rs
@@ -12,30 +12,22 @@
fn chip_paint(&self, c: Self::Color) { }
}
-///////////////////////////////////////////////////////////////////////////
-
struct Black;
struct ModelT;
impl Vehicle for ModelT { type Color = Black; }
impl Car for ModelT { }
-///////////////////////////////////////////////////////////////////////////
-
struct Blue;
struct ModelU;
impl Vehicle for ModelU { type Color = Blue; }
impl Car for ModelU { }
-///////////////////////////////////////////////////////////////////////////
-
fn dent<C:Car>(c: C, color: C::Color) { c.chip_paint(color) }
fn a() { dent(ModelT, Black); }
fn b() { dent(ModelT, Blue); } //~ ERROR mismatched types
fn c() { dent(ModelU, Black); } //~ ERROR mismatched types
fn d() { dent(ModelU, Blue); }
-///////////////////////////////////////////////////////////////////////////
-
fn e() { ModelT.chip_paint(Black); }
fn f() { ModelT.chip_paint(Blue); } //~ ERROR mismatched types
fn g() { ModelU.chip_paint(Black); } //~ ERROR mismatched types
diff --git a/src/test/ui/associated-type/associated-type-projection-from-supertrait.stderr b/src/test/ui/associated-type/associated-type-projection-from-supertrait.stderr
index 06f1a1c..4ba4925 100644
--- a/src/test/ui/associated-type/associated-type-projection-from-supertrait.stderr
+++ b/src/test/ui/associated-type/associated-type-projection-from-supertrait.stderr
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
- --> $DIR/associated-type-projection-from-supertrait.rs:33:23
+ --> $DIR/associated-type-projection-from-supertrait.rs:27:23
|
LL | fn b() { dent(ModelT, Blue); }
| ^^^^ expected struct `Black`, found struct `Blue`
@@ -8,7 +8,7 @@
found type `Blue`
error[E0308]: mismatched types
- --> $DIR/associated-type-projection-from-supertrait.rs:34:23
+ --> $DIR/associated-type-projection-from-supertrait.rs:28:23
|
LL | fn c() { dent(ModelU, Black); }
| ^^^^^ expected struct `Blue`, found struct `Black`
@@ -17,7 +17,7 @@
found type `Black`
error[E0308]: mismatched types
- --> $DIR/associated-type-projection-from-supertrait.rs:40:28
+ --> $DIR/associated-type-projection-from-supertrait.rs:32:28
|
LL | fn f() { ModelT.chip_paint(Blue); }
| ^^^^ expected struct `Black`, found struct `Blue`
@@ -26,7 +26,7 @@
found type `Blue`
error[E0308]: mismatched types
- --> $DIR/associated-type-projection-from-supertrait.rs:41:28
+ --> $DIR/associated-type-projection-from-supertrait.rs:33:28
|
LL | fn g() { ModelU.chip_paint(Black); }
| ^^^^^ expected struct `Blue`, found struct `Black`
diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.rs b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.rs
index 6531308..6b2bbbe 100644
--- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.rs
+++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.rs
@@ -11,22 +11,16 @@
fn honk(&self) { }
}
-///////////////////////////////////////////////////////////////////////////
-
struct Black;
struct ModelT;
impl Vehicle for ModelT { type Color = Black; }
impl Car for ModelT { }
-///////////////////////////////////////////////////////////////////////////
-
struct Blue;
struct ModelU;
impl Vehicle for ModelU { type Color = Blue; }
impl Car for ModelU { }
-///////////////////////////////////////////////////////////////////////////
-
fn black_car<C:Car<Color=Black>>(c: C) {
}
diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr
index 4b54860..89c48d5 100644
--- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr
+++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr
@@ -1,5 +1,5 @@
error[E0271]: type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
- --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:37:10
+ --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10
|
LL | fn b() { blue_car(ModelT); }
| ^^^^^^^^ expected struct `Black`, found struct `Blue`
@@ -7,13 +7,13 @@
= note: expected type `Black`
found type `Blue`
note: required by `blue_car`
- --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:33:1
+ --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:27:1
|
LL | fn blue_car<C:Car<Color=Blue>>(c: C) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0271]: type mismatch resolving `<ModelU as Vehicle>::Color == Black`
- --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:38:10
+ --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10
|
LL | fn c() { black_car(ModelU); }
| ^^^^^^^^^ expected struct `Blue`, found struct `Black`
@@ -21,7 +21,7 @@
= note: expected type `Blue`
found type `Black`
note: required by `black_car`
- --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:30:1
+ --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:24:1
|
LL | fn black_car<C:Car<Color=Black>>(c: C) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/associated-types/associated-types-ref-from-struct.rs b/src/test/ui/associated-types/associated-types-ref-from-struct.rs
index 3ccba28..c89f604 100644
--- a/src/test/ui/associated-types/associated-types-ref-from-struct.rs
+++ b/src/test/ui/associated-types/associated-types-ref-from-struct.rs
@@ -9,8 +9,6 @@
fn test(&self, value: &Self::V) -> bool;
}
-///////////////////////////////////////////////////////////////////////////
-
struct TesterPair<T:Test> {
tester: T,
value: T::V,
@@ -26,8 +24,6 @@
}
}
-///////////////////////////////////////////////////////////////////////////
-
struct EqU32(u32);
impl Test for EqU32 {
type V = u32;
diff --git a/src/test/ui/consts/const-eval/ub-nonnull.rs b/src/test/ui/consts/const-eval/ub-nonnull.rs
index 431ff35..9edae19 100644
--- a/src/test/ui/consts/const-eval/ub-nonnull.rs
+++ b/src/test/ui/consts/const-eval/ub-nonnull.rs
@@ -1,5 +1,5 @@
#![feature(rustc_attrs, const_transmute)]
-#![allow(const_err)] // make sure we cannot allow away the errors tested here
+#![allow(const_err, invalid_value)] // make sure we cannot allow away the errors tested here
use std::mem;
use std::ptr::NonNull;
diff --git a/src/test/ui/consts/const-eval/ub-ref.rs b/src/test/ui/consts/const-eval/ub-ref.rs
index 0d8f301..bbab85c 100644
--- a/src/test/ui/consts/const-eval/ub-ref.rs
+++ b/src/test/ui/consts/const-eval/ub-ref.rs
@@ -1,6 +1,6 @@
// ignore-tidy-linelength
#![feature(const_transmute)]
-#![allow(const_err)] // make sure we cannot allow away the errors tested here
+#![allow(const_err, invalid_value)] // make sure we cannot allow away the errors tested here
use std::mem;
diff --git a/src/test/ui/consts/const-eval/ub-upvars.rs b/src/test/ui/consts/const-eval/ub-upvars.rs
index 0a427cd..baab14d 100644
--- a/src/test/ui/consts/const-eval/ub-upvars.rs
+++ b/src/test/ui/consts/const-eval/ub-upvars.rs
@@ -1,5 +1,5 @@
#![feature(const_transmute)]
-#![allow(const_err)] // make sure we cannot allow away the errors tested here
+#![allow(const_err, invalid_value)] // make sure we cannot allow away the errors tested here
use std::mem;
diff --git a/src/test/ui/higher-rank-trait-bounds/hrtb-type-outlives.rs b/src/test/ui/higher-rank-trait-bounds/hrtb-type-outlives.rs
index a8f3818..88d3961 100644
--- a/src/test/ui/higher-rank-trait-bounds/hrtb-type-outlives.rs
+++ b/src/test/ui/higher-rank-trait-bounds/hrtb-type-outlives.rs
@@ -14,7 +14,6 @@
{
}
-///////////////////////////////////////////////////////////////////////////
// Expressed as a where clause
struct SomeStruct<X> {
@@ -30,7 +29,6 @@
want_foo::<SomeStruct<usize>>();
}
-///////////////////////////////////////////////////////////////////////////
// Expressed as shorthand
struct AnotherStruct<X> {
diff --git a/src/test/ui/hrtb/hrtb-conflate-regions.rs b/src/test/ui/hrtb/hrtb-conflate-regions.rs
index 3913036..004d62a 100644
--- a/src/test/ui/hrtb/hrtb-conflate-regions.rs
+++ b/src/test/ui/hrtb/hrtb-conflate-regions.rs
@@ -15,7 +15,6 @@
{
}
-///////////////////////////////////////////////////////////////////////////
// Expressed as a where clause
struct SomeStruct;
diff --git a/src/test/ui/hrtb/hrtb-conflate-regions.stderr b/src/test/ui/hrtb/hrtb-conflate-regions.stderr
index 3fb6baa..20265d6 100644
--- a/src/test/ui/hrtb/hrtb-conflate-regions.stderr
+++ b/src/test/ui/hrtb/hrtb-conflate-regions.stderr
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `for<'a, 'b> SomeStruct: Foo<(&'a isize, &'b isize)>` is not satisfied
- --> $DIR/hrtb-conflate-regions.rs:28:10
+ --> $DIR/hrtb-conflate-regions.rs:27:10
|
LL | fn b() { want_foo2::<SomeStruct>(); }
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a, 'b> Foo<(&'a isize, &'b isize)>` is not implemented for `SomeStruct`
diff --git a/src/test/ui/impl-trait/bound-normalization-fail.rs b/src/test/ui/impl-trait/bound-normalization-fail.rs
index 9ba7c91..ce15505 100644
--- a/src/test/ui/impl-trait/bound-normalization-fail.rs
+++ b/src/test/ui/impl-trait/bound-normalization-fail.rs
@@ -8,7 +8,6 @@
// See issue 60414
-/////////////////////////////////////////////
// Reduction to `impl Trait`
struct Foo<T>(T);
@@ -33,7 +32,6 @@
}
}
-/////////////////////////////////////////////
// Same with lifetimes in the trait
mod lifetimes {
diff --git a/src/test/ui/impl-trait/bound-normalization-fail.stderr b/src/test/ui/impl-trait/bound-normalization-fail.stderr
index b5c8e07..4811b1e 100644
--- a/src/test/ui/impl-trait/bound-normalization-fail.stderr
+++ b/src/test/ui/impl-trait/bound-normalization-fail.stderr
@@ -7,7 +7,7 @@
= note: `#[warn(incomplete_features)]` on by default
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
- --> $DIR/bound-normalization-fail.rs:30:32
+ --> $DIR/bound-normalization-fail.rs:29:32
|
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output=T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type
@@ -17,13 +17,13 @@
= note: the return type of a function must have a statically known size
error: `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
- --> $DIR/bound-normalization-fail.rs:47:41
+ --> $DIR/bound-normalization-fail.rs:45:41
|
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
- --> $DIR/bound-normalization-fail.rs:47:41
+ --> $DIR/bound-normalization-fail.rs:45:41
|
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type
diff --git a/src/test/ui/impl-trait/bound-normalization-pass.rs b/src/test/ui/impl-trait/bound-normalization-pass.rs
index 5b634e3..b0ed4be 100644
--- a/src/test/ui/impl-trait/bound-normalization-pass.rs
+++ b/src/test/ui/impl-trait/bound-normalization-pass.rs
@@ -8,7 +8,6 @@
// See issue 60414
-/////////////////////////////////////////////
// Reduction to `impl Trait`
struct Foo<T>(T);
@@ -32,7 +31,6 @@
}
}
-/////////////////////////////////////////////
// Same with lifetimes in the trait
mod lifetimes {
@@ -59,7 +57,6 @@
}
}
-/////////////////////////////////////////////
// Reduction using `impl Trait` in bindings
mod impl_trait_in_bindings {
@@ -80,7 +77,6 @@
}
}
-/////////////////////////////////////////////
// The same applied to `type Foo = impl Bar`s
mod opaque_types {
diff --git a/src/test/ui/issues/issue-12028.rs b/src/test/ui/issues/issue-12028.rs
index d553545..7c2b0d6 100644
--- a/src/test/ui/issues/issue-12028.rs
+++ b/src/test/ui/issues/issue-12028.rs
@@ -17,8 +17,6 @@
fn stream(&self) -> Self::S;
}
-//////////////////////////////////////////////////////////////////////////////
-
trait StreamHash<H: StreamHasher>: Hash<H> {
fn input_stream(&self, stream: &mut H::S);
}
diff --git a/src/test/ui/issues/issue-12028.stderr b/src/test/ui/issues/issue-12028.stderr
index 64694c7..24aa88c 100644
--- a/src/test/ui/issues/issue-12028.stderr
+++ b/src/test/ui/issues/issue-12028.stderr
@@ -1,5 +1,5 @@
error[E0284]: type annotations required: cannot resolve `<_ as StreamHasher>::S == <H as StreamHasher>::S`
- --> $DIR/issue-12028.rs:29:14
+ --> $DIR/issue-12028.rs:27:14
|
LL | self.input_stream(&mut stream);
| ^^^^^^^^^^^^
diff --git a/src/test/ui/issues/issue-16739.rs b/src/test/ui/issues/issue-16739.rs
index 54ad8fd..94da2ca 100644
--- a/src/test/ui/issues/issue-16739.rs
+++ b/src/test/ui/issues/issue-16739.rs
@@ -16,8 +16,6 @@
extern "rust-call" fn call_once(mut self, _: ()) -> u32 { self.call_mut(()) }
}
-/////////////////////////////////////////////////////////////////////////
-
impl FnMut<(u32,)> for Foo {
extern "rust-call" fn call_mut(&mut self, (x,): (u32,)) -> u32 { self.foo + x }
}
@@ -27,8 +25,6 @@
extern "rust-call" fn call_once(mut self, args: (u32,)) -> u32 { self.call_mut(args) }
}
-/////////////////////////////////////////////////////////////////////////
-
impl FnMut<(u32,u32)> for Foo {
extern "rust-call" fn call_mut(&mut self, (x, y): (u32, u32)) -> u32 { self.foo + x + y }
}
diff --git a/src/test/ui/lint/uninitialized-zeroed.rs b/src/test/ui/lint/uninitialized-zeroed.rs
index d816479..5cf62b8 100644
--- a/src/test/ui/lint/uninitialized-zeroed.rs
+++ b/src/test/ui/lint/uninitialized-zeroed.rs
@@ -2,11 +2,13 @@
// This test checks that calling `mem::{uninitialized,zeroed}` with certain types results
// in a lint.
-#![feature(never_type)]
+#![feature(never_type, rustc_attrs)]
#![allow(deprecated)]
#![deny(invalid_value)]
use std::mem::{self, MaybeUninit};
+use std::ptr::NonNull;
+use std::num::NonZeroU32;
enum Void {}
@@ -16,6 +18,11 @@
struct Wrap<T> { wrapped: T }
enum WrapEnum<T> { Wrapped(T) }
+#[rustc_layout_scalar_valid_range_start(0)]
+#[rustc_layout_scalar_valid_range_end(128)]
+#[repr(transparent)]
+pub(crate) struct NonBig(u64);
+
#[allow(unused)]
fn generic<T: 'static>() {
unsafe {
@@ -29,6 +36,7 @@
fn main() {
unsafe {
+ // Things that cannot even be zero.
let _val: ! = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: ! = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
@@ -56,11 +64,28 @@
let _val: Wrap<(RefPair, i32)> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
- // Some types that should work just fine.
+ let _val: NonNull<i32> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
+ let _val: NonNull<i32> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
+ // Things that can be zero, but not uninit.
+ let _val: bool = mem::zeroed();
+ let _val: bool = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
+ let _val: Wrap<char> = mem::zeroed();
+ let _val: Wrap<char> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
+ let _val: NonBig = mem::zeroed();
+ let _val: NonBig = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
+ // Transmute-from-0
+ let _val: &'static i32 = mem::transmute(0usize); //~ ERROR: does not permit zero-initialization
+ let _val: &'static [i32] = mem::transmute((0usize, 0usize)); //~ ERROR: does not permit zero-initialization
+ let _val: NonZeroU32 = mem::transmute(0); //~ ERROR: does not permit zero-initialization
+
+ // Some more types that should work just fine.
let _val: Option<&'static i32> = mem::zeroed();
let _val: Option<fn()> = mem::zeroed();
let _val: MaybeUninit<&'static i32> = mem::zeroed();
- let _val: bool = mem::zeroed();
let _val: i32 = mem::zeroed();
}
}
diff --git a/src/test/ui/lint/uninitialized-zeroed.stderr b/src/test/ui/lint/uninitialized-zeroed.stderr
index 1b15fc2..a36a32a 100644
--- a/src/test/ui/lint/uninitialized-zeroed.stderr
+++ b/src/test/ui/lint/uninitialized-zeroed.stderr
@@ -1,5 +1,5 @@
error: the type `&'static T` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:22:32
+ --> $DIR/uninitialized-zeroed.rs:29:32
|
LL | let _val: &'static T = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -15,7 +15,7 @@
= note: References must be non-null
error: the type `&'static T` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:23:32
+ --> $DIR/uninitialized-zeroed.rs:30:32
|
LL | let _val: &'static T = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@
= note: References must be non-null
error: the type `Wrap<&'static T>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:25:38
+ --> $DIR/uninitialized-zeroed.rs:32:38
|
LL | let _val: Wrap<&'static T> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -35,13 +35,13 @@
| help: use `MaybeUninit<T>` instead
|
note: References must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:16:18
+ --> $DIR/uninitialized-zeroed.rs:18:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `Wrap<&'static T>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:26:38
+ --> $DIR/uninitialized-zeroed.rs:33:38
|
LL | let _val: Wrap<&'static T> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -50,13 +50,13 @@
| help: use `MaybeUninit<T>` instead
|
note: References must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:16:18
+ --> $DIR/uninitialized-zeroed.rs:18:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `!` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:32:23
+ --> $DIR/uninitialized-zeroed.rs:40:23
|
LL | let _val: ! = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -67,7 +67,7 @@
= note: The never type (`!`) has no valid value
error: the type `!` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:33:23
+ --> $DIR/uninitialized-zeroed.rs:41:23
|
LL | let _val: ! = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -78,7 +78,7 @@
= note: The never type (`!`) has no valid value
error: the type `(i32, !)` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:35:30
+ --> $DIR/uninitialized-zeroed.rs:43:30
|
LL | let _val: (i32, !) = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -89,7 +89,7 @@
= note: The never type (`!`) has no valid value
error: the type `(i32, !)` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:36:30
+ --> $DIR/uninitialized-zeroed.rs:44:30
|
LL | let _val: (i32, !) = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -100,7 +100,7 @@
= note: The never type (`!`) has no valid value
error: the type `Void` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:38:26
+ --> $DIR/uninitialized-zeroed.rs:46:26
|
LL | let _val: Void = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -111,7 +111,7 @@
= note: 0-variant enums have no valid value
error: the type `Void` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:39:26
+ --> $DIR/uninitialized-zeroed.rs:47:26
|
LL | let _val: Void = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -122,7 +122,7 @@
= note: 0-variant enums have no valid value
error: the type `&'static i32` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:41:34
+ --> $DIR/uninitialized-zeroed.rs:49:34
|
LL | let _val: &'static i32 = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -133,7 +133,7 @@
= note: References must be non-null
error: the type `&'static i32` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:42:34
+ --> $DIR/uninitialized-zeroed.rs:50:34
|
LL | let _val: &'static i32 = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -144,7 +144,7 @@
= note: References must be non-null
error: the type `Ref` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:44:25
+ --> $DIR/uninitialized-zeroed.rs:52:25
|
LL | let _val: Ref = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -153,13 +153,13 @@
| help: use `MaybeUninit<T>` instead
|
note: References must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:13:12
+ --> $DIR/uninitialized-zeroed.rs:15:12
|
LL | struct Ref(&'static i32);
| ^^^^^^^^^^^^
error: the type `Ref` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:45:25
+ --> $DIR/uninitialized-zeroed.rs:53:25
|
LL | let _val: Ref = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -168,13 +168,13 @@
| help: use `MaybeUninit<T>` instead
|
note: References must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:13:12
+ --> $DIR/uninitialized-zeroed.rs:15:12
|
LL | struct Ref(&'static i32);
| ^^^^^^^^^^^^
error: the type `fn()` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:47:26
+ --> $DIR/uninitialized-zeroed.rs:55:26
|
LL | let _val: fn() = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -185,7 +185,7 @@
= note: Function pointers must be non-null
error: the type `fn()` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:48:26
+ --> $DIR/uninitialized-zeroed.rs:56:26
|
LL | let _val: fn() = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -196,7 +196,7 @@
= note: Function pointers must be non-null
error: the type `Wrap<fn()>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:50:32
+ --> $DIR/uninitialized-zeroed.rs:58:32
|
LL | let _val: Wrap<fn()> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -205,13 +205,13 @@
| help: use `MaybeUninit<T>` instead
|
note: Function pointers must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:16:18
+ --> $DIR/uninitialized-zeroed.rs:18:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `Wrap<fn()>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:51:32
+ --> $DIR/uninitialized-zeroed.rs:59:32
|
LL | let _val: Wrap<fn()> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -220,13 +220,13 @@
| help: use `MaybeUninit<T>` instead
|
note: Function pointers must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:16:18
+ --> $DIR/uninitialized-zeroed.rs:18:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `WrapEnum<fn()>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:53:36
+ --> $DIR/uninitialized-zeroed.rs:61:36
|
LL | let _val: WrapEnum<fn()> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -235,13 +235,13 @@
| help: use `MaybeUninit<T>` instead
|
note: Function pointers must be non-null (in this enum field)
- --> $DIR/uninitialized-zeroed.rs:17:28
+ --> $DIR/uninitialized-zeroed.rs:19:28
|
LL | enum WrapEnum<T> { Wrapped(T) }
| ^
error: the type `WrapEnum<fn()>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:54:36
+ --> $DIR/uninitialized-zeroed.rs:62:36
|
LL | let _val: WrapEnum<fn()> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -250,13 +250,13 @@
| help: use `MaybeUninit<T>` instead
|
note: Function pointers must be non-null (in this enum field)
- --> $DIR/uninitialized-zeroed.rs:17:28
+ --> $DIR/uninitialized-zeroed.rs:19:28
|
LL | enum WrapEnum<T> { Wrapped(T) }
| ^
error: the type `Wrap<(RefPair, i32)>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:56:42
+ --> $DIR/uninitialized-zeroed.rs:64:42
|
LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -265,13 +265,13 @@
| help: use `MaybeUninit<T>` instead
|
note: References must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:14:16
+ --> $DIR/uninitialized-zeroed.rs:16:16
|
LL | struct RefPair((&'static i32, i32));
| ^^^^^^^^^^^^^^^^^^^
error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:57:42
+ --> $DIR/uninitialized-zeroed.rs:65:42
|
LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -280,10 +280,102 @@
| help: use `MaybeUninit<T>` instead
|
note: References must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:14:16
+ --> $DIR/uninitialized-zeroed.rs:16:16
|
LL | struct RefPair((&'static i32, i32));
| ^^^^^^^^^^^^^^^^^^^
-error: aborting due to 22 previous errors
+error: the type `std::ptr::NonNull<i32>` does not permit zero-initialization
+ --> $DIR/uninitialized-zeroed.rs:67:34
+ |
+LL | let _val: NonNull<i32> = mem::zeroed();
+ | ^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+ = note: std::ptr::NonNull<i32> must be non-null
+
+error: the type `std::ptr::NonNull<i32>` does not permit being left uninitialized
+ --> $DIR/uninitialized-zeroed.rs:68:34
+ |
+LL | let _val: NonNull<i32> = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+ = note: std::ptr::NonNull<i32> must be non-null
+
+error: the type `bool` does not permit being left uninitialized
+ --> $DIR/uninitialized-zeroed.rs:72:26
+ |
+LL | let _val: bool = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+ = note: Booleans must be `true` or `false`
+
+error: the type `Wrap<char>` does not permit being left uninitialized
+ --> $DIR/uninitialized-zeroed.rs:75:32
+ |
+LL | let _val: Wrap<char> = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+note: Characters must be a valid unicode codepoint (in this struct field)
+ --> $DIR/uninitialized-zeroed.rs:18:18
+ |
+LL | struct Wrap<T> { wrapped: T }
+ | ^^^^^^^^^^
+
+error: the type `NonBig` does not permit being left uninitialized
+ --> $DIR/uninitialized-zeroed.rs:78:28
+ |
+LL | let _val: NonBig = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+ = note: NonBig must be initialized inside its custom valid range
+
+error: the type `&'static i32` does not permit zero-initialization
+ --> $DIR/uninitialized-zeroed.rs:81:34
+ |
+LL | let _val: &'static i32 = mem::transmute(0usize);
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+ = note: References must be non-null
+
+error: the type `&'static [i32]` does not permit zero-initialization
+ --> $DIR/uninitialized-zeroed.rs:82:36
+ |
+LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+ = note: References must be non-null
+
+error: the type `std::num::NonZeroU32` does not permit zero-initialization
+ --> $DIR/uninitialized-zeroed.rs:83:32
+ |
+LL | let _val: NonZeroU32 = mem::transmute(0);
+ | ^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead
+ |
+ = note: std::num::NonZeroU32 must be non-null
+
+error: aborting due to 30 previous errors
diff --git a/src/test/ui/methods/method-projection.rs b/src/test/ui/methods/method-projection.rs
index cf33d53..21d983f 100644
--- a/src/test/ui/methods/method-projection.rs
+++ b/src/test/ui/methods/method-projection.rs
@@ -2,9 +2,6 @@
// Test that we can use method notation to call methods based on a
// projection bound from a trait. Issue #20469.
-///////////////////////////////////////////////////////////////////////////
-
-
trait MakeString {
fn make_string(&self) -> String;
}
@@ -21,8 +18,6 @@
}
}
-///////////////////////////////////////////////////////////////////////////
-
trait Foo {
type F: MakeString;
@@ -33,8 +28,6 @@
f.get().make_string()
}
-///////////////////////////////////////////////////////////////////////////
-
struct SomeStruct {
field: isize,
}
@@ -47,8 +40,6 @@
}
}
-///////////////////////////////////////////////////////////////////////////
-
struct SomeOtherStruct {
field: usize,
}
diff --git a/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.nll.stderr b/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.nll.stderr
index 5028663..eed9934 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.nll.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.nll.stderr
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container-hrtb.rs:35:12
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:30:12
|
LL | fn with_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
@@ -10,7 +10,7 @@
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container-hrtb.rs:57:12
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:50:12
|
LL | fn with_assoc_sub<'a,'b>() {
| -- -- lifetime `'b` defined here
diff --git a/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr b/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr
index d833018..ed58009 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr
@@ -1,33 +1,33 @@
error[E0491]: in type `&'a WithHrAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
- --> $DIR/regions-outlives-projection-container-hrtb.rs:35:12
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:30:12
|
LL | let _: &'a WithHrAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the pointer is valid for the lifetime 'a as defined on the function body at 32:15
- --> $DIR/regions-outlives-projection-container-hrtb.rs:32:15
+note: the pointer is valid for the lifetime 'a as defined on the function body at 27:15
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:27:15
|
LL | fn with_assoc<'a,'b>() {
| ^^
-note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 32:18
- --> $DIR/regions-outlives-projection-container-hrtb.rs:32:18
+note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 27:18
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:27:18
|
LL | fn with_assoc<'a,'b>() {
| ^^
error[E0491]: in type `&'a WithHrAssocSub<TheType<'b>>`, reference has a longer lifetime than the data it references
- --> $DIR/regions-outlives-projection-container-hrtb.rs:57:12
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:50:12
|
LL | let _: &'a WithHrAssocSub<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the pointer is valid for the lifetime 'a as defined on the function body at 53:19
- --> $DIR/regions-outlives-projection-container-hrtb.rs:53:19
+note: the pointer is valid for the lifetime 'a as defined on the function body at 46:19
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:46:19
|
LL | fn with_assoc_sub<'a,'b>() {
| ^^
-note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 53:22
- --> $DIR/regions-outlives-projection-container-hrtb.rs:53:22
+note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 46:22
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:46:22
|
LL | fn with_assoc_sub<'a,'b>() {
| ^^
diff --git a/src/test/ui/regions/regions-outlives-projection-container-hrtb.nll.stderr b/src/test/ui/regions/regions-outlives-projection-container-hrtb.nll.stderr
index 5028663..eed9934 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-hrtb.nll.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container-hrtb.nll.stderr
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container-hrtb.rs:35:12
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:30:12
|
LL | fn with_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
@@ -10,7 +10,7 @@
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container-hrtb.rs:57:12
+ --> $DIR/regions-outlives-projection-container-hrtb.rs:50:12
|
LL | fn with_assoc_sub<'a,'b>() {
| -- -- lifetime `'b` defined here
diff --git a/src/test/ui/regions/regions-outlives-projection-container-hrtb.rs b/src/test/ui/regions/regions-outlives-projection-container-hrtb.rs
index 407a4fd..cee7411 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-hrtb.rs
+++ b/src/test/ui/regions/regions-outlives-projection-container-hrtb.rs
@@ -6,9 +6,6 @@
#![allow(dead_code)]
-
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheTrait<'b> {
type TheAssocType;
}
@@ -21,8 +18,6 @@
type TheAssocType = &'b ();
}
-///////////////////////////////////////////////////////////////////////////
-
pub struct WithHrAssoc<T>
where for<'a> T : TheTrait<'a>
{
@@ -37,8 +32,6 @@
//[nll]~^^ ERROR lifetime may not live long enough
}
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheSubTrait : for<'a> TheTrait<'a> {
}
diff --git a/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.nll.stderr b/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.nll.stderr
index 880fe17..8c54d8d 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.nll.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.nll.stderr
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container-wc.rs:37:12
+ --> $DIR/regions-outlives-projection-container-wc.rs:33:12
|
LL | fn with_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
diff --git a/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr b/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr
index 9e31065..152e6c5 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr
@@ -1,16 +1,16 @@
error[E0491]: in type `&'a WithAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
- --> $DIR/regions-outlives-projection-container-wc.rs:37:12
+ --> $DIR/regions-outlives-projection-container-wc.rs:33:12
|
LL | let _: &'a WithAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the pointer is valid for the lifetime 'a as defined on the function body at 31:15
- --> $DIR/regions-outlives-projection-container-wc.rs:31:15
+note: the pointer is valid for the lifetime 'a as defined on the function body at 27:15
+ --> $DIR/regions-outlives-projection-container-wc.rs:27:15
|
LL | fn with_assoc<'a,'b>() {
| ^^
-note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 31:18
- --> $DIR/regions-outlives-projection-container-wc.rs:31:18
+note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 27:18
+ --> $DIR/regions-outlives-projection-container-wc.rs:27:18
|
LL | fn with_assoc<'a,'b>() {
| ^^
diff --git a/src/test/ui/regions/regions-outlives-projection-container-wc.nll.stderr b/src/test/ui/regions/regions-outlives-projection-container-wc.nll.stderr
index 880fe17..8c54d8d 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-wc.nll.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container-wc.nll.stderr
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container-wc.rs:37:12
+ --> $DIR/regions-outlives-projection-container-wc.rs:33:12
|
LL | fn with_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
diff --git a/src/test/ui/regions/regions-outlives-projection-container-wc.rs b/src/test/ui/regions/regions-outlives-projection-container-wc.rs
index 5037ea5..99965f3 100644
--- a/src/test/ui/regions/regions-outlives-projection-container-wc.rs
+++ b/src/test/ui/regions/regions-outlives-projection-container-wc.rs
@@ -8,8 +8,6 @@
#![allow(dead_code)]
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheTrait {
type TheAssocType;
}
@@ -22,8 +20,6 @@
type TheAssocType = &'b ();
}
-///////////////////////////////////////////////////////////////////////////
-
pub struct WithAssoc<T> where T : TheTrait {
m: [T; 0]
}
diff --git a/src/test/ui/regions/regions-outlives-projection-container.nll.stderr b/src/test/ui/regions/regions-outlives-projection-container.nll.stderr
index ef87d02..2cf6e24 100644
--- a/src/test/ui/regions/regions-outlives-projection-container.nll.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container.nll.stderr
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container.rs:40:13
+ --> $DIR/regions-outlives-projection-container.rs:36:13
|
LL | fn with_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
@@ -10,7 +10,7 @@
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container.rs:58:13
+ --> $DIR/regions-outlives-projection-container.rs:54:13
|
LL | fn without_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
@@ -21,7 +21,7 @@
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'a`
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container.rs:67:5
+ --> $DIR/regions-outlives-projection-container.rs:63:5
|
LL | fn call_with_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
@@ -32,7 +32,7 @@
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a`
error: lifetime may not live long enough
- --> $DIR/regions-outlives-projection-container.rs:74:5
+ --> $DIR/regions-outlives-projection-container.rs:70:5
|
LL | fn call_without_assoc<'a,'b>() {
| -- -- lifetime `'b` defined here
diff --git a/src/test/ui/regions/regions-outlives-projection-container.rs b/src/test/ui/regions/regions-outlives-projection-container.rs
index 78305c0..3afc600 100644
--- a/src/test/ui/regions/regions-outlives-projection-container.rs
+++ b/src/test/ui/regions/regions-outlives-projection-container.rs
@@ -5,8 +5,6 @@
#![allow(dead_code)]
#![feature(rustc_attrs)]
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheTrait {
type TheAssocType;
}
@@ -19,8 +17,6 @@
type TheAssocType = &'b ();
}
-///////////////////////////////////////////////////////////////////////////
-
pub struct WithAssoc<T:TheTrait> {
m: [T; 0]
}
diff --git a/src/test/ui/regions/regions-outlives-projection-container.stderr b/src/test/ui/regions/regions-outlives-projection-container.stderr
index b50347a..3c1a98a 100644
--- a/src/test/ui/regions/regions-outlives-projection-container.stderr
+++ b/src/test/ui/regions/regions-outlives-projection-container.stderr
@@ -1,67 +1,67 @@
error[E0491]: in type `&'a WithAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
- --> $DIR/regions-outlives-projection-container.rs:40:13
+ --> $DIR/regions-outlives-projection-container.rs:36:13
|
LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the pointer is valid for the lifetime 'a as defined on the function body at 32:15
- --> $DIR/regions-outlives-projection-container.rs:32:15
+note: the pointer is valid for the lifetime 'a as defined on the function body at 28:15
+ --> $DIR/regions-outlives-projection-container.rs:28:15
|
LL | fn with_assoc<'a,'b>() {
| ^^
-note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 32:18
- --> $DIR/regions-outlives-projection-container.rs:32:18
+note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 28:18
+ --> $DIR/regions-outlives-projection-container.rs:28:18
|
LL | fn with_assoc<'a,'b>() {
| ^^
error[E0491]: in type `&'a WithoutAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
- --> $DIR/regions-outlives-projection-container.rs:58:13
+ --> $DIR/regions-outlives-projection-container.rs:54:13
|
LL | let _x: &'a WithoutAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the pointer is valid for the lifetime 'a as defined on the function body at 54:18
- --> $DIR/regions-outlives-projection-container.rs:54:18
+note: the pointer is valid for the lifetime 'a as defined on the function body at 50:18
+ --> $DIR/regions-outlives-projection-container.rs:50:18
|
LL | fn without_assoc<'a,'b>() {
| ^^
-note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 54:21
- --> $DIR/regions-outlives-projection-container.rs:54:21
+note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 50:21
+ --> $DIR/regions-outlives-projection-container.rs:50:21
|
LL | fn without_assoc<'a,'b>() {
| ^^
error[E0491]: in type `&'a WithAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
- --> $DIR/regions-outlives-projection-container.rs:67:12
+ --> $DIR/regions-outlives-projection-container.rs:63:12
|
LL | call::<&'a WithAssoc<TheType<'b>>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the pointer is valid for the lifetime 'a as defined on the function body at 62:20
- --> $DIR/regions-outlives-projection-container.rs:62:20
+note: the pointer is valid for the lifetime 'a as defined on the function body at 58:20
+ --> $DIR/regions-outlives-projection-container.rs:58:20
|
LL | fn call_with_assoc<'a,'b>() {
| ^^
-note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 62:23
- --> $DIR/regions-outlives-projection-container.rs:62:23
+note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 58:23
+ --> $DIR/regions-outlives-projection-container.rs:58:23
|
LL | fn call_with_assoc<'a,'b>() {
| ^^
error[E0491]: in type `&'a WithoutAssoc<TheType<'b>>`, reference has a longer lifetime than the data it references
- --> $DIR/regions-outlives-projection-container.rs:74:12
+ --> $DIR/regions-outlives-projection-container.rs:70:12
|
LL | call::<&'a WithoutAssoc<TheType<'b>>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the pointer is valid for the lifetime 'a as defined on the function body at 71:23
- --> $DIR/regions-outlives-projection-container.rs:71:23
+note: the pointer is valid for the lifetime 'a as defined on the function body at 67:23
+ --> $DIR/regions-outlives-projection-container.rs:67:23
|
LL | fn call_without_assoc<'a,'b>() {
| ^^
-note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 71:26
- --> $DIR/regions-outlives-projection-container.rs:71:26
+note: but the referenced data is only valid for the lifetime 'b as defined on the function body at 67:26
+ --> $DIR/regions-outlives-projection-container.rs:67:26
|
LL | fn call_without_assoc<'a,'b>() {
| ^^
diff --git a/src/test/ui/specialization/defaultimpl/specialization-no-default.rs b/src/test/ui/specialization/defaultimpl/specialization-no-default.rs
index 7ea79a9..37005f83 100644
--- a/src/test/ui/specialization/defaultimpl/specialization-no-default.rs
+++ b/src/test/ui/specialization/defaultimpl/specialization-no-default.rs
@@ -3,9 +3,7 @@
// Check a number of scenarios in which one impl tries to override another,
// without correctly using `default`.
-////////////////////////////////////////////////////////////////////////////////
// Test 1: one layer of specialization, multiple methods, missing `default`
-////////////////////////////////////////////////////////////////////////////////
trait Foo {
fn foo(&self);
@@ -25,9 +23,7 @@
fn bar(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 2: one layer of specialization, missing `default` on associated type
-////////////////////////////////////////////////////////////////////////////////
trait Bar {
type T;
@@ -41,9 +37,7 @@
type T = (); //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3a: multiple layers of specialization, missing interior `default`
-////////////////////////////////////////////////////////////////////////////////
trait Baz {
fn baz(&self);
@@ -61,10 +55,8 @@
fn baz(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3b: multiple layers of specialization, missing interior `default`,
// redundant `default` in bottom layer.
-////////////////////////////////////////////////////////////////////////////////
trait Redundant {
fn redundant(&self);
diff --git a/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr b/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr
index 91690f6..13636b2 100644
--- a/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr
+++ b/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr
@@ -1,5 +1,5 @@
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:22:5
+ --> $DIR/specialization-no-default.rs:20:5
|
LL | / impl<T> Foo for T {
LL | | fn foo(&self) {}
@@ -13,7 +13,7 @@
= note: to specialize, `foo` in the parent `impl` must be marked `default`
error[E0520]: `bar` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:25:5
+ --> $DIR/specialization-no-default.rs:23:5
|
LL | / impl<T> Foo for T {
LL | | fn foo(&self) {}
@@ -27,7 +27,7 @@
= note: to specialize, `bar` in the parent `impl` must be marked `default`
error[E0520]: `T` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:41:5
+ --> $DIR/specialization-no-default.rs:37:5
|
LL | / impl<T> Bar for T {
LL | | type T = u8;
@@ -40,7 +40,7 @@
= note: to specialize, `T` in the parent `impl` must be marked `default`
error[E0520]: `baz` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:61:5
+ --> $DIR/specialization-no-default.rs:55:5
|
LL | / impl<T: Clone> Baz for T {
LL | | fn baz(&self) {}
@@ -53,7 +53,7 @@
= note: to specialize, `baz` in the parent `impl` must be marked `default`
error[E0520]: `redundant` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:82:5
+ --> $DIR/specialization-no-default.rs:74:5
|
LL | / impl<T: Clone> Redundant for T {
LL | | fn redundant(&self) {}
diff --git a/src/test/ui/specialization/specialization-no-default.rs b/src/test/ui/specialization/specialization-no-default.rs
index 29afbbd9..57346b2 100644
--- a/src/test/ui/specialization/specialization-no-default.rs
+++ b/src/test/ui/specialization/specialization-no-default.rs
@@ -3,9 +3,7 @@
// Check a number of scenarios in which one impl tries to override another,
// without correctly using `default`.
-////////////////////////////////////////////////////////////////////////////////
// Test 1: one layer of specialization, multiple methods, missing `default`
-////////////////////////////////////////////////////////////////////////////////
trait Foo {
fn foo(&self);
@@ -25,9 +23,7 @@
fn bar(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 2: one layer of specialization, missing `default` on associated type
-////////////////////////////////////////////////////////////////////////////////
trait Bar {
type T;
@@ -41,9 +37,7 @@
type T = (); //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3a: multiple layers of specialization, missing interior `default`
-////////////////////////////////////////////////////////////////////////////////
trait Baz {
fn baz(&self);
@@ -61,10 +55,8 @@
fn baz(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3b: multiple layers of specialization, missing interior `default`,
// redundant `default` in bottom layer.
-////////////////////////////////////////////////////////////////////////////////
trait Redundant {
fn redundant(&self);
diff --git a/src/test/ui/specialization/specialization-no-default.stderr b/src/test/ui/specialization/specialization-no-default.stderr
index c39986d..992e9ab 100644
--- a/src/test/ui/specialization/specialization-no-default.stderr
+++ b/src/test/ui/specialization/specialization-no-default.stderr
@@ -1,5 +1,5 @@
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:22:5
+ --> $DIR/specialization-no-default.rs:20:5
|
LL | / impl<T> Foo for T {
LL | | fn foo(&self) {}
@@ -13,7 +13,7 @@
= note: to specialize, `foo` in the parent `impl` must be marked `default`
error[E0520]: `bar` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:25:5
+ --> $DIR/specialization-no-default.rs:23:5
|
LL | / impl<T> Foo for T {
LL | | fn foo(&self) {}
@@ -27,7 +27,7 @@
= note: to specialize, `bar` in the parent `impl` must be marked `default`
error[E0520]: `T` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:41:5
+ --> $DIR/specialization-no-default.rs:37:5
|
LL | / impl<T> Bar for T {
LL | | type T = u8;
@@ -40,7 +40,7 @@
= note: to specialize, `T` in the parent `impl` must be marked `default`
error[E0520]: `baz` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:61:5
+ --> $DIR/specialization-no-default.rs:55:5
|
LL | / impl<T: Clone> Baz for T {
LL | | fn baz(&self) {}
@@ -53,7 +53,7 @@
= note: to specialize, `baz` in the parent `impl` must be marked `default`
error[E0520]: `redundant` specializes an item from a parent `impl`, but that item is not marked `default`
- --> $DIR/specialization-no-default.rs:82:5
+ --> $DIR/specialization-no-default.rs:74:5
|
LL | / impl<T: Clone> Redundant for T {
LL | | fn redundant(&self) {}
diff --git a/src/test/ui/traits/traits-conditional-model-fn.rs b/src/test/ui/traits/traits-conditional-model-fn.rs
index 27ce6d9..afdfb96 100644
--- a/src/test/ui/traits/traits-conditional-model-fn.rs
+++ b/src/test/ui/traits/traits-conditional-model-fn.rs
@@ -14,8 +14,6 @@
use std::rc::Rc;
use std::cell::Cell;
-///////////////////////////////////////////////////////////////////////////
-
struct SomeGoableThing {
counter: Rc<Cell<isize>>
}
@@ -26,8 +24,6 @@
}
}
-///////////////////////////////////////////////////////////////////////////
-
struct SomeGoOnceableThing {
counter: Rc<Cell<isize>>
}
@@ -38,8 +34,6 @@
}
}
-///////////////////////////////////////////////////////////////////////////
-
fn main() {
let counter = Rc::new(Cell::new(0));
let mut x = SomeGoableThing { counter: counter.clone() };