mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Auto merge of #43487 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 10 pull requests - Successful merges: #42959, #43447, #43455, #43456, #43458, #43462, #43463, #43465, #43471, #43480 - Failed merges:
This commit is contained in:
commit
599be0d18f
@ -1 +1 @@
|
||||
Subproject commit 81134a4dff811403b3b2f349b0c59a819f0fe0c1
|
||||
Subproject commit f8fd6710399a1a557155cb5be4922fe6a6f694c0
|
@ -892,7 +892,7 @@ pub unsafe trait Alloc {
|
||||
{
|
||||
let k = Layout::new::<T>();
|
||||
if k.size() > 0 {
|
||||
unsafe { self.alloc(k).map(|p| Unique::new(p as *mut T)) }
|
||||
unsafe { self.alloc(k).map(|p| Unique::new_unchecked(p as *mut T)) }
|
||||
} else {
|
||||
Err(AllocErr::invalid_input("zero-sized type invalid for alloc_one"))
|
||||
}
|
||||
@ -963,7 +963,7 @@ pub unsafe trait Alloc {
|
||||
unsafe {
|
||||
self.alloc(layout.clone())
|
||||
.map(|p| {
|
||||
Unique::new(p as *mut T)
|
||||
Unique::new_unchecked(p as *mut T)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1012,7 +1012,7 @@ pub unsafe trait Alloc {
|
||||
match (Layout::array::<T>(n_old), Layout::array::<T>(n_new), ptr.as_ptr()) {
|
||||
(Some(ref k_old), Some(ref k_new), ptr) if k_old.size() > 0 && k_new.size() > 0 => {
|
||||
self.realloc(ptr as *mut u8, k_old.clone(), k_new.clone())
|
||||
.map(|p|Unique::new(p as *mut T))
|
||||
.map(|p|Unique::new_unchecked(p as *mut T))
|
||||
}
|
||||
_ => {
|
||||
Err(AllocErr::invalid_input("invalid layout for realloc_array"))
|
||||
|
@ -280,7 +280,7 @@ impl<T> Arc<T> {
|
||||
weak: atomic::AtomicUsize::new(1),
|
||||
data: data,
|
||||
};
|
||||
Arc { ptr: unsafe { Shared::new(Box::into_raw(x)) } }
|
||||
Arc { ptr: Shared::from(Box::into_unique(x)) }
|
||||
}
|
||||
|
||||
/// Returns the contained value, if the `Arc` has exactly one strong reference.
|
||||
@ -382,7 +382,7 @@ impl<T> Arc<T> {
|
||||
// `data` field from the pointer.
|
||||
let ptr = (ptr as *const u8).offset(-offset_of!(ArcInner<T>, data));
|
||||
Arc {
|
||||
ptr: Shared::new(ptr as *mut u8 as *mut _),
|
||||
ptr: Shared::new_unchecked(ptr as *mut u8 as *mut _),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -842,7 +842,7 @@ impl<T> Weak<T> {
|
||||
pub fn new() -> Weak<T> {
|
||||
unsafe {
|
||||
Weak {
|
||||
ptr: Shared::new(Box::into_raw(box ArcInner {
|
||||
ptr: Shared::from(Box::into_unique(box ArcInner {
|
||||
strong: atomic::AtomicUsize::new(0),
|
||||
weak: atomic::AtomicUsize::new(1),
|
||||
data: uninitialized(),
|
||||
|
@ -297,6 +297,37 @@ impl<T: ?Sized> Box<T> {
|
||||
pub fn into_raw(b: Box<T>) -> *mut T {
|
||||
unsafe { mem::transmute(b) }
|
||||
}
|
||||
|
||||
/// Consumes the `Box`, returning the wrapped pointer as `Unique<T>`.
|
||||
///
|
||||
/// After calling this function, the caller is responsible for the
|
||||
/// memory previously managed by the `Box`. In particular, the
|
||||
/// caller should properly destroy `T` and release the memory. The
|
||||
/// proper way to do so is to convert the raw pointer back into a
|
||||
/// `Box` with the [`Box::from_raw`] function.
|
||||
///
|
||||
/// Note: this is an associated function, which means that you have
|
||||
/// to call it as `Box::into_unique(b)` instead of `b.into_unique()`. This
|
||||
/// is so that there is no conflict with a method on the inner type.
|
||||
///
|
||||
/// [`Box::from_raw`]: struct.Box.html#method.from_raw
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(unique)]
|
||||
///
|
||||
/// fn main() {
|
||||
/// let x = Box::new(5);
|
||||
/// let ptr = Box::into_unique(x);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "unique", reason = "needs an RFC to flesh out design",
|
||||
issue = "27730")]
|
||||
#[inline]
|
||||
pub fn into_unique(b: Box<T>) -> Unique<T> {
|
||||
unsafe { mem::transmute(b) }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -140,24 +140,22 @@ struct BoxedNode<K, V> {
|
||||
|
||||
impl<K, V> BoxedNode<K, V> {
|
||||
fn from_leaf(node: Box<LeafNode<K, V>>) -> Self {
|
||||
unsafe {
|
||||
BoxedNode { ptr: Unique::new(Box::into_raw(node)) }
|
||||
}
|
||||
BoxedNode { ptr: Box::into_unique(node) }
|
||||
}
|
||||
|
||||
fn from_internal(node: Box<InternalNode<K, V>>) -> Self {
|
||||
unsafe {
|
||||
BoxedNode { ptr: Unique::new(Box::into_raw(node) as *mut LeafNode<K, V>) }
|
||||
BoxedNode { ptr: Unique::new_unchecked(Box::into_raw(node) as *mut LeafNode<K, V>) }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn from_ptr(ptr: NonZero<*const LeafNode<K, V>>) -> Self {
|
||||
BoxedNode { ptr: Unique::new(ptr.get() as *mut LeafNode<K, V>) }
|
||||
BoxedNode { ptr: Unique::new_unchecked(ptr.get() as *mut LeafNode<K, V>) }
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> NonZero<*const LeafNode<K, V>> {
|
||||
unsafe {
|
||||
NonZero::new(self.ptr.as_ptr())
|
||||
NonZero::from(self.ptr.as_ref())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -384,21 +382,19 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
|
||||
>,
|
||||
Self
|
||||
> {
|
||||
if self.as_leaf().parent.is_null() {
|
||||
Err(self)
|
||||
} else {
|
||||
if let Some(non_zero) = NonZero::new(self.as_leaf().parent as *const LeafNode<K, V>) {
|
||||
Ok(Handle {
|
||||
node: NodeRef {
|
||||
height: self.height + 1,
|
||||
node: unsafe {
|
||||
NonZero::new(self.as_leaf().parent as *mut LeafNode<K, V>)
|
||||
},
|
||||
node: non_zero,
|
||||
root: self.root,
|
||||
_marker: PhantomData
|
||||
},
|
||||
idx: self.as_leaf().parent_idx as usize,
|
||||
_marker: PhantomData
|
||||
})
|
||||
} else {
|
||||
Err(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ impl<T> LinkedList<T> {
|
||||
unsafe {
|
||||
node.next = self.head;
|
||||
node.prev = None;
|
||||
let node = Some(Shared::new(Box::into_raw(node)));
|
||||
let node = Some(Shared::from(Box::into_unique(node)));
|
||||
|
||||
match self.head {
|
||||
None => self.tail = node,
|
||||
@ -192,7 +192,7 @@ impl<T> LinkedList<T> {
|
||||
unsafe {
|
||||
node.next = None;
|
||||
node.prev = self.tail;
|
||||
let node = Some(Shared::new(Box::into_raw(node)));
|
||||
let node = Some(Shared::from(Box::into_unique(node)));
|
||||
|
||||
match self.tail {
|
||||
None => self.head = node,
|
||||
@ -921,7 +921,7 @@ impl<'a, T> IterMut<'a, T> {
|
||||
Some(prev) => prev,
|
||||
};
|
||||
|
||||
let node = Some(Shared::new(Box::into_raw(box Node {
|
||||
let node = Some(Shared::from(Box::into_unique(box Node {
|
||||
next: Some(head),
|
||||
prev: Some(prev),
|
||||
element: element,
|
||||
|
@ -104,7 +104,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||
};
|
||||
|
||||
RawVec {
|
||||
ptr: Unique::new(ptr as *mut _),
|
||||
ptr: Unique::new_unchecked(ptr as *mut _),
|
||||
cap: cap,
|
||||
a: a,
|
||||
}
|
||||
@ -159,7 +159,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||
/// If the ptr and capacity come from a RawVec created via `a`, then this is guaranteed.
|
||||
pub unsafe fn from_raw_parts_in(ptr: *mut T, cap: usize, a: A) -> Self {
|
||||
RawVec {
|
||||
ptr: Unique::new(ptr),
|
||||
ptr: Unique::new_unchecked(ptr),
|
||||
cap: cap,
|
||||
a: a,
|
||||
}
|
||||
@ -176,7 +176,7 @@ impl<T> RawVec<T, Heap> {
|
||||
/// If the ptr and capacity come from a RawVec, then this is guaranteed.
|
||||
pub unsafe fn from_raw_parts(ptr: *mut T, cap: usize) -> Self {
|
||||
RawVec {
|
||||
ptr: Unique::new(ptr),
|
||||
ptr: Unique::new_unchecked(ptr),
|
||||
cap: cap,
|
||||
a: Heap,
|
||||
}
|
||||
|
@ -303,18 +303,16 @@ impl<T> Rc<T> {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn new(value: T) -> Rc<T> {
|
||||
unsafe {
|
||||
Rc {
|
||||
// there is an implicit weak pointer owned by all the strong
|
||||
// pointers, which ensures that the weak destructor never frees
|
||||
// the allocation while the strong destructor is running, even
|
||||
// if the weak pointer is stored inside the strong one.
|
||||
ptr: Shared::new(Box::into_raw(box RcBox {
|
||||
strong: Cell::new(1),
|
||||
weak: Cell::new(1),
|
||||
value: value,
|
||||
})),
|
||||
}
|
||||
Rc {
|
||||
// there is an implicit weak pointer owned by all the strong
|
||||
// pointers, which ensures that the weak destructor never frees
|
||||
// the allocation while the strong destructor is running, even
|
||||
// if the weak pointer is stored inside the strong one.
|
||||
ptr: Shared::from(Box::into_unique(box RcBox {
|
||||
strong: Cell::new(1),
|
||||
weak: Cell::new(1),
|
||||
value: value,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,7 +416,7 @@ impl<T> Rc<T> {
|
||||
|
||||
let ptr = (ptr as *const u8).offset(-offset_of!(RcBox<T>, value));
|
||||
Rc {
|
||||
ptr: Shared::new(ptr as *mut u8 as *mut _)
|
||||
ptr: Shared::new_unchecked(ptr as *mut u8 as *mut _)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -443,7 +441,7 @@ impl Rc<str> {
|
||||
// Combine the allocation address and the string length into a fat pointer to `RcBox`.
|
||||
let rcbox_ptr: *mut RcBox<str> = mem::transmute([ptr as usize, value.len()]);
|
||||
assert!(aligned_len * size_of::<usize>() == size_of_val(&*rcbox_ptr));
|
||||
Rc { ptr: Shared::new(rcbox_ptr) }
|
||||
Rc { ptr: Shared::new_unchecked(rcbox_ptr) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -476,7 +474,7 @@ impl<T> Rc<[T]> {
|
||||
// Free the original allocation without freeing its (moved) contents.
|
||||
box_free(Box::into_raw(value));
|
||||
|
||||
Rc { ptr: Shared::new(ptr as *mut _) }
|
||||
Rc { ptr: Shared::new_unchecked(ptr as *mut _) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1016,7 +1014,7 @@ impl<T> Weak<T> {
|
||||
pub fn new() -> Weak<T> {
|
||||
unsafe {
|
||||
Weak {
|
||||
ptr: Shared::new(Box::into_raw(box RcBox {
|
||||
ptr: Shared::from(Box::into_unique(box RcBox {
|
||||
strong: Cell::new(0),
|
||||
weak: Cell::new(1),
|
||||
value: uninitialized(),
|
||||
|
@ -1126,7 +1126,7 @@ impl<T> Vec<T> {
|
||||
tail_start: end,
|
||||
tail_len: len - end,
|
||||
iter: range_slice.iter(),
|
||||
vec: Shared::new(self as *mut _),
|
||||
vec: Shared::from(self),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1727,7 +1727,7 @@ impl<T> IntoIterator for Vec<T> {
|
||||
let cap = self.buf.cap();
|
||||
mem::forget(self);
|
||||
IntoIter {
|
||||
buf: Shared::new(begin),
|
||||
buf: Shared::new_unchecked(begin),
|
||||
cap: cap,
|
||||
ptr: begin,
|
||||
end: end,
|
||||
@ -1962,6 +1962,12 @@ impl<T> Vec<T> {
|
||||
|
||||
}
|
||||
|
||||
/// Extend implementation that copies elements out of references before pushing them onto the Vec.
|
||||
///
|
||||
/// This implementation is specialized for slice iterators, where it uses [`copy_from_slice`] to
|
||||
/// append the entire slice at once.
|
||||
///
|
||||
/// [`copy_from_slice`]: ../../std/primitive.slice.html#method.copy_from_slice
|
||||
#[stable(feature = "extend_ref", since = "1.2.0")]
|
||||
impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
|
||||
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
|
||||
|
@ -893,7 +893,7 @@ impl<T> VecDeque<T> {
|
||||
self.head = drain_tail;
|
||||
|
||||
Drain {
|
||||
deque: unsafe { Shared::new(self as *mut _) },
|
||||
deque: Shared::from(&mut *self),
|
||||
after_tail: drain_head,
|
||||
after_head: head,
|
||||
iter: Iter {
|
||||
|
@ -16,22 +16,48 @@
|
||||
use ops::CoerceUnsized;
|
||||
|
||||
/// Unsafe trait to indicate what types are usable with the NonZero struct
|
||||
pub unsafe trait Zeroable {}
|
||||
pub unsafe trait Zeroable {
|
||||
/// Whether this value is zero
|
||||
fn is_zero(&self) -> bool;
|
||||
}
|
||||
|
||||
unsafe impl<T:?Sized> Zeroable for *const T {}
|
||||
unsafe impl<T:?Sized> Zeroable for *mut T {}
|
||||
unsafe impl Zeroable for isize {}
|
||||
unsafe impl Zeroable for usize {}
|
||||
unsafe impl Zeroable for i8 {}
|
||||
unsafe impl Zeroable for u8 {}
|
||||
unsafe impl Zeroable for i16 {}
|
||||
unsafe impl Zeroable for u16 {}
|
||||
unsafe impl Zeroable for i32 {}
|
||||
unsafe impl Zeroable for u32 {}
|
||||
unsafe impl Zeroable for i64 {}
|
||||
unsafe impl Zeroable for u64 {}
|
||||
unsafe impl Zeroable for i128 {}
|
||||
unsafe impl Zeroable for u128 {}
|
||||
macro_rules! impl_zeroable_for_pointer_types {
|
||||
( $( $Ptr: ty )+ ) => {
|
||||
$(
|
||||
/// For fat pointers to be considered "zero", only the "data" part needs to be null.
|
||||
unsafe impl<T: ?Sized> Zeroable for $Ptr {
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
// Cast because `is_null` is only available on thin pointers
|
||||
(*self as *mut u8).is_null()
|
||||
}
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_zeroable_for_integer_types {
|
||||
( $( $Int: ty )+ ) => {
|
||||
$(
|
||||
unsafe impl Zeroable for $Int {
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
*self == 0
|
||||
}
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
impl_zeroable_for_pointer_types! {
|
||||
*const T
|
||||
*mut T
|
||||
}
|
||||
|
||||
impl_zeroable_for_integer_types! {
|
||||
usize u8 u16 u32 u64 u128
|
||||
isize i8 i16 i32 i64 i128
|
||||
}
|
||||
|
||||
/// A wrapper type for raw pointers and integers that will never be
|
||||
/// NULL or 0 that might allow certain optimizations.
|
||||
@ -43,10 +69,20 @@ impl<T: Zeroable> NonZero<T> {
|
||||
/// Creates an instance of NonZero with the provided value.
|
||||
/// You must indeed ensure that the value is actually "non-zero".
|
||||
#[inline]
|
||||
pub const unsafe fn new(inner: T) -> NonZero<T> {
|
||||
pub const unsafe fn new_unchecked(inner: T) -> Self {
|
||||
NonZero(inner)
|
||||
}
|
||||
|
||||
/// Creates an instance of NonZero with the provided value.
|
||||
#[inline]
|
||||
pub fn new(inner: T) -> Option<Self> {
|
||||
if inner.is_zero() {
|
||||
None
|
||||
} else {
|
||||
Some(NonZero(inner))
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the inner value.
|
||||
pub fn get(self) -> T {
|
||||
self.0
|
||||
@ -54,3 +90,22 @@ impl<T: Zeroable> NonZero<T> {
|
||||
}
|
||||
|
||||
impl<T: Zeroable+CoerceUnsized<U>, U: Zeroable> CoerceUnsized<NonZero<U>> for NonZero<T> {}
|
||||
|
||||
impl<'a, T: ?Sized> From<&'a mut T> for NonZero<*mut T> {
|
||||
fn from(reference: &'a mut T) -> Self {
|
||||
NonZero(reference)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized> From<&'a mut T> for NonZero<*const T> {
|
||||
fn from(reference: &'a mut T) -> Self {
|
||||
let ptr: *mut T = reference;
|
||||
NonZero(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized> From<&'a T> for NonZero<*const T> {
|
||||
fn from(reference: &'a T) -> Self {
|
||||
NonZero(reference)
|
||||
}
|
||||
}
|
||||
|
@ -2622,8 +2622,11 @@ try_from_both_bounded!(i32, u16, u8);
|
||||
try_from_both_bounded!(i64, u32, u16, u8);
|
||||
try_from_both_bounded!(i128, u64, u32, u16, u8);
|
||||
|
||||
#[unstable(feature = "try_from", issue = "33417")]
|
||||
pub use self::ptr_try_from_impls::*;
|
||||
// usize/isize
|
||||
try_from_unbounded!(usize, usize);
|
||||
try_from_upper_bounded!(usize, isize);
|
||||
try_from_lower_bounded!(isize, usize);
|
||||
try_from_unbounded!(isize, isize);
|
||||
|
||||
#[cfg(target_pointer_width = "16")]
|
||||
mod ptr_try_from_impls {
|
||||
@ -2631,12 +2634,12 @@ mod ptr_try_from_impls {
|
||||
use convert::TryFrom;
|
||||
|
||||
try_from_upper_bounded!(usize, u8);
|
||||
try_from_unbounded!(usize, usize, u16, u32, u64, u128);
|
||||
try_from_upper_bounded!(usize, i8, i16, isize);
|
||||
try_from_unbounded!(usize, u16, u32, u64, u128);
|
||||
try_from_upper_bounded!(usize, i8, i16);
|
||||
try_from_unbounded!(usize, i32, i64, i128);
|
||||
|
||||
try_from_both_bounded!(isize, u8);
|
||||
try_from_lower_bounded!(isize, usize, u16, u32, u64, u128);
|
||||
try_from_lower_bounded!(isize, u16, u32, u64, u128);
|
||||
try_from_both_bounded!(isize, i8);
|
||||
try_from_unbounded!(isize, i16, i32, i64, i128);
|
||||
|
||||
@ -2657,12 +2660,12 @@ mod ptr_try_from_impls {
|
||||
use convert::TryFrom;
|
||||
|
||||
try_from_upper_bounded!(usize, u8, u16);
|
||||
try_from_unbounded!(usize, usize, u32, u64, u128);
|
||||
try_from_upper_bounded!(usize, i8, i16, i32, isize);
|
||||
try_from_unbounded!(usize, u32, u64, u128);
|
||||
try_from_upper_bounded!(usize, i8, i16, i32);
|
||||
try_from_unbounded!(usize, i64, i128);
|
||||
|
||||
try_from_both_bounded!(isize, u8, u16);
|
||||
try_from_lower_bounded!(isize, usize, u32, u64, u128);
|
||||
try_from_lower_bounded!(isize, u32, u64, u128);
|
||||
try_from_both_bounded!(isize, i8, i16);
|
||||
try_from_unbounded!(isize, i32, i64, i128);
|
||||
|
||||
@ -2683,12 +2686,12 @@ mod ptr_try_from_impls {
|
||||
use convert::TryFrom;
|
||||
|
||||
try_from_upper_bounded!(usize, u8, u16, u32);
|
||||
try_from_unbounded!(usize, usize, u64, u128);
|
||||
try_from_upper_bounded!(usize, i8, i16, i32, i64, isize);
|
||||
try_from_unbounded!(usize, u64, u128);
|
||||
try_from_upper_bounded!(usize, i8, i16, i32, i64);
|
||||
try_from_unbounded!(usize, i128);
|
||||
|
||||
try_from_both_bounded!(isize, u8, u16, u32);
|
||||
try_from_lower_bounded!(isize, usize, u64, u128);
|
||||
try_from_lower_bounded!(isize, u64, u128);
|
||||
try_from_both_bounded!(isize, i8, i16, i32);
|
||||
try_from_unbounded!(isize, i64, i128);
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use convert::From;
|
||||
use intrinsics;
|
||||
use ops::CoerceUnsized;
|
||||
use fmt;
|
||||
@ -1098,7 +1099,7 @@ impl<T: Sized> Unique<T> {
|
||||
pub fn empty() -> Self {
|
||||
unsafe {
|
||||
let ptr = mem::align_of::<T>() as *mut T;
|
||||
Unique::new(ptr)
|
||||
Unique::new_unchecked(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1110,8 +1111,13 @@ impl<T: ?Sized> Unique<T> {
|
||||
/// # Safety
|
||||
///
|
||||
/// `ptr` must be non-null.
|
||||
pub const unsafe fn new(ptr: *mut T) -> Unique<T> {
|
||||
Unique { pointer: NonZero::new(ptr), _marker: PhantomData }
|
||||
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
|
||||
Unique { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData }
|
||||
}
|
||||
|
||||
/// Creates a new `Unique` if `ptr` is non-null.
|
||||
pub fn new(ptr: *mut T) -> Option<Self> {
|
||||
NonZero::new(ptr as *const T).map(|nz| Unique { pointer: nz, _marker: PhantomData })
|
||||
}
|
||||
|
||||
/// Acquires the underlying `*mut` pointer.
|
||||
@ -1138,14 +1144,14 @@ impl<T: ?Sized> Unique<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "shared", issue = "27730")]
|
||||
#[unstable(feature = "unique", issue = "27730")]
|
||||
impl<T: ?Sized> Clone for Unique<T> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "shared", issue = "27730")]
|
||||
#[unstable(feature = "unique", issue = "27730")]
|
||||
impl<T: ?Sized> Copy for Unique<T> { }
|
||||
|
||||
#[unstable(feature = "unique", issue = "27730")]
|
||||
@ -1158,6 +1164,20 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "unique", issue = "27730")]
|
||||
impl<'a, T: ?Sized> From<&'a mut T> for Unique<T> {
|
||||
fn from(reference: &'a mut T) -> Self {
|
||||
Unique { pointer: NonZero::from(reference), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "unique", issue = "27730")]
|
||||
impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
|
||||
fn from(reference: &'a T) -> Self {
|
||||
Unique { pointer: NonZero::from(reference), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper around a raw `*mut T` that indicates that the possessor
|
||||
/// of this wrapper has shared ownership of the referent. Useful for
|
||||
/// building abstractions like `Rc<T>`, `Arc<T>`, or doubly-linked lists, which
|
||||
@ -1212,7 +1232,7 @@ impl<T: Sized> Shared<T> {
|
||||
pub fn empty() -> Self {
|
||||
unsafe {
|
||||
let ptr = mem::align_of::<T>() as *mut T;
|
||||
Shared::new(ptr)
|
||||
Shared::new_unchecked(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1224,8 +1244,13 @@ impl<T: ?Sized> Shared<T> {
|
||||
/// # Safety
|
||||
///
|
||||
/// `ptr` must be non-null.
|
||||
pub unsafe fn new(ptr: *mut T) -> Self {
|
||||
Shared { pointer: NonZero::new(ptr), _marker: PhantomData }
|
||||
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
|
||||
Shared { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData }
|
||||
}
|
||||
|
||||
/// Creates a new `Shared` if `ptr` is non-null.
|
||||
pub fn new(ptr: *mut T) -> Option<Self> {
|
||||
NonZero::new(ptr as *const T).map(|nz| Shared { pointer: nz, _marker: PhantomData })
|
||||
}
|
||||
|
||||
/// Acquires the underlying `*mut` pointer.
|
||||
@ -1278,3 +1303,24 @@ impl<T: ?Sized> fmt::Pointer for Shared<T> {
|
||||
fmt::Pointer::fmt(&self.as_ptr(), f)
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "shared", issue = "27730")]
|
||||
impl<T: ?Sized> From<Unique<T>> for Shared<T> {
|
||||
fn from(unique: Unique<T>) -> Self {
|
||||
Shared { pointer: unique.pointer, _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "shared", issue = "27730")]
|
||||
impl<'a, T: ?Sized> From<&'a mut T> for Shared<T> {
|
||||
fn from(reference: &'a mut T) -> Self {
|
||||
Shared { pointer: NonZero::from(reference), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "shared", issue = "27730")]
|
||||
impl<'a, T: ?Sized> From<&'a T> for Shared<T> {
|
||||
fn from(reference: &'a T) -> Self {
|
||||
Shared { pointer: NonZero::from(reference), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ use std::mem::size_of;
|
||||
#[test]
|
||||
fn test_create_nonzero_instance() {
|
||||
let _a = unsafe {
|
||||
NonZero::new(21)
|
||||
NonZero::new_unchecked(21)
|
||||
};
|
||||
}
|
||||
|
||||
@ -28,14 +28,14 @@ fn test_size_nonzero_in_option() {
|
||||
#[test]
|
||||
fn test_match_on_nonzero_option() {
|
||||
let a = Some(unsafe {
|
||||
NonZero::new(42)
|
||||
NonZero::new_unchecked(42)
|
||||
});
|
||||
match a {
|
||||
Some(val) => assert_eq!(val.get(), 42),
|
||||
None => panic!("unexpected None while matching on Some(NonZero(_))")
|
||||
}
|
||||
|
||||
match unsafe { Some(NonZero::new(43)) } {
|
||||
match unsafe { Some(NonZero::new_unchecked(43)) } {
|
||||
Some(val) => assert_eq!(val.get(), 43),
|
||||
None => panic!("unexpected None while matching on Some(NonZero(_))")
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ test_impl_try_from_always_ok! { test_try_u64u64, u64, u64 }
|
||||
test_impl_try_from_always_ok! { test_try_u64u128, u64, u128 }
|
||||
test_impl_try_from_always_ok! { test_try_u64i128, u64, i128 }
|
||||
|
||||
test_impl_try_from_always_ok! { test_try_u128, u128, u128 }
|
||||
test_impl_try_from_always_ok! { test_try_u128u128, u128, u128 }
|
||||
|
||||
test_impl_try_from_always_ok! { test_try_i8i8, i8, i8 }
|
||||
test_impl_try_from_always_ok! { test_try_i8i16, i8, i16 }
|
||||
@ -301,8 +301,12 @@ test_impl_try_from_always_ok! { test_try_i64i128, i64, i128 }
|
||||
|
||||
test_impl_try_from_always_ok! { test_try_i128i128, i128, i128 }
|
||||
|
||||
test_impl_try_from_always_ok! { test_try_usizeusize, usize, usize }
|
||||
test_impl_try_from_always_ok! { test_try_isizeisize, isize, isize }
|
||||
|
||||
assume_usize_width! {
|
||||
test_impl_try_from_always_ok! { test_try_u8usize, u8, usize }
|
||||
test_impl_try_from_always_ok! { test_try_u8isize, u8, isize }
|
||||
test_impl_try_from_always_ok! { test_try_i8isize, i8, isize }
|
||||
|
||||
test_impl_try_from_always_ok! { test_try_u16usize, u16, usize }
|
||||
@ -317,19 +321,27 @@ assume_usize_width! {
|
||||
|
||||
cfg_block!(
|
||||
#[cfg(target_pointer_width = "16")] {
|
||||
test_impl_try_from_always_ok! { test_try_u16usize, u16, usize }
|
||||
test_impl_try_from_always_ok! { test_try_i16isize, i16, isize }
|
||||
test_impl_try_from_always_ok! { test_try_usizeu16, usize, u16 }
|
||||
test_impl_try_from_always_ok! { test_try_isizei16, isize, i16 }
|
||||
test_impl_try_from_always_ok! { test_try_usizeu32, usize, u32 }
|
||||
test_impl_try_from_always_ok! { test_try_usizei32, usize, i32 }
|
||||
test_impl_try_from_always_ok! { test_try_isizei32, isize, i32 }
|
||||
test_impl_try_from_always_ok! { test_try_usizei64, usize, i64 }
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")] {
|
||||
test_impl_try_from_always_ok! { test_try_u16isize, u16, isize }
|
||||
test_impl_try_from_always_ok! { test_try_usizeu32, usize, u32 }
|
||||
test_impl_try_from_always_ok! { test_try_isizei32, isize, i32 }
|
||||
test_impl_try_from_always_ok! { test_try_u32usize, u32, usize }
|
||||
test_impl_try_from_always_ok! { test_try_i32isize, i32, isize }
|
||||
test_impl_try_from_always_ok! { test_try_usizei64, usize, i64 }
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")] {
|
||||
test_impl_try_from_always_ok! { test_try_u16isize, u16, isize }
|
||||
test_impl_try_from_always_ok! { test_try_u32usize, u32, usize }
|
||||
test_impl_try_from_always_ok! { test_try_u32isize, u32, isize }
|
||||
test_impl_try_from_always_ok! { test_try_i32isize, i32, isize }
|
||||
test_impl_try_from_always_ok! { test_try_u64usize, u64, usize }
|
||||
test_impl_try_from_always_ok! { test_try_i64isize, i64, isize }
|
||||
@ -451,8 +463,8 @@ assume_usize_width! {
|
||||
|
||||
cfg_block!(
|
||||
#[cfg(target_pointer_width = "16")] {
|
||||
test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u16isize, u16, isize }
|
||||
test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u32isize, u32, isize }
|
||||
test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u32isize, u64, isize }
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")] {
|
||||
|
@ -167,7 +167,7 @@ fn test_set_memory() {
|
||||
#[test]
|
||||
fn test_unsized_unique() {
|
||||
let xs: &[i32] = &[1, 2, 3];
|
||||
let ptr = unsafe { Unique::new(xs as *const [i32] as *mut [i32]) };
|
||||
let ptr = unsafe { Unique::new_unchecked(xs as *const [i32] as *mut [i32]) };
|
||||
let ys = unsafe { ptr.as_ref() };
|
||||
let zs: &[i32] = &[1, 2, 3];
|
||||
assert!(ys == zs);
|
||||
|
@ -1208,13 +1208,13 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
||||
BorrowKind::Mut | BorrowKind::Unique => "mut ",
|
||||
};
|
||||
|
||||
// When identifying regions, add trailing space if
|
||||
// necessary.
|
||||
let region = if ppaux::identify_regions() {
|
||||
// When printing regions, add trailing space if necessary.
|
||||
let region = if ppaux::verbose() || ppaux::identify_regions() {
|
||||
let mut region = format!("{}", region);
|
||||
if region.len() > 0 { region.push(' '); }
|
||||
region
|
||||
} else {
|
||||
// Do not even print 'static
|
||||
"".to_owned()
|
||||
};
|
||||
write!(fmt, "&{}{}{:?}", region, kind_str, lv)
|
||||
|
@ -47,7 +47,7 @@ impl<'tcx> From<Ty<'tcx>> for Kind<'tcx> {
|
||||
let ptr = ty as *const _ as usize;
|
||||
Kind {
|
||||
ptr: unsafe {
|
||||
NonZero::new(ptr | TYPE_TAG)
|
||||
NonZero::new_unchecked(ptr | TYPE_TAG)
|
||||
},
|
||||
marker: PhantomData
|
||||
}
|
||||
@ -62,7 +62,7 @@ impl<'tcx> From<ty::Region<'tcx>> for Kind<'tcx> {
|
||||
let ptr = r as *const _ as usize;
|
||||
Kind {
|
||||
ptr: unsafe {
|
||||
NonZero::new(ptr | REGION_TAG)
|
||||
NonZero::new_unchecked(ptr | REGION_TAG)
|
||||
},
|
||||
marker: PhantomData
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ impl<A: Array> ArrayVec<A> {
|
||||
tail_start: end,
|
||||
tail_len: len - end,
|
||||
iter: range_slice.iter(),
|
||||
array_vec: Shared::new(self as *mut _),
|
||||
array_vec: Shared::from(self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Blake2bCtx {
|
||||
b: [u8; 128],
|
||||
h: [u64; 8],
|
||||
|
@ -19,7 +19,7 @@ pub struct NodeIndex {
|
||||
impl NodeIndex {
|
||||
pub fn new(value: usize) -> NodeIndex {
|
||||
assert!(value < (u32::MAX as usize));
|
||||
unsafe { NodeIndex { index: NonZero::new((value as u32) + 1) } }
|
||||
NodeIndex { index: NonZero::new((value as u32) + 1).unwrap() }
|
||||
}
|
||||
|
||||
pub fn get(self) -> usize {
|
||||
|
@ -42,7 +42,7 @@ pub(crate) mod indexes {
|
||||
|
||||
impl Idx for $Index {
|
||||
fn new(idx: usize) -> Self {
|
||||
unsafe { $Index(NonZero::new(idx + 1)) }
|
||||
$Index(NonZero::new(idx + 1).unwrap())
|
||||
}
|
||||
fn index(self) -> usize {
|
||||
self.0.get() - 1
|
||||
|
@ -35,6 +35,7 @@ use syntax::attr;
|
||||
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind};
|
||||
use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind};
|
||||
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use syntax::codemap::respan;
|
||||
use syntax::ext::base::SyntaxExtension;
|
||||
use syntax::ext::base::Determinacy::Undetermined;
|
||||
use syntax::ext::hygiene::Mark;
|
||||
@ -119,7 +120,7 @@ impl<'a> Resolver<'a> {
|
||||
.unwrap()
|
||||
.1
|
||||
.iter()
|
||||
.map(|seg| seg.identifier)
|
||||
.map(|seg| respan(seg.span, seg.identifier))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -127,14 +128,16 @@ impl<'a> Resolver<'a> {
|
||||
ViewPathList(ref module_ident_path, _) => {
|
||||
module_ident_path.segments
|
||||
.iter()
|
||||
.map(|seg| seg.identifier)
|
||||
.map(|seg| respan(seg.span, seg.identifier))
|
||||
.collect()
|
||||
}
|
||||
};
|
||||
|
||||
// This can be removed once warning cycle #36888 is complete.
|
||||
if module_path.len() >= 2 && module_path[0].name == keywords::CrateRoot.name() &&
|
||||
token::Ident(module_path[1]).is_path_segment_keyword() {
|
||||
if module_path.len() >= 2 &&
|
||||
module_path[0].node.name == keywords::CrateRoot.name() &&
|
||||
token::Ident(module_path[1].node).is_path_segment_keyword()
|
||||
{
|
||||
module_path.remove(0);
|
||||
}
|
||||
|
||||
@ -202,10 +205,13 @@ impl<'a> Resolver<'a> {
|
||||
let (module_path, ident, rename, type_ns_only) = {
|
||||
if node.name.name != keywords::SelfValue.name() {
|
||||
let rename = node.rename.unwrap_or(node.name);
|
||||
(module_path.clone(), node.name, rename, false)
|
||||
(module_path.clone(),
|
||||
respan(source_item.span, node.name),
|
||||
rename,
|
||||
false)
|
||||
} else {
|
||||
let ident = *module_path.last().unwrap();
|
||||
if ident.name == keywords::CrateRoot.name() {
|
||||
if ident.node.name == keywords::CrateRoot.name() {
|
||||
resolve_error(
|
||||
self,
|
||||
source_item.span,
|
||||
@ -215,13 +221,13 @@ impl<'a> Resolver<'a> {
|
||||
continue;
|
||||
}
|
||||
let module_path = module_path.split_last().unwrap().1;
|
||||
let rename = node.rename.unwrap_or(ident);
|
||||
let rename = node.rename.unwrap_or(ident.node);
|
||||
(module_path.to_vec(), ident, rename, true)
|
||||
}
|
||||
};
|
||||
let subclass = SingleImport {
|
||||
target: rename,
|
||||
source: ident,
|
||||
source: ident.node,
|
||||
result: self.per_ns(|_, _| Cell::new(Err(Undetermined))),
|
||||
type_ns_only: type_ns_only,
|
||||
};
|
||||
|
@ -43,6 +43,7 @@ use rustc::ty;
|
||||
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
|
||||
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
|
||||
|
||||
use syntax::codemap::{dummy_spanned, respan};
|
||||
use syntax::ext::hygiene::{Mark, SyntaxContext};
|
||||
use syntax::ast::{self, Name, NodeId, Ident, SpannedIdent, FloatTy, IntTy, UintTy};
|
||||
use syntax::ext::base::SyntaxExtension;
|
||||
@ -147,7 +148,7 @@ enum ResolutionError<'a> {
|
||||
/// error E0431: `self` import can only appear in an import list with a non-empty prefix
|
||||
SelfImportOnlyInImportListWithNonEmptyPrefix,
|
||||
/// error E0432: unresolved import
|
||||
UnresolvedImport(Option<(&'a str, &'a str)>),
|
||||
UnresolvedImport(Option<(Span, &'a str, &'a str)>),
|
||||
/// error E0433: failed to resolve
|
||||
FailedToResolve(&'a str),
|
||||
/// error E0434: can't capture dynamic environment in a fn item
|
||||
@ -295,12 +296,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
|
||||
non-empty prefix")
|
||||
}
|
||||
ResolutionError::UnresolvedImport(name) => {
|
||||
let msg = match name {
|
||||
Some((n, _)) => format!("unresolved import `{}`", n),
|
||||
None => "unresolved import".to_owned(),
|
||||
let (span, msg) = match name {
|
||||
Some((sp, n, _)) => (sp, format!("unresolved import `{}`", n)),
|
||||
None => (span, "unresolved import".to_owned()),
|
||||
};
|
||||
let mut err = struct_span_err!(resolver.session, span, E0432, "{}", msg);
|
||||
if let Some((_, p)) = name {
|
||||
if let Some((_, _, p)) = name {
|
||||
err.span_label(span, p);
|
||||
}
|
||||
err
|
||||
@ -823,7 +824,7 @@ enum PathResult<'a> {
|
||||
Module(Module<'a>),
|
||||
NonModule(PathResolution),
|
||||
Indeterminate,
|
||||
Failed(String, bool /* is the error from the last segment? */),
|
||||
Failed(Span, String, bool /* is the error from the last segment? */),
|
||||
}
|
||||
|
||||
enum ModuleKind {
|
||||
@ -1282,19 +1283,21 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
|
||||
fn resolve_hir_path(&mut self, path: &mut hir::Path, is_value: bool) {
|
||||
let namespace = if is_value { ValueNS } else { TypeNS };
|
||||
let hir::Path { ref segments, span, ref mut def } = *path;
|
||||
let path: Vec<_> = segments.iter().map(|seg| Ident::with_empty_ctxt(seg.name)).collect();
|
||||
let path: Vec<SpannedIdent> = segments.iter()
|
||||
.map(|seg| respan(span, Ident::with_empty_ctxt(seg.name)))
|
||||
.collect();
|
||||
match self.resolve_path(&path, Some(namespace), true, span) {
|
||||
PathResult::Module(module) => *def = module.def().unwrap(),
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 =>
|
||||
*def = path_res.base_def(),
|
||||
PathResult::NonModule(..) => match self.resolve_path(&path, None, true, span) {
|
||||
PathResult::Failed(msg, _) => {
|
||||
PathResult::Failed(span, msg, _) => {
|
||||
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
PathResult::Indeterminate => unreachable!(),
|
||||
PathResult::Failed(msg, _) => {
|
||||
PathResult::Failed(span, msg, _) => {
|
||||
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
|
||||
}
|
||||
}
|
||||
@ -1916,7 +1919,9 @@ impl<'a> Resolver<'a> {
|
||||
let mut new_val = None;
|
||||
let mut new_id = None;
|
||||
if let Some(trait_ref) = opt_trait_ref {
|
||||
let path: Vec<_> = trait_ref.path.segments.iter().map(|seg| seg.identifier).collect();
|
||||
let path: Vec<_> = trait_ref.path.segments.iter()
|
||||
.map(|seg| respan(seg.span, seg.identifier))
|
||||
.collect();
|
||||
let def = self.smart_resolve_path_fragment(trait_ref.ref_id,
|
||||
None,
|
||||
&path,
|
||||
@ -2341,7 +2346,9 @@ impl<'a> Resolver<'a> {
|
||||
path: &Path,
|
||||
source: PathSource)
|
||||
-> PathResolution {
|
||||
let segments = &path.segments.iter().map(|seg| seg.identifier).collect::<Vec<_>>();
|
||||
let segments = &path.segments.iter()
|
||||
.map(|seg| respan(seg.span, seg.identifier))
|
||||
.collect::<Vec<_>>();
|
||||
let ident_span = path.segments.last().map_or(path.span, |seg| seg.span);
|
||||
self.smart_resolve_path_fragment(id, qself, segments, path.span, ident_span, source)
|
||||
}
|
||||
@ -2349,7 +2356,7 @@ impl<'a> Resolver<'a> {
|
||||
fn smart_resolve_path_fragment(&mut self,
|
||||
id: NodeId,
|
||||
qself: Option<&QSelf>,
|
||||
path: &[Ident],
|
||||
path: &[SpannedIdent],
|
||||
span: Span,
|
||||
ident_span: Span,
|
||||
source: PathSource)
|
||||
@ -2368,10 +2375,11 @@ impl<'a> Resolver<'a> {
|
||||
(format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str),
|
||||
format!("not a {}", expected), span)
|
||||
} else {
|
||||
let item_str = path[path.len() - 1];
|
||||
let item_str = path[path.len() - 1].node;
|
||||
let item_span = path[path.len() - 1].span;
|
||||
let (mod_prefix, mod_str) = if path.len() == 1 {
|
||||
(format!(""), format!("this scope"))
|
||||
} else if path.len() == 2 && path[0].name == keywords::CrateRoot.name() {
|
||||
} else if path.len() == 2 && path[0].node.name == keywords::CrateRoot.name() {
|
||||
(format!(""), format!("the crate root"))
|
||||
} else {
|
||||
let mod_path = &path[..path.len() - 1];
|
||||
@ -2382,7 +2390,7 @@ impl<'a> Resolver<'a> {
|
||||
(mod_prefix, format!("`{}`", names_to_string(mod_path)))
|
||||
};
|
||||
(format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str),
|
||||
format!("not found in {}", mod_str), ident_span)
|
||||
format!("not found in {}", mod_str), item_span)
|
||||
};
|
||||
let mut err = this.session.struct_span_err_with_code(base_span, &base_msg, code);
|
||||
|
||||
@ -2403,7 +2411,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
// Try to lookup the name in more relaxed fashion for better error reporting.
|
||||
let ident = *path.last().unwrap();
|
||||
let candidates = this.lookup_import_candidates(ident.name, ns, is_expected);
|
||||
let candidates = this.lookup_import_candidates(ident.node.name, ns, is_expected);
|
||||
if !candidates.is_empty() {
|
||||
let mut module_span = this.current_module.span;
|
||||
module_span.hi = module_span.lo;
|
||||
@ -2411,7 +2419,7 @@ impl<'a> Resolver<'a> {
|
||||
show_candidates(&mut err, module_span, &candidates, def.is_some());
|
||||
} else if is_expected(Def::Enum(DefId::local(CRATE_DEF_INDEX))) {
|
||||
let enum_candidates =
|
||||
this.lookup_import_candidates(ident.name, ns, is_enum_variant);
|
||||
this.lookup_import_candidates(ident.node.name, ns, is_enum_variant);
|
||||
let mut enum_candidates = enum_candidates.iter()
|
||||
.map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>();
|
||||
enum_candidates.sort();
|
||||
@ -2429,8 +2437,8 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
if path.len() == 1 && this.self_type_is_available(span) {
|
||||
if let Some(candidate) = this.lookup_assoc_candidate(ident, ns, is_expected) {
|
||||
let self_is_available = this.self_value_is_available(path[0].ctxt, span);
|
||||
if let Some(candidate) = this.lookup_assoc_candidate(ident.node, ns, is_expected) {
|
||||
let self_is_available = this.self_value_is_available(path[0].node.ctxt, span);
|
||||
match candidate {
|
||||
AssocSuggestion::Field => {
|
||||
err.span_suggestion(span, "try",
|
||||
@ -2546,7 +2554,7 @@ impl<'a> Resolver<'a> {
|
||||
// or `<T>::A::B`. If `B` should be resolved in value namespace then
|
||||
// it needs to be added to the trait map.
|
||||
if ns == ValueNS {
|
||||
let item_name = *path.last().unwrap();
|
||||
let item_name = path.last().unwrap().node;
|
||||
let traits = self.get_traits_containing_item(item_name, ns);
|
||||
self.trait_map.insert(id, traits);
|
||||
}
|
||||
@ -2613,7 +2621,7 @@ impl<'a> Resolver<'a> {
|
||||
fn resolve_qpath_anywhere(&mut self,
|
||||
id: NodeId,
|
||||
qself: Option<&QSelf>,
|
||||
path: &[Ident],
|
||||
path: &[SpannedIdent],
|
||||
primary_ns: Namespace,
|
||||
span: Span,
|
||||
defer_to_typeck: bool,
|
||||
@ -2633,9 +2641,10 @@ impl<'a> Resolver<'a> {
|
||||
};
|
||||
}
|
||||
}
|
||||
let is_global = self.global_macros.get(&path[0].name).cloned()
|
||||
let is_global = self.global_macros.get(&path[0].node.name).cloned()
|
||||
.map(|binding| binding.get_macro(self).kind() == MacroKind::Bang).unwrap_or(false);
|
||||
if primary_ns != MacroNS && (is_global || self.macro_names.contains(&path[0].modern())) {
|
||||
if primary_ns != MacroNS && (is_global ||
|
||||
self.macro_names.contains(&path[0].node.modern())) {
|
||||
// Return some dummy definition, it's enough for error reporting.
|
||||
return Some(
|
||||
PathResolution::new(Def::Macro(DefId::local(CRATE_DEF_INDEX), MacroKind::Bang))
|
||||
@ -2648,7 +2657,7 @@ impl<'a> Resolver<'a> {
|
||||
fn resolve_qpath(&mut self,
|
||||
id: NodeId,
|
||||
qself: Option<&QSelf>,
|
||||
path: &[Ident],
|
||||
path: &[SpannedIdent],
|
||||
ns: Namespace,
|
||||
span: Span,
|
||||
global_by_default: bool)
|
||||
@ -2688,8 +2697,9 @@ impl<'a> Resolver<'a> {
|
||||
// The same fallback is used when `a` resolves to nothing.
|
||||
PathResult::Module(..) | PathResult::Failed(..)
|
||||
if (ns == TypeNS || path.len() > 1) &&
|
||||
self.primitive_type_table.primitive_types.contains_key(&path[0].name) => {
|
||||
let prim = self.primitive_type_table.primitive_types[&path[0].name];
|
||||
self.primitive_type_table.primitive_types
|
||||
.contains_key(&path[0].node.name) => {
|
||||
let prim = self.primitive_type_table.primitive_types[&path[0].node.name];
|
||||
match prim {
|
||||
TyUint(UintTy::U128) | TyInt(IntTy::I128) => {
|
||||
if !self.session.features.borrow().i128_type {
|
||||
@ -2704,7 +2714,7 @@ impl<'a> Resolver<'a> {
|
||||
PathResolution::with_unresolved_segments(Def::PrimTy(prim), path.len() - 1)
|
||||
}
|
||||
PathResult::Module(module) => PathResolution::new(module.def().unwrap()),
|
||||
PathResult::Failed(msg, false) => {
|
||||
PathResult::Failed(span, msg, false) => {
|
||||
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
|
||||
err_path_resolution()
|
||||
}
|
||||
@ -2713,8 +2723,8 @@ impl<'a> Resolver<'a> {
|
||||
};
|
||||
|
||||
if path.len() > 1 && !global_by_default && result.base_def() != Def::Err &&
|
||||
path[0].name != keywords::CrateRoot.name() &&
|
||||
path[0].name != keywords::DollarCrate.name() {
|
||||
path[0].node.name != keywords::CrateRoot.name() &&
|
||||
path[0].node.name != keywords::DollarCrate.name() {
|
||||
let unqualified_result = {
|
||||
match self.resolve_path(&[*path.last().unwrap()], Some(ns), false, span) {
|
||||
PathResult::NonModule(path_res) => path_res.base_def(),
|
||||
@ -2732,7 +2742,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
|
||||
fn resolve_path(&mut self,
|
||||
path: &[Ident],
|
||||
path: &[SpannedIdent],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path
|
||||
record_used: bool,
|
||||
path_span: Span)
|
||||
@ -2741,15 +2751,16 @@ impl<'a> Resolver<'a> {
|
||||
let mut allow_super = true;
|
||||
|
||||
for (i, &ident) in path.iter().enumerate() {
|
||||
debug!("resolve_path ident {} {:?}", i, ident);
|
||||
let is_last = i == path.len() - 1;
|
||||
let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
|
||||
|
||||
if i == 0 && ns == TypeNS && ident.name == keywords::SelfValue.name() {
|
||||
let mut ctxt = ident.ctxt.modern();
|
||||
if i == 0 && ns == TypeNS && ident.node.name == keywords::SelfValue.name() {
|
||||
let mut ctxt = ident.node.ctxt.modern();
|
||||
module = Some(self.resolve_self(&mut ctxt, self.current_module));
|
||||
continue
|
||||
} else if allow_super && ns == TypeNS && ident.name == keywords::Super.name() {
|
||||
let mut ctxt = ident.ctxt.modern();
|
||||
} else if allow_super && ns == TypeNS && ident.node.name == keywords::Super.name() {
|
||||
let mut ctxt = ident.node.ctxt.modern();
|
||||
let self_module = match i {
|
||||
0 => self.resolve_self(&mut ctxt, self.current_module),
|
||||
_ => module.unwrap(),
|
||||
@ -2759,26 +2770,26 @@ impl<'a> Resolver<'a> {
|
||||
continue
|
||||
} else {
|
||||
let msg = "There are too many initial `super`s.".to_string();
|
||||
return PathResult::Failed(msg, false);
|
||||
return PathResult::Failed(ident.span, msg, false);
|
||||
}
|
||||
}
|
||||
allow_super = false;
|
||||
|
||||
if i == 0 && ns == TypeNS && ident.name == keywords::CrateRoot.name() {
|
||||
module = Some(self.resolve_crate_root(ident.ctxt.modern()));
|
||||
if i == 0 && ns == TypeNS && ident.node.name == keywords::CrateRoot.name() {
|
||||
module = Some(self.resolve_crate_root(ident.node.ctxt.modern()));
|
||||
continue
|
||||
} else if i == 0 && ns == TypeNS && ident.name == keywords::DollarCrate.name() {
|
||||
module = Some(self.resolve_crate_root(ident.ctxt));
|
||||
} else if i == 0 && ns == TypeNS && ident.node.name == keywords::DollarCrate.name() {
|
||||
module = Some(self.resolve_crate_root(ident.node.ctxt));
|
||||
continue
|
||||
}
|
||||
|
||||
let binding = if let Some(module) = module {
|
||||
self.resolve_ident_in_module(module, ident, ns, false, record_used, path_span)
|
||||
self.resolve_ident_in_module(module, ident.node, ns, false, record_used, path_span)
|
||||
} else if opt_ns == Some(MacroNS) {
|
||||
self.resolve_lexical_macro_path_segment(ident, ns, record_used, path_span)
|
||||
self.resolve_lexical_macro_path_segment(ident.node, ns, record_used, path_span)
|
||||
.map(MacroBinding::binding)
|
||||
} else {
|
||||
match self.resolve_ident_in_lexical_scope(ident, ns, record_used, path_span) {
|
||||
match self.resolve_ident_in_lexical_scope(ident.node, ns, record_used, path_span) {
|
||||
Some(LexicalScopeBinding::Item(binding)) => Ok(binding),
|
||||
Some(LexicalScopeBinding::Def(def))
|
||||
if opt_ns == Some(TypeNS) || opt_ns == Some(ValueNS) => {
|
||||
@ -2803,7 +2814,9 @@ impl<'a> Resolver<'a> {
|
||||
def, path.len() - i - 1
|
||||
));
|
||||
} else {
|
||||
return PathResult::Failed(format!("Not a module `{}`", ident), is_last);
|
||||
return PathResult::Failed(ident.span,
|
||||
format!("Not a module `{}`", ident.node),
|
||||
is_last);
|
||||
}
|
||||
}
|
||||
Err(Undetermined) => return PathResult::Indeterminate,
|
||||
@ -2818,19 +2831,19 @@ impl<'a> Resolver<'a> {
|
||||
let msg = if module.and_then(ModuleData::def) == self.graph_root.def() {
|
||||
let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
|
||||
let mut candidates =
|
||||
self.lookup_import_candidates(ident.name, TypeNS, is_mod);
|
||||
self.lookup_import_candidates(ident.node.name, TypeNS, is_mod);
|
||||
candidates.sort_by_key(|c| (c.path.segments.len(), c.path.to_string()));
|
||||
if let Some(candidate) = candidates.get(0) {
|
||||
format!("Did you mean `{}`?", candidate.path)
|
||||
} else {
|
||||
format!("Maybe a missing `extern crate {};`?", ident)
|
||||
format!("Maybe a missing `extern crate {};`?", ident.node)
|
||||
}
|
||||
} else if i == 0 {
|
||||
format!("Use of undeclared type or module `{}`", ident)
|
||||
format!("Use of undeclared type or module `{}`", ident.node)
|
||||
} else {
|
||||
format!("Could not find `{}` in `{}`", ident, path[i - 1])
|
||||
format!("Could not find `{}` in `{}`", ident.node, path[i - 1].node)
|
||||
};
|
||||
return PathResult::Failed(msg, is_last);
|
||||
return PathResult::Failed(ident.span, msg, is_last);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2850,8 +2863,7 @@ impl<'a> Resolver<'a> {
|
||||
// An invalid forward use of a type parameter from a previous default.
|
||||
if let ForwardTyParamBanRibKind = self.ribs[ns][rib_index].kind {
|
||||
if record_used {
|
||||
resolve_error(self, span,
|
||||
ResolutionError::ForwardDeclaredTyParam);
|
||||
resolve_error(self, span, ResolutionError::ForwardDeclaredTyParam);
|
||||
}
|
||||
assert_eq!(def, Def::Err);
|
||||
return Def::Err;
|
||||
@ -3021,7 +3033,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
|
||||
fn lookup_typo_candidate<FilterFn>(&mut self,
|
||||
path: &[Ident],
|
||||
path: &[SpannedIdent],
|
||||
ns: Namespace,
|
||||
filter_fn: FilterFn,
|
||||
span: Span)
|
||||
@ -3082,7 +3094,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
let name = path[path.len() - 1].name;
|
||||
let name = path[path.len() - 1].node.name;
|
||||
// Make sure error reporting is deterministic.
|
||||
names.sort_by_key(|name| name.as_str());
|
||||
match find_best_match_for_name(names.iter(), &name.as_str(), None) {
|
||||
@ -3620,27 +3632,31 @@ fn is_struct_like(def: Def) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_self_type(path: &[Ident], namespace: Namespace) -> bool {
|
||||
namespace == TypeNS && path.len() == 1 && path[0].name == keywords::SelfType.name()
|
||||
fn is_self_type(path: &[SpannedIdent], namespace: Namespace) -> bool {
|
||||
namespace == TypeNS && path.len() == 1 && path[0].node.name == keywords::SelfType.name()
|
||||
}
|
||||
|
||||
fn is_self_value(path: &[Ident], namespace: Namespace) -> bool {
|
||||
namespace == ValueNS && path.len() == 1 && path[0].name == keywords::SelfValue.name()
|
||||
fn is_self_value(path: &[SpannedIdent], namespace: Namespace) -> bool {
|
||||
namespace == ValueNS && path.len() == 1 && path[0].node.name == keywords::SelfValue.name()
|
||||
}
|
||||
|
||||
fn names_to_string(idents: &[Ident]) -> String {
|
||||
fn names_to_string(idents: &[SpannedIdent]) -> String {
|
||||
let mut result = String::new();
|
||||
for (i, ident) in idents.iter().filter(|i| i.name != keywords::CrateRoot.name()).enumerate() {
|
||||
for (i, ident) in idents.iter()
|
||||
.filter(|i| i.node.name != keywords::CrateRoot.name())
|
||||
.enumerate() {
|
||||
if i > 0 {
|
||||
result.push_str("::");
|
||||
}
|
||||
result.push_str(&ident.name.as_str());
|
||||
result.push_str(&ident.node.name.as_str());
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn path_names_to_string(path: &Path) -> String {
|
||||
names_to_string(&path.segments.iter().map(|seg| seg.identifier).collect::<Vec<_>>())
|
||||
names_to_string(&path.segments.iter()
|
||||
.map(|seg| respan(seg.span, seg.identifier))
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
/// Get the path for an enum and the variant from an `ImportSuggestion` for an enum variant.
|
||||
@ -3708,7 +3724,10 @@ fn module_to_string(module: Module) -> String {
|
||||
if names.is_empty() {
|
||||
return "???".to_string();
|
||||
}
|
||||
names_to_string(&names.into_iter().rev().collect::<Vec<_>>())
|
||||
names_to_string(&names.into_iter()
|
||||
.rev()
|
||||
.map(|n| dummy_spanned(n))
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
fn err_path_resolution() -> PathResolution {
|
||||
|
@ -19,6 +19,7 @@ use rustc::hir::map::{self, DefCollector};
|
||||
use rustc::{ty, lint};
|
||||
use syntax::ast::{self, Name, Ident};
|
||||
use syntax::attr::{self, HasAttrs};
|
||||
use syntax::codemap::respan;
|
||||
use syntax::errors::DiagnosticBuilder;
|
||||
use syntax::ext::base::{self, Annotatable, Determinacy, MultiModifier, MultiDecorator};
|
||||
use syntax::ext::base::{MacroKind, SyntaxExtension, Resolver as SyntaxResolver};
|
||||
@ -393,7 +394,7 @@ impl<'a> Resolver<'a> {
|
||||
return Err(Determinacy::Determined);
|
||||
}
|
||||
|
||||
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
|
||||
let path: Vec<_> = segments.iter().map(|seg| respan(seg.span, seg.identifier)).collect();
|
||||
let invocation = self.invocations[&scope];
|
||||
self.current_module = invocation.module.get();
|
||||
|
||||
@ -418,16 +419,19 @@ impl<'a> Resolver<'a> {
|
||||
Err(Determinacy::Determined)
|
||||
},
|
||||
};
|
||||
let path = path.iter().map(|p| p.node).collect::<Vec<_>>();
|
||||
self.current_module.nearest_item_scope().macro_resolutions.borrow_mut()
|
||||
.push((path.into_boxed_slice(), span));
|
||||
return def;
|
||||
}
|
||||
|
||||
let legacy_resolution = self.resolve_legacy_scope(&invocation.legacy_scope, path[0], false);
|
||||
let legacy_resolution = self.resolve_legacy_scope(&invocation.legacy_scope,
|
||||
path[0].node,
|
||||
false);
|
||||
let result = if let Some(MacroBinding::Legacy(binding)) = legacy_resolution {
|
||||
Ok(Def::Macro(binding.def_id, MacroKind::Bang))
|
||||
} else {
|
||||
match self.resolve_lexical_macro_path_segment(path[0], MacroNS, false, span) {
|
||||
match self.resolve_lexical_macro_path_segment(path[0].node, MacroNS, false, span) {
|
||||
Ok(binding) => Ok(binding.binding().def_ignoring_ambiguity()),
|
||||
Err(Determinacy::Undetermined) if !force => return Err(Determinacy::Undetermined),
|
||||
Err(_) => {
|
||||
@ -438,7 +442,7 @@ impl<'a> Resolver<'a> {
|
||||
};
|
||||
|
||||
self.current_module.nearest_item_scope().legacy_macro_resolutions.borrow_mut()
|
||||
.push((scope, path[0], span, kind));
|
||||
.push((scope, path[0].node, span, kind));
|
||||
|
||||
result
|
||||
}
|
||||
@ -576,9 +580,10 @@ impl<'a> Resolver<'a> {
|
||||
pub fn finalize_current_module_macro_resolutions(&mut self) {
|
||||
let module = self.current_module;
|
||||
for &(ref path, span) in module.macro_resolutions.borrow().iter() {
|
||||
match self.resolve_path(path, Some(MacroNS), true, span) {
|
||||
let path = path.iter().map(|p| respan(span, *p)).collect::<Vec<_>>();
|
||||
match self.resolve_path(&path, Some(MacroNS), true, span) {
|
||||
PathResult::NonModule(_) => {},
|
||||
PathResult::Failed(msg, _) => {
|
||||
PathResult::Failed(span, msg, _) => {
|
||||
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@ -652,7 +657,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
};
|
||||
let ident = Ident::from_str(name);
|
||||
self.lookup_typo_candidate(&vec![ident], MacroNS, is_macro, span)
|
||||
self.lookup_typo_candidate(&vec![respan(span, ident)], MacroNS, is_macro, span)
|
||||
});
|
||||
|
||||
if let Some(suggestion) = suggestion {
|
||||
|
@ -21,9 +21,9 @@ use rustc::ty;
|
||||
use rustc::lint::builtin::PUB_USE_OF_PRIVATE_EXTERN_CRATE;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::def::*;
|
||||
use rustc::util::nodemap::FxHashMap;
|
||||
use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
||||
|
||||
use syntax::ast::{Ident, NodeId};
|
||||
use syntax::ast::{Ident, SpannedIdent, NodeId};
|
||||
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
|
||||
use syntax::ext::hygiene::Mark;
|
||||
use syntax::parse::token;
|
||||
@ -57,7 +57,7 @@ pub enum ImportDirectiveSubclass<'a> {
|
||||
pub struct ImportDirective<'a> {
|
||||
pub id: NodeId,
|
||||
pub parent: Module<'a>,
|
||||
pub module_path: Vec<Ident>,
|
||||
pub module_path: Vec<SpannedIdent>,
|
||||
pub imported_module: Cell<Option<Module<'a>>>, // the resolution of `module_path`
|
||||
pub subclass: ImportDirectiveSubclass<'a>,
|
||||
pub span: Span,
|
||||
@ -256,7 +256,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
// Add an import directive to the current module.
|
||||
pub fn add_import_directive(&mut self,
|
||||
module_path: Vec<Ident>,
|
||||
module_path: Vec<SpannedIdent>,
|
||||
subclass: ImportDirectiveSubclass<'a>,
|
||||
span: Span,
|
||||
id: NodeId,
|
||||
@ -478,9 +478,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
}
|
||||
|
||||
let mut errors = false;
|
||||
let mut seen_spans = FxHashSet();
|
||||
for i in 0 .. self.determined_imports.len() {
|
||||
let import = self.determined_imports[i];
|
||||
if let Some(err) = self.finalize_import(import) {
|
||||
if let Some((span, err)) = self.finalize_import(import) {
|
||||
errors = true;
|
||||
|
||||
if let SingleImport { source, ref result, .. } = import.subclass {
|
||||
@ -496,9 +497,14 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
// If the error is a single failed import then create a "fake" import
|
||||
// resolution for it so that later resolve stages won't complain.
|
||||
self.import_dummy_binding(import);
|
||||
let path = import_path_to_string(&import.module_path, &import.subclass);
|
||||
let error = ResolutionError::UnresolvedImport(Some((&path, &err)));
|
||||
resolve_error(self.resolver, import.span, error);
|
||||
if !seen_spans.contains(&span) {
|
||||
let path = import_path_to_string(&import.module_path[..],
|
||||
&import.subclass,
|
||||
span);
|
||||
let error = ResolutionError::UnresolvedImport(Some((span, &path, &err)));
|
||||
resolve_error(self.resolver, span, error);
|
||||
seen_spans.insert(span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -516,7 +522,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
/// If successful, the resolved bindings are written into the module.
|
||||
fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool {
|
||||
debug!("(resolving import for module) resolving import `{}::...` in `{}`",
|
||||
names_to_string(&directive.module_path),
|
||||
names_to_string(&directive.module_path[..]),
|
||||
module_to_string(self.current_module));
|
||||
|
||||
self.current_module = directive.parent;
|
||||
@ -528,7 +534,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
// For better failure detection, pretend that the import will not define any names
|
||||
// while resolving its module path.
|
||||
directive.vis.set(ty::Visibility::Invisible);
|
||||
let result = self.resolve_path(&directive.module_path, None, false, directive.span);
|
||||
let result = self.resolve_path(&directive.module_path[..], None, false, directive.span);
|
||||
directive.vis.set(vis);
|
||||
|
||||
match result {
|
||||
@ -593,23 +599,25 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
}
|
||||
|
||||
// If appropriate, returns an error to report.
|
||||
fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<String> {
|
||||
fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Span, String)> {
|
||||
self.current_module = directive.parent;
|
||||
|
||||
let ImportDirective { ref module_path, span, .. } = *directive;
|
||||
let module_result = self.resolve_path(&module_path, None, true, span);
|
||||
let module = match module_result {
|
||||
PathResult::Module(module) => module,
|
||||
PathResult::Failed(msg, _) => {
|
||||
PathResult::Failed(span, msg, _) => {
|
||||
let (mut self_path, mut self_result) = (module_path.clone(), None);
|
||||
if !self_path.is_empty() && !token::Ident(self_path[0]).is_path_segment_keyword() {
|
||||
self_path[0].name = keywords::SelfValue.name();
|
||||
if !self_path.is_empty() &&
|
||||
!token::Ident(self_path[0].node).is_path_segment_keyword()
|
||||
{
|
||||
self_path[0].node.name = keywords::SelfValue.name();
|
||||
self_result = Some(self.resolve_path(&self_path, None, false, span));
|
||||
}
|
||||
return if let Some(PathResult::Module(..)) = self_result {
|
||||
Some(format!("Did you mean `{}`?", names_to_string(&self_path)))
|
||||
Some((span, format!("Did you mean `{}`?", names_to_string(&self_path[..]))))
|
||||
} else {
|
||||
Some(msg)
|
||||
Some((span, msg))
|
||||
};
|
||||
},
|
||||
_ => return None,
|
||||
@ -619,7 +627,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
SingleImport { source, ref result, type_ns_only, .. } => (source, result, type_ns_only),
|
||||
GlobImport { .. } if module.def_id() == directive.parent.def_id() => {
|
||||
// Importing a module into itself is not allowed.
|
||||
return Some("Cannot glob-import a module into itself.".to_string());
|
||||
return Some((directive.span,
|
||||
"Cannot glob-import a module into itself.".to_string()));
|
||||
}
|
||||
GlobImport { is_prelude, ref max_vis } => {
|
||||
if !is_prelude &&
|
||||
@ -708,7 +717,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
} else {
|
||||
format!("no `{}` in `{}`{}", ident, module_str, lev_suggestion)
|
||||
};
|
||||
Some(msg)
|
||||
Some((span, msg))
|
||||
} else {
|
||||
// `resolve_ident_in_module` reported a privacy error.
|
||||
self.import_dummy_binding(directive);
|
||||
@ -888,16 +897,24 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
fn import_path_to_string(names: &[Ident], subclass: &ImportDirectiveSubclass) -> String {
|
||||
let global = !names.is_empty() && names[0].name == keywords::CrateRoot.name();
|
||||
let names = if global { &names[1..] } else { names };
|
||||
if names.is_empty() {
|
||||
import_directive_subclass_to_string(subclass)
|
||||
fn import_path_to_string(names: &[SpannedIdent],
|
||||
subclass: &ImportDirectiveSubclass,
|
||||
span: Span) -> String {
|
||||
let pos = names.iter()
|
||||
.position(|p| span == p.span && p.node.name != keywords::CrateRoot.name());
|
||||
let global = !names.is_empty() && names[0].node.name == keywords::CrateRoot.name();
|
||||
if let Some(pos) = pos {
|
||||
let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] };
|
||||
names_to_string(names)
|
||||
} else {
|
||||
(format!("{}::{}",
|
||||
names_to_string(names),
|
||||
import_directive_subclass_to_string(subclass)))
|
||||
.to_string()
|
||||
let names = if global { &names[1..] } else { names };
|
||||
if names.is_empty() {
|
||||
import_directive_subclass_to_string(subclass)
|
||||
} else {
|
||||
(format!("{}::{}",
|
||||
names_to_string(names),
|
||||
import_directive_subclass_to_string(subclass)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ fn main() {
|
||||
println!("cargo:rustc-link-lib=socket");
|
||||
println!("cargo:rustc-link-lib=posix4");
|
||||
println!("cargo:rustc-link-lib=pthread");
|
||||
println!("cargo:rustc-link-lib=resolv");
|
||||
} else if target.contains("apple-darwin") {
|
||||
println!("cargo:rustc-link-lib=System");
|
||||
|
||||
|
@ -44,7 +44,7 @@ impl TaggedHashUintPtr {
|
||||
#[inline]
|
||||
unsafe fn new(ptr: *mut HashUint) -> Self {
|
||||
debug_assert!(ptr as usize & 1 == 0 || ptr as usize == EMPTY as usize);
|
||||
TaggedHashUintPtr(Unique::new(ptr))
|
||||
TaggedHashUintPtr(Unique::new_unchecked(ptr))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -56,7 +56,7 @@ impl TaggedHashUintPtr {
|
||||
} else {
|
||||
usize_ptr &= !1;
|
||||
}
|
||||
self.0 = Unique::new(usize_ptr as *mut HashUint)
|
||||
self.0 = Unique::new_unchecked(usize_ptr as *mut HashUint)
|
||||
}
|
||||
}
|
||||
|
||||
@ -877,7 +877,7 @@ impl<K, V> RawTable<K, V> {
|
||||
elems_left: elems_left,
|
||||
marker: marker::PhantomData,
|
||||
},
|
||||
table: unsafe { Shared::new(self) },
|
||||
table: Shared::from(self),
|
||||
marker: marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ impl Builder {
|
||||
/// *by value* from the thread where it is spawned to the new thread. Its
|
||||
/// return value will need to be passed from the new thread to the thread
|
||||
/// where it is `join`ed.
|
||||
/// As a reminder, the [`Send`] marker trait, expresses that it is safe to be
|
||||
/// As a reminder, the [`Send`] marker trait expresses that it is safe to be
|
||||
/// passed from thread to thread. [`Sync`] expresses that it is safe to have a
|
||||
/// reference be passed from thread to thread.
|
||||
///
|
||||
|
@ -2243,9 +2243,9 @@ impl<'a> Parser<'a> {
|
||||
attrs);
|
||||
}
|
||||
if self.is_catch_expr() {
|
||||
let lo = self.span;
|
||||
assert!(self.eat_keyword(keywords::Do));
|
||||
assert!(self.eat_keyword(keywords::Catch));
|
||||
let lo = self.prev_span;
|
||||
return self.parse_catch_expr(lo, attrs);
|
||||
}
|
||||
if self.eat_keyword(keywords::Return) {
|
||||
|
@ -13,7 +13,7 @@ mod a {}
|
||||
macro_rules! m {
|
||||
() => {
|
||||
use a::$crate; //~ ERROR unresolved import `a::$crate`
|
||||
use a::$crate::b; //~ ERROR unresolved import `a::$crate::b`
|
||||
use a::$crate::b; //~ ERROR unresolved import `a::$crate`
|
||||
type A = a::$crate; //~ ERROR cannot find type `$crate` in module `a`
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use baz::zed::bar; //~ ERROR unresolved import `baz::zed::bar` [E0432]
|
||||
use baz::zed::bar; //~ ERROR unresolved import `baz::zed` [E0432]
|
||||
//~^ Could not find `zed` in `baz`
|
||||
|
||||
mod baz {}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// Testing that we don't fail abnormally after hitting the errors
|
||||
|
||||
use unresolved::*; //~ ERROR unresolved import `unresolved::*` [E0432]
|
||||
use unresolved::*; //~ ERROR unresolved import `unresolved` [E0432]
|
||||
//~^ Maybe a missing `extern crate unresolved;`?
|
||||
|
||||
fn main() {}
|
||||
|
@ -10,10 +10,10 @@
|
||||
|
||||
type Alias = ();
|
||||
use Alias::*;
|
||||
//~^ ERROR unresolved import `Alias::*` [E0432]
|
||||
//~^ ERROR unresolved import `Alias` [E0432]
|
||||
//~| Not a module `Alias`
|
||||
use std::io::Result::*;
|
||||
//~^ ERROR unresolved import `std::io::Result::*` [E0432]
|
||||
//~^ ERROR unresolved import `std::io::Result` [E0432]
|
||||
//~| Not a module `Result`
|
||||
|
||||
trait T {}
|
||||
|
@ -11,13 +11,10 @@
|
||||
// Make sure that the spans of import errors are correct.
|
||||
|
||||
use abc::one_el;
|
||||
//~^ ERROR 13:5: 13:16
|
||||
//~^ ERROR 13:5: 13:8
|
||||
use abc::{a, bbb, cccccc};
|
||||
//~^ ERROR 15:11: 15:12
|
||||
//~^^ ERROR 15:14: 15:17
|
||||
//~^^^ ERROR 15:19: 15:25
|
||||
//~^ ERROR 15:5: 15:8
|
||||
use a_very_long_name::{el, el2};
|
||||
//~^ ERROR 19:24: 19:26
|
||||
//~^^ ERROR 19:28: 19:31
|
||||
//~^ ERROR 17:5: 17:21
|
||||
|
||||
fn main() {}
|
||||
|
19
src/test/compile-fail/issue-33504.rs
Normal file
19
src/test/compile-fail/issue-33504.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Shadowing a unit-like enum in a closure
|
||||
|
||||
struct Test;
|
||||
|
||||
fn main() {
|
||||
|| {
|
||||
let Test = 1; //~ ERROR let bindings cannot shadow unit structs
|
||||
};
|
||||
}
|
24
src/test/compile-fail/issue-39211.rs
Normal file
24
src/test/compile-fail/issue-39211.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(associated_consts)]
|
||||
|
||||
trait VecN {
|
||||
const DIM: usize;
|
||||
}
|
||||
trait Mat {
|
||||
type Row: VecN;
|
||||
}
|
||||
|
||||
fn m<M: Mat>() {
|
||||
let a = [3; M::Row::DIM]; //~ ERROR associated type `Row` not found for `M`
|
||||
}
|
||||
fn main() {
|
||||
}
|
@ -13,19 +13,19 @@
|
||||
mod a {
|
||||
extern crate alloc;
|
||||
use alloc::HashMap;
|
||||
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
|
||||
//~^ ERROR unresolved import `alloc` [E0432]
|
||||
//~| Did you mean `self::alloc`?
|
||||
mod b {
|
||||
use alloc::HashMap;
|
||||
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
|
||||
//~^ ERROR unresolved import `alloc` [E0432]
|
||||
//~| Did you mean `a::alloc`?
|
||||
mod c {
|
||||
use alloc::HashMap;
|
||||
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
|
||||
//~^ ERROR unresolved import `alloc` [E0432]
|
||||
//~| Did you mean `a::alloc`?
|
||||
mod d {
|
||||
use alloc::HashMap;
|
||||
//~^ ERROR unresolved import `alloc::HashMap` [E0432]
|
||||
//~^ ERROR unresolved import `alloc` [E0432]
|
||||
//~| Did you mean `a::alloc`?
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use super::f; //~ ERROR unresolved import `super::f` [E0432]
|
||||
use super::f; //~ ERROR unresolved import `super` [E0432]
|
||||
//~^ There are too many initial `super`s.
|
||||
|
||||
fn main() {
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
|
||||
use foo::bar; //~ ERROR unresolved import `foo::bar` [E0432]
|
||||
use foo::bar; //~ ERROR unresolved import `foo` [E0432]
|
||||
//~^ Maybe a missing `extern crate foo;`?
|
||||
|
||||
use bar::Baz as x; //~ ERROR unresolved import `bar::Baz` [E0432]
|
||||
@ -41,7 +41,7 @@ mod m {
|
||||
MyVariant
|
||||
}
|
||||
|
||||
use MyEnum::*; //~ ERROR unresolved import `MyEnum::*` [E0432]
|
||||
use MyEnum::*; //~ ERROR unresolved import `MyEnum` [E0432]
|
||||
//~^ Did you mean `self::MyEnum`?
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ mod items {
|
||||
Variant
|
||||
}
|
||||
|
||||
use Enum::*; //~ ERROR unresolved import `Enum::*` [E0432]
|
||||
use Enum::*; //~ ERROR unresolved import `Enum` [E0432]
|
||||
//~^ Did you mean `self::Enum`?
|
||||
|
||||
fn item() {}
|
||||
|
@ -22,13 +22,13 @@ use use_from_trait_xc::Trait::CONST;
|
||||
//~^ ERROR `CONST` is not directly importable
|
||||
|
||||
use use_from_trait_xc::Foo::new; //~ ERROR struct `Foo` is private
|
||||
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`
|
||||
//~^ ERROR unresolved import `use_from_trait_xc::Foo`
|
||||
|
||||
use use_from_trait_xc::Foo::C; //~ ERROR struct `Foo` is private
|
||||
//~^ ERROR unresolved import `use_from_trait_xc::Foo::C`
|
||||
//~^ ERROR unresolved import `use_from_trait_xc::Foo`
|
||||
|
||||
use use_from_trait_xc::Bar::new as bnew;
|
||||
//~^ ERROR unresolved import `use_from_trait_xc::Bar::new`
|
||||
//~^ ERROR unresolved import `use_from_trait_xc::Bar`
|
||||
|
||||
use use_from_trait_xc::Baz::new as baznew;
|
||||
//~^ ERROR unresolved import `use_from_trait_xc::Baz::new`
|
||||
|
@ -17,11 +17,11 @@ use Trait::C;
|
||||
//~^ ERROR `C` is not directly importable
|
||||
|
||||
use Foo::new;
|
||||
//~^ ERROR unresolved import `Foo::new` [E0432]
|
||||
//~^ ERROR unresolved import `Foo` [E0432]
|
||||
//~| Not a module `Foo`
|
||||
|
||||
use Foo::C2;
|
||||
//~^ ERROR unresolved import `Foo::C2` [E0432]
|
||||
//~^ ERROR unresolved import `Foo` [E0432]
|
||||
//~| Not a module `Foo`
|
||||
|
||||
pub trait Trait {
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use foo::self; //~ ERROR unresolved import `foo::self`
|
||||
use foo::self; //~ ERROR unresolved import `foo`
|
||||
//~^ ERROR `self` imports are only allowed within a { } list
|
||||
|
||||
use std::mem::self;
|
||||
|
20
src/test/run-fail/issue-29798.rs
Normal file
20
src/test/run-fail/issue-29798.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:index out of bounds: the len is 5 but the index is 5
|
||||
|
||||
#![feature(const_fn)]
|
||||
const fn test(x: usize) -> i32 {
|
||||
[42;5][x]
|
||||
}
|
||||
|
||||
fn main () {
|
||||
let _ = test(5);
|
||||
}
|
@ -16,7 +16,7 @@ use std::ptr::Unique;
|
||||
|
||||
fn main() {
|
||||
let mut a = [0u8; 5];
|
||||
let b: Option<Unique<[u8]>> = unsafe { Some(Unique::new(&mut a)) };
|
||||
let b: Option<Unique<[u8]>> = Some(Unique::from(&mut a));
|
||||
match b {
|
||||
Some(_) => println!("Got `Some`"),
|
||||
None => panic!("Unexpected `None`"),
|
||||
|
28
src/test/run-pass/issue-29516.rs
Normal file
28
src/test/run-pass/issue-29516.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait NotSame {}
|
||||
impl NotSame for .. {}
|
||||
impl<A> !NotSame for (A, A) {}
|
||||
|
||||
trait OneOfEach {}
|
||||
|
||||
impl<A> OneOfEach for (A,) {}
|
||||
|
||||
impl<A, B> OneOfEach for (A, B)
|
||||
where
|
||||
(B,): OneOfEach,
|
||||
(A, B): NotSame,
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
19
src/test/run-pass/issue-34780.rs
Normal file
19
src/test/run-pass/issue-34780.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(associated_consts)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
trait Tr<'a> {
|
||||
const C: PhantomData<&'a u8> = PhantomData::<&'a u8>;
|
||||
}
|
||||
|
||||
fn main() {}
|
19
src/test/run-pass/issue-39467.rs
Normal file
19
src/test/run-pass/issue-39467.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
macro_rules! expr { () => { () } }
|
||||
|
||||
enum A {}
|
||||
|
||||
impl A {
|
||||
const A: () = expr!();
|
||||
}
|
||||
|
||||
fn main() {}
|
31
src/test/run-pass/issue-39720.rs
Normal file
31
src/test/run-pass/issue-39720.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(repr_simd, platform_intrinsics)]
|
||||
|
||||
#[repr(C)]
|
||||
#[repr(simd)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct char3(pub i8, pub i8, pub i8);
|
||||
|
||||
#[repr(C)]
|
||||
#[repr(simd)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct short3(pub i16, pub i16, pub i16);
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_cast<T, U>(x: T) -> U;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cast: short3 = unsafe { simd_cast(char3(10, -3, -9)) };
|
||||
|
||||
println!("{:?}", cast);
|
||||
}
|
15
src/test/rustdoc/issue-19181.rs
Normal file
15
src/test/rustdoc/issue-19181.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags:--test
|
||||
|
||||
// rustdoc should not panic when target crate has compilation errors
|
||||
|
||||
fn main() { 0 }
|
@ -2,7 +2,7 @@ error[E0433]: failed to resolve. Use of undeclared type or module `m`
|
||||
--> $DIR/macro_path_as_generic_bound.rs:17:6
|
||||
|
|
||||
17 | foo!(m::m2::A);
|
||||
| ^^^^^^^^ Use of undeclared type or module `m`
|
||||
| ^ Use of undeclared type or module `m`
|
||||
|
||||
error: cannot continue compilation due to previous error
|
||||
|
||||
|
@ -42,7 +42,7 @@ impl Default for EmbeddedDiscr {
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct IndirectNonZero<T: Zeroable> {
|
||||
pub struct IndirectNonZero<T: Zeroable + One> {
|
||||
pre: u8,
|
||||
nested: NestedNonZero<T>,
|
||||
post: u16,
|
||||
@ -54,14 +54,20 @@ pub struct NestedNonZero<T: Zeroable> {
|
||||
post: u16,
|
||||
}
|
||||
|
||||
impl<T: Zeroable+Default> Default for NestedNonZero<T> {
|
||||
impl<T: Zeroable+One> Default for NestedNonZero<T> {
|
||||
fn default() -> Self {
|
||||
unsafe {
|
||||
NestedNonZero { pre: 0, val: NonZero::new(Default::default()), post: 0 }
|
||||
}
|
||||
NestedNonZero { pre: 0, val: NonZero::new(T::one()).unwrap(), post: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait One {
|
||||
fn one() -> Self;
|
||||
}
|
||||
|
||||
impl One for u32 {
|
||||
fn one() -> Self { 1 }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let _x: MyOption<NonZero<u32>> = Default::default();
|
||||
let _y: EmbeddedDiscr = Default::default();
|
||||
|
13
src/test/ui/span/non-existing-module-import.rs
Normal file
13
src/test/ui/span/non-existing-module-import.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::bar::{foo1, foo2};
|
||||
|
||||
fn main() {}
|
8
src/test/ui/span/non-existing-module-import.stderr
Normal file
8
src/test/ui/span/non-existing-module-import.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error[E0432]: unresolved import `std::bar`
|
||||
--> $DIR/non-existing-module-import.rs:11:10
|
||||
|
|
||||
11 | use std::bar::{foo1, foo2};
|
||||
| ^^^ Could not find `bar` in `std`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user