Auto merge of #63671 - Centril:rollup-zufavt5, r=Centril

Rollup of 5 pull requests

Successful merges:

 - #62451 (Add APIs for uninitialized Box, Rc, and Arc. (Plus get_mut_unchecked))
 - #63487 (Remove meaningless comments in src/test)
 - #63657 (Crank up invalid value lint)
 - #63667 (resolve: Properly integrate derives and `macro_rules` scopes)
 - #63669 (fix typos in mir/interpret)

Failed merges:

r? @ghost
This commit is contained in:
bors 2019-08-17 21:30:10 +00:00
commit bd1da18b04
54 changed files with 924 additions and 290 deletions

View File

@ -91,8 +91,10 @@ use core::ops::{
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 @@ impl<T> Box<T> {
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> {
}
}
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.
///

View File

@ -327,6 +327,37 @@ impl<T> Rc<T> {
}))
}
/// 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> {
}
}
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 @@ impl<T: ?Sized> Rc<T> {
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 Rc<dyn Any> {
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 @@ impl<T: ?Sized> Rc<T> {
/// 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: ?Sized> Rc<T> {
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]>,
)

View File

@ -311,6 +311,37 @@ impl<T> Arc<T> {
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> {
}
}
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> {
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 @@ impl<T: ?Sized> Arc<T> {
/// 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: ?Sized> Arc<T> {
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 @@ impl<T: ?Sized> Arc<T> {
// 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.
///

View File

@ -122,6 +122,14 @@ impl<T: ?Sized> Unique<T> {
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")]

View File

@ -74,7 +74,7 @@ impl<'a> DefCollector<'a> {
})
}
fn visit_macro_invoc(&mut self, id: NodeId) {
pub fn visit_macro_invoc(&mut self, id: NodeId) {
self.definitions.set_invocation_parent(id.placeholder_to_expn_id(), self.parent_def);
}
}

View File

@ -306,7 +306,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
///
/// zsts can't be read out of two reasons:
/// * byteorder cannot work with zero element buffers
/// * in oder to obtain a `Pointer` we need to check for ZSTness anyway due to integer pointers
/// * in order to obtain a `Pointer` we need to check for ZSTness anyway due to integer pointers
/// being valid for ZSTs
///
/// It is the caller's responsibility to check bounds and alignment beforehand.

View File

@ -1876,16 +1876,70 @@ declare_lint_pass!(InvalidValue => [INVALID_VALUE]);
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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
})
})
}
// 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();
}
}
}

View File

@ -297,7 +297,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
/// and `align`. On success, returns `None` for zero-sized accesses (where
/// nothing else is left to do) and a `Pointer` to use for the actual access otherwise.
/// Crucially, if the input is a `Pointer`, we will test it for liveness
/// *even of* the size is 0.
/// *even if* the size is 0.
///
/// Everyone accessing memory based on a `Scalar` should use this method to get the
/// `Pointer` they need. And even if you already have a `Pointer`, call this method

View File

@ -160,12 +160,25 @@ impl<'a> Resolver<'a> {
Some(ext)
}
// FIXME: `extra_placeholders` should be included into the `fragment` as regular placeholders.
crate fn build_reduced_graph(
&mut self, fragment: &AstFragment, parent_scope: ParentScope<'a>
&mut self,
fragment: &AstFragment,
extra_placeholders: &[NodeId],
parent_scope: ParentScope<'a>,
) -> LegacyScope<'a> {
fragment.visit_with(&mut DefCollector::new(&mut self.definitions, parent_scope.expansion));
let mut def_collector = DefCollector::new(&mut self.definitions, parent_scope.expansion);
fragment.visit_with(&mut def_collector);
for placeholder in extra_placeholders {
def_collector.visit_macro_invoc(*placeholder);
}
let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope };
fragment.visit_with(&mut visitor);
for placeholder in extra_placeholders {
visitor.parent_scope.legacy = visitor.visit_invoc(*placeholder);
}
visitor.parent_scope.legacy
}
@ -871,7 +884,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}
/// Builds the reduced graph for a single item in an external crate.
fn build_reduced_graph_for_external_crate_res(&mut self, child: Export<ast::NodeId>) {
fn build_reduced_graph_for_external_crate_res(&mut self, child: Export<NodeId>) {
let parent = self.parent_scope.module;
let Export { ident, res, vis, span } = child;
// FIXME: We shouldn't create the gensym here, it should come from metadata,
@ -1060,10 +1073,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
false
}
fn visit_invoc(&mut self, id: ast::NodeId) -> LegacyScope<'a> {
fn visit_invoc(&mut self, id: NodeId) -> LegacyScope<'a> {
let invoc_id = id.placeholder_to_expn_id();
self.parent_scope.module.unresolved_invocations.borrow_mut().insert(invoc_id);
self.parent_scope.module.unexpanded_invocations.borrow_mut().insert(invoc_id);
let old_parent_scope = self.r.invocation_parent_scopes.insert(invoc_id, self.parent_scope);
assert!(old_parent_scope.is_none(), "invocation data is reset for an invocation");

View File

@ -448,7 +448,7 @@ pub struct ModuleData<'a> {
populate_on_access: Cell<bool>,
// Macro invocations that can expand into items in this module.
unresolved_invocations: RefCell<FxHashSet<ExpnId>>,
unexpanded_invocations: RefCell<FxHashSet<ExpnId>>,
no_implicit_prelude: bool,
@ -478,7 +478,7 @@ impl<'a> ModuleData<'a> {
normal_ancestor_id,
lazy_resolutions: Default::default(),
populate_on_access: Cell::new(!normal_ancestor_id.is_local()),
unresolved_invocations: Default::default(),
unexpanded_invocations: Default::default(),
no_implicit_prelude: false,
glob_importers: RefCell::new(Vec::new()),
globs: RefCell::new(Vec::new()),

View File

@ -10,7 +10,7 @@ use crate::resolve_imports::ImportResolver;
use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
use rustc::middle::stability;
use rustc::{ty, lint, span_bug};
use syntax::ast::{self, Ident};
use syntax::ast::{self, NodeId, Ident};
use syntax::attr::StabilityLevel;
use syntax::edition::Edition;
use syntax::ext::base::{self, Indeterminate, SpecialDerives};
@ -26,7 +26,7 @@ use syntax_pos::{Span, DUMMY_SP};
use std::{mem, ptr};
use rustc_data_structures::sync::Lrc;
type Res = def::Res<ast::NodeId>;
type Res = def::Res<NodeId>;
/// Binding produced by a `macro_rules` item.
/// Not modularized, can shadow previous legacy bindings, etc.
@ -91,11 +91,11 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
}
impl<'a> base::Resolver for Resolver<'a> {
fn next_node_id(&mut self) -> ast::NodeId {
fn next_node_id(&mut self) -> NodeId {
self.session.next_node_id()
}
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId {
fn get_module_scope(&mut self, id: NodeId) -> ExpnId {
let expn_id = ExpnId::fresh(Some(ExpnData::default(
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition()
)));
@ -115,23 +115,18 @@ impl<'a> base::Resolver for Resolver<'a> {
});
}
// FIXME: `extra_placeholders` should be included into the `fragment` as regular placeholders.
fn visit_ast_fragment_with_placeholders(
&mut self, expansion: ExpnId, fragment: &AstFragment, derives: &[ExpnId]
&mut self, expansion: ExpnId, fragment: &AstFragment, extra_placeholders: &[NodeId]
) {
// Fill in some data for derives if the fragment is from a derive container.
// Integrate the new AST fragment into all the definition and module structures.
// We are inside the `expansion` now, but other parent scope components are still the same.
let parent_scope = ParentScope { expansion, ..self.invocation_parent_scopes[&expansion] };
let parent_def = self.definitions.invocation_parent(expansion);
self.invocation_parent_scopes.extend(derives.iter().map(|&derive| (derive, parent_scope)));
for &derive_invoc_id in derives {
self.definitions.set_invocation_parent(derive_invoc_id, parent_def);
}
parent_scope.module.unresolved_invocations.borrow_mut().remove(&expansion);
parent_scope.module.unresolved_invocations.borrow_mut().extend(derives);
// Integrate the new AST fragment into all the definition and module structures.
let output_legacy_scope = self.build_reduced_graph(fragment, parent_scope);
let output_legacy_scope =
self.build_reduced_graph(fragment, extra_placeholders, parent_scope);
self.output_legacy_scopes.insert(expansion, output_legacy_scope);
parent_scope.module.unexpanded_invocations.borrow_mut().remove(&expansion);
}
fn register_builtin_macro(&mut self, ident: ast::Ident, ext: SyntaxExtension) {
@ -485,7 +480,7 @@ impl<'a> Resolver<'a> {
Scope::MacroUsePrelude => match this.macro_use_prelude.get(&ident.name).cloned() {
Some(binding) => Ok((binding, Flags::PRELUDE | Flags::MISC_FROM_PRELUDE)),
None => Err(Determinacy::determined(
this.graph_root.unresolved_invocations.borrow().is_empty()
this.graph_root.unexpanded_invocations.borrow().is_empty()
))
}
Scope::BuiltinAttrs => if is_builtin_attr_name(ident.name) {
@ -508,7 +503,7 @@ impl<'a> Resolver<'a> {
Scope::ExternPrelude => match this.extern_prelude_get(ident, !record_used) {
Some(binding) => Ok((binding, Flags::PRELUDE)),
None => Err(Determinacy::determined(
this.graph_root.unresolved_invocations.borrow().is_empty()
this.graph_root.unexpanded_invocations.borrow().is_empty()
)),
}
Scope::ToolPrelude => if KNOWN_TOOLS.contains(&ident.name) {

View File

@ -202,7 +202,7 @@ impl<'a> Resolver<'a> {
Err((Determined, Weak::No))
} else if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
Ok(binding)
} else if !self.graph_root.unresolved_invocations.borrow().is_empty() {
} else if !self.graph_root.unexpanded_invocations.borrow().is_empty() {
// Macro-expanded `extern crate` items can add names to extern prelude.
Err((Undetermined, Weak::No))
} else {
@ -348,7 +348,7 @@ impl<'a> Resolver<'a> {
// progress, we have to ignore those potential unresolved invocations from other modules
// and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
let unexpanded_macros = !module.unresolved_invocations.borrow().is_empty();
let unexpanded_macros = !module.unexpanded_invocations.borrow().is_empty();
if let Some(binding) = resolution.binding {
if !unexpanded_macros || ns == MacroNS || restricted_shadowing {
return check_usable(self, binding);

View File

@ -1,4 +1,4 @@
use crate::ast::{self, Attribute, Name, PatKind};
use crate::ast::{self, NodeId, Attribute, Name, PatKind};
use crate::attr::{HasAttrs, Stability, Deprecation};
use crate::source_map::SourceMap;
use crate::edition::Edition;
@ -671,13 +671,13 @@ bitflags::bitflags! {
}
pub trait Resolver {
fn next_node_id(&mut self) -> ast::NodeId;
fn next_node_id(&mut self) -> NodeId;
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId;
fn get_module_scope(&mut self, id: NodeId) -> ExpnId;
fn resolve_dollar_crates(&mut self);
fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment,
derives: &[ExpnId]);
extra_placeholders: &[NodeId]);
fn register_builtin_macro(&mut self, ident: ast::Ident, ext: SyntaxExtension);
fn resolve_imports(&mut self);

View File

@ -291,7 +291,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
// Unresolved macros produce dummy outputs as a recovery measure.
invocations.reverse();
let mut expanded_fragments = Vec::new();
let mut derives: FxHashMap<ExpnId, Vec<_>> = FxHashMap::default();
let mut all_derive_placeholders: FxHashMap<ExpnId, Vec<_>> = FxHashMap::default();
let mut undetermined_invocations = Vec::new();
let (mut progress, mut force) = (false, !self.monotonic);
loop {
@ -347,13 +347,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let mut item = self.fully_configure(item);
item.visit_attrs(|attrs| attrs.retain(|a| a.path != sym::derive));
let derives = derives.entry(invoc.expansion_data.id).or_default();
let derive_placeholders =
all_derive_placeholders.entry(invoc.expansion_data.id).or_default();
derives.reserve(traits.len());
derive_placeholders.reserve(traits.len());
invocations.reserve(traits.len());
for path in traits {
let expn_id = ExpnId::fresh(None);
derives.push(expn_id);
derive_placeholders.push(NodeId::placeholder_from_expn_id(expn_id));
invocations.push(Invocation {
kind: InvocationKind::Derive { path, item: item.clone() },
fragment_kind: invoc.fragment_kind,
@ -365,7 +366,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
let fragment = invoc.fragment_kind
.expect_from_annotatables(::std::iter::once(item));
self.collect_invocations(fragment, derives)
self.collect_invocations(fragment, derive_placeholders)
} else {
unreachable!()
};
@ -384,10 +385,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
// Finally incorporate all the expanded macros into the input AST fragment.
let mut placeholder_expander = PlaceholderExpander::new(self.cx, self.monotonic);
while let Some(expanded_fragments) = expanded_fragments.pop() {
for (mark, expanded_fragment) in expanded_fragments.into_iter().rev() {
let derives = derives.remove(&mark).unwrap_or_else(Vec::new);
placeholder_expander.add(NodeId::placeholder_from_expn_id(mark),
expanded_fragment, derives);
for (expn_id, expanded_fragment) in expanded_fragments.into_iter().rev() {
let derive_placeholders =
all_derive_placeholders.remove(&expn_id).unwrap_or_else(Vec::new);
placeholder_expander.add(NodeId::placeholder_from_expn_id(expn_id),
expanded_fragment, derive_placeholders);
}
}
fragment_with_placeholders.mut_visit_with(&mut placeholder_expander);
@ -404,7 +406,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
/// them with "placeholders" - dummy macro invocations with specially crafted `NodeId`s.
/// Then call into resolver that builds a skeleton ("reduced graph") of the fragment and
/// prepares data for resolving paths of macro invocations.
fn collect_invocations(&mut self, mut fragment: AstFragment, derives: &[ExpnId])
fn collect_invocations(&mut self, mut fragment: AstFragment, extra_placeholders: &[NodeId])
-> (AstFragment, Vec<Invocation>) {
// Resolve `$crate`s in the fragment for pretty-printing.
self.cx.resolver.resolve_dollar_crates();
@ -423,9 +425,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
collector.invocations
};
// FIXME: Merge `extra_placeholders` into the `fragment` as regular placeholders.
if self.monotonic {
self.cx.resolver.visit_ast_fragment_with_placeholders(
self.cx.current_expansion.id, &fragment, derives);
self.cx.current_expansion.id, &fragment, extra_placeholders);
}
(fragment, invocations)

View File

@ -2,7 +2,6 @@ use crate::ast::{self, NodeId};
use crate::source_map::{DUMMY_SP, dummy_spanned};
use crate::ext::base::ExtCtxt;
use crate::ext::expand::{AstFragment, AstFragmentKind};
use crate::ext::hygiene::ExpnId;
use crate::tokenstream::TokenStream;
use crate::mut_visit::*;
use crate::ptr::P;
@ -86,11 +85,11 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
}
}
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, derives: Vec<ExpnId>) {
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, placeholders: Vec<NodeId>) {
fragment.mut_visit_with(self);
if let AstFragment::Items(mut items) = fragment {
for derive in derives {
match self.remove(NodeId::placeholder_from_expn_id(derive)) {
for placeholder in placeholders {
match self.remove(placeholder) {
AstFragment::Items(derived_items) => items.extend(derived_items),
_ => unreachable!(),
}

View File

@ -259,8 +259,6 @@ fn _12() {
}
}
/////////////////
fn foo() { }
fn foo3(_: i32, _: (), _: ()) { }
fn qux(_: i32) { }

View File

@ -12,30 +12,22 @@ pub trait Car : Vehicle {
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

View File

@ -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 @@ LL | fn b() { dent(ModelT, Blue); }
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 @@ LL | fn c() { dent(ModelU, Black); }
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 @@ LL | fn f() { ModelT.chip_paint(Blue); }
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`

View File

@ -11,22 +11,16 @@ pub trait Car : Vehicle {
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) {
}

View File

@ -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 @@ LL | fn b() { blue_car(ModelT); }
= 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 @@ LL | fn c() { black_car(ModelU); }
= 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) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -9,8 +9,6 @@ trait Test {
fn test(&self, value: &Self::V) -> bool;
}
///////////////////////////////////////////////////////////////////////////
struct TesterPair<T:Test> {
tester: T,
value: T::V,
@ -26,8 +24,6 @@ impl<T:Test> TesterPair<T> {
}
}
///////////////////////////////////////////////////////////////////////////
struct EqU32(u32);
impl Test for EqU32 {
type V = u32;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -14,7 +14,6 @@ fn want_foo<T>()
{
}
///////////////////////////////////////////////////////////////////////////
// Expressed as a where clause
struct SomeStruct<X> {
@ -30,7 +29,6 @@ fn one() {
want_foo::<SomeStruct<usize>>();
}
///////////////////////////////////////////////////////////////////////////
// Expressed as shorthand
struct AnotherStruct<X> {

View File

@ -15,7 +15,6 @@ fn want_foo1<T>()
{
}
///////////////////////////////////////////////////////////////////////////
// Expressed as a where clause
struct SomeStruct;

View File

@ -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`

View File

@ -8,7 +8,6 @@
// See issue 60414
/////////////////////////////////////////////
// Reduction to `impl Trait`
struct Foo<T>(T);
@ -33,7 +32,6 @@ mod impl_trait {
}
}
/////////////////////////////////////////////
// Same with lifetimes in the trait
mod lifetimes {

View File

@ -7,7 +7,7 @@ LL | #![feature(impl_trait_in_bindings)]
= 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 @@ LL | fn foo_fail<T: Trait>() -> impl FooLike<Output=T::Assoc> {
= 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

View File

@ -8,7 +8,6 @@
// See issue 60414
/////////////////////////////////////////////
// Reduction to `impl Trait`
struct Foo<T>(T);
@ -32,7 +31,6 @@ mod impl_trait {
}
}
/////////////////////////////////////////////
// Same with lifetimes in the trait
mod lifetimes {
@ -59,7 +57,6 @@ mod lifetimes {
}
}
/////////////////////////////////////////////
// Reduction using `impl Trait` in bindings
mod impl_trait_in_bindings {
@ -80,7 +77,6 @@ mod impl_trait_in_bindings {
}
}
/////////////////////////////////////////////
// The same applied to `type Foo = impl Bar`s
mod opaque_types {

View File

@ -17,8 +17,6 @@ trait StreamHasher {
fn stream(&self) -> Self::S;
}
//////////////////////////////////////////////////////////////////////////////
trait StreamHash<H: StreamHasher>: Hash<H> {
fn input_stream(&self, stream: &mut H::S);
}

View File

@ -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);
| ^^^^^^^^^^^^

View File

@ -16,8 +16,6 @@ impl FnOnce<()> for Foo {
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 @@ impl FnOnce<(u32,)> for Foo {
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 }
}

View File

@ -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 RefPair((&'static i32, i32));
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 generic<T: 'static>() {
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 @@ fn main() {
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();
}
}

View File

@ -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 @@ LL | #![deny(invalid_value)]
= 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 @@ LL | let _val: &'static T = mem::uninitialized();
= 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 @@ LL | let _val: Wrap<&'static T> = mem::zeroed();
| 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 @@ LL | let _val: Wrap<&'static T> = mem::uninitialized();
| 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 @@ LL | let _val: ! = mem::zeroed();
= 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 @@ LL | let _val: ! = mem::uninitialized();
= 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 @@ LL | let _val: (i32, !) = mem::zeroed();
= 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 @@ LL | let _val: (i32, !) = mem::uninitialized();
= 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 @@ LL | let _val: Void = mem::zeroed();
= 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 @@ LL | let _val: Void = mem::uninitialized();
= 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 @@ LL | let _val: &'static i32 = mem::zeroed();
= 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 @@ LL | let _val: &'static i32 = mem::uninitialized();
= 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 @@ LL | let _val: Ref = mem::zeroed();
| 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 @@ LL | let _val: Ref = mem::uninitialized();
| 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 @@ LL | let _val: fn() = mem::zeroed();
= 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 @@ LL | let _val: fn() = mem::uninitialized();
= 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 @@ LL | let _val: Wrap<fn()> = mem::zeroed();
| 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 @@ LL | let _val: Wrap<fn()> = mem::uninitialized();
| 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 @@ LL | let _val: WrapEnum<fn()> = mem::zeroed();
| 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 @@ LL | let _val: WrapEnum<fn()> = mem::uninitialized();
| 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 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
| 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 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
| 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

View File

@ -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 @@ impl MakeString for usize {
}
}
///////////////////////////////////////////////////////////////////////////
trait Foo {
type F: MakeString;
@ -33,8 +28,6 @@ fn foo<F:Foo>(f: &F) -> String {
f.get().make_string()
}
///////////////////////////////////////////////////////////////////////////
struct SomeStruct {
field: isize,
}
@ -47,8 +40,6 @@ impl Foo for SomeStruct {
}
}
///////////////////////////////////////////////////////////////////////////
struct SomeOtherStruct {
field: usize,
}

View File

@ -0,0 +1,12 @@
// force-host
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_derive(repro)]
pub fn proc_macro_hack_expr(_input: TokenStream) -> TokenStream {
"macro_rules! m {()=>{}}".parse().unwrap()
}

View File

@ -0,0 +1,13 @@
// Derive macros can generate `macro_rules` items, regression test for issue #63651.
// check-pass
// aux-build:gen-macro-rules.rs
extern crate gen_macro_rules as repro;
#[derive(repro::repro)]
pub struct S;
m!(); // OK
fn main() {}

View File

@ -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 @@ LL | let _: &'a WithHrAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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

View File

@ -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>() {
| ^^

View File

@ -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 @@ LL | let _: &'a WithHrAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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

View File

@ -6,9 +6,6 @@
#![allow(dead_code)]
///////////////////////////////////////////////////////////////////////////
pub trait TheTrait<'b> {
type TheAssocType;
}
@ -21,8 +18,6 @@ impl<'a,'b> TheTrait<'a> for TheType<'b> {
type TheAssocType = &'b ();
}
///////////////////////////////////////////////////////////////////////////
pub struct WithHrAssoc<T>
where for<'a> T : TheTrait<'a>
{
@ -37,8 +32,6 @@ fn with_assoc<'a,'b>() {
//[nll]~^^ ERROR lifetime may not live long enough
}
///////////////////////////////////////////////////////////////////////////
pub trait TheSubTrait : for<'a> TheTrait<'a> {
}

View File

@ -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

View File

@ -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>() {
| ^^

View File

@ -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

View File

@ -8,8 +8,6 @@
#![allow(dead_code)]
///////////////////////////////////////////////////////////////////////////
pub trait TheTrait {
type TheAssocType;
}
@ -22,8 +20,6 @@ impl<'b> TheTrait for TheType<'b> {
type TheAssocType = &'b ();
}
///////////////////////////////////////////////////////////////////////////
pub struct WithAssoc<T> where T : TheTrait {
m: [T; 0]
}

View File

@ -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 @@ LL | let _x: &'a WithAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ LL | let _x: &'a WithoutAssoc<TheType<'b>> = loop { };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 @@ LL | call::<&'a WithAssoc<TheType<'b>>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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

View File

@ -5,8 +5,6 @@
#![allow(dead_code)]
#![feature(rustc_attrs)]
///////////////////////////////////////////////////////////////////////////
pub trait TheTrait {
type TheAssocType;
}
@ -19,8 +17,6 @@ impl<'b> TheTrait for TheType<'b> {
type TheAssocType = &'b ();
}
///////////////////////////////////////////////////////////////////////////
pub struct WithAssoc<T:TheTrait> {
m: [T; 0]
}

View File

@ -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>() {
| ^^

View File

@ -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 @@ impl Foo for u32 {
fn bar(&self) {} //~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 2: one layer of specialization, missing `default` on associated type
////////////////////////////////////////////////////////////////////////////////
trait Bar {
type T;
@ -41,9 +37,7 @@ impl Bar for u8 {
type T = (); //~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 3a: multiple layers of specialization, missing interior `default`
////////////////////////////////////////////////////////////////////////////////
trait Baz {
fn baz(&self);
@ -61,10 +55,8 @@ impl Baz for i32 {
fn baz(&self) {} //~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 3b: multiple layers of specialization, missing interior `default`,
// redundant `default` in bottom layer.
////////////////////////////////////////////////////////////////////////////////
trait Redundant {
fn redundant(&self);

View File

@ -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 @@ LL | fn foo(&self) {}
= 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 @@ LL | fn bar(&self) {}
= 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 @@ LL | type T = ();
= 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 @@ LL | fn baz(&self) {}
= 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) {}

View File

@ -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 @@ impl Foo for u32 {
fn bar(&self) {} //~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 2: one layer of specialization, missing `default` on associated type
////////////////////////////////////////////////////////////////////////////////
trait Bar {
type T;
@ -41,9 +37,7 @@ impl Bar for u8 {
type T = (); //~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 3a: multiple layers of specialization, missing interior `default`
////////////////////////////////////////////////////////////////////////////////
trait Baz {
fn baz(&self);
@ -61,10 +55,8 @@ impl Baz for i32 {
fn baz(&self) {} //~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 3b: multiple layers of specialization, missing interior `default`,
// redundant `default` in bottom layer.
////////////////////////////////////////////////////////////////////////////////
trait Redundant {
fn redundant(&self);

View File

@ -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 @@ LL | fn foo(&self) {}
= 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 @@ LL | fn bar(&self) {}
= 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 @@ LL | type T = ();
= 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 @@ LL | fn baz(&self) {}
= 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) {}

View File

@ -14,8 +14,6 @@ use go_trait::{Go, GoMut, GoOnce, go, go_mut, go_once};
use std::rc::Rc;
use std::cell::Cell;
///////////////////////////////////////////////////////////////////////////
struct SomeGoableThing {
counter: Rc<Cell<isize>>
}
@ -26,8 +24,6 @@ impl Go for SomeGoableThing {
}
}
///////////////////////////////////////////////////////////////////////////
struct SomeGoOnceableThing {
counter: Rc<Cell<isize>>
}
@ -38,8 +34,6 @@ impl GoOnce for SomeGoOnceableThing {
}
}
///////////////////////////////////////////////////////////////////////////
fn main() {
let counter = Rc::new(Cell::new(0));
let mut x = SomeGoableThing { counter: counter.clone() };