diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index f25631e028eec..487f3b76fc75f 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -359,9 +359,12 @@ impl fmt::Display for AllocErr { } } -/// The `CannotReallocInPlace` error is used when `grow_in_place` or -/// `shrink_in_place` were unable to reuse the given memory block for +/// The `CannotReallocInPlace` error is used when [`grow_in_place`] or +/// [`shrink_in_place`] were unable to reuse the given memory block for /// a requested layout. +/// +/// [`grow_in_place`]: ./trait.Alloc.html#method.grow_in_place +/// [`shrink_in_place`]: ./trait.Alloc.html#method.shrink_in_place #[unstable(feature = "allocator_api", issue = "32838")] #[derive(Clone, PartialEq, Eq, Debug)] pub struct CannotReallocInPlace; diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index beafddc5a1019..f74e945b3cc1b 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -290,7 +290,7 @@ impl Clone for Cell { } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for Cell { +impl Default for Cell { /// Creates a `Cell`, with the `Default` value for T. #[inline] fn default() -> Cell { @@ -299,7 +299,7 @@ impl Default for Cell { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for Cell { +impl PartialEq for Cell { #[inline] fn eq(&self, other: &Cell) -> bool { self.get() == other.get() @@ -307,10 +307,10 @@ impl PartialEq for Cell { } #[stable(feature = "cell_eq", since = "1.2.0")] -impl Eq for Cell {} +impl Eq for Cell {} #[stable(feature = "cell_ord", since = "1.10.0")] -impl PartialOrd for Cell { +impl PartialOrd for Cell { #[inline] fn partial_cmp(&self, other: &Cell) -> Option { self.get().partial_cmp(&other.get()) @@ -338,7 +338,7 @@ impl PartialOrd for Cell { } #[stable(feature = "cell_ord", since = "1.10.0")] -impl Ord for Cell { +impl Ord for Cell { #[inline] fn cmp(&self, other: &Cell) -> Ordering { self.get().cmp(&other.get()) @@ -1008,7 +1008,7 @@ impl Clone for RefCell { } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for RefCell { +impl Default for RefCell { /// Creates a `RefCell`, with the `Default` value for T. #[inline] fn default() -> RefCell { diff --git a/src/libcore/ffi.rs b/src/libcore/ffi.rs index 4f87cc506efae..eda0e7c518c58 100644 --- a/src/libcore/ffi.rs +++ b/src/libcore/ffi.rs @@ -60,7 +60,10 @@ impl fmt::Debug for c_void { #[lang = "va_list"] pub struct VaListImpl<'f> { ptr: *mut c_void, - _marker: PhantomData<&'f c_void>, + + // Invariant over `'f`, so each `VaListImpl<'f>` object is tied to + // the region of the function it's defined in + _marker: PhantomData<&'f mut &'f c_void>, } #[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), @@ -96,7 +99,7 @@ pub struct VaListImpl<'f> { vr_top: *mut c_void, gr_offs: i32, vr_offs: i32, - _marker: PhantomData<&'f c_void>, + _marker: PhantomData<&'f mut &'f c_void>, } /// PowerPC ABI implementation of a `va_list`. @@ -114,7 +117,7 @@ pub struct VaListImpl<'f> { reserved: u16, overflow_arg_area: *mut c_void, reg_save_area: *mut c_void, - _marker: PhantomData<&'f c_void>, + _marker: PhantomData<&'f mut &'f c_void>, } /// x86_64 ABI implementation of a `va_list`. @@ -131,7 +134,7 @@ pub struct VaListImpl<'f> { fp_offset: i32, overflow_arg_area: *mut c_void, reg_save_area: *mut c_void, - _marker: PhantomData<&'f c_void>, + _marker: PhantomData<&'f mut &'f c_void>, } /// asm.js ABI implementation of a `va_list`. @@ -148,7 +151,7 @@ pub struct VaListImpl<'f> { #[lang = "va_list"] pub struct VaListImpl<'f> { inner: [crate::mem::MaybeUninit; 4], - _marker: PhantomData<&'f c_void>, + _marker: PhantomData<&'f mut &'f c_void>, } #[cfg(all(target_arch = "asmjs", not(windows)))] diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 193cdb15b548d..0b3ef41891b5f 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -291,6 +291,8 @@ impl Option { /// Converts from [`Pin`]`<&Option>` to `Option<`[`Pin`]`<&T>>`. + /// + /// [`Pin`]: ../pin/struct.Pin.html #[inline] #[stable(feature = "pin", since = "1.33.0")] pub fn as_pin_ref<'a>(self: Pin<&'a Option>) -> Option> { @@ -300,6 +302,8 @@ impl Option { } /// Converts from [`Pin`]`<&mut Option>` to `Option<`[`Pin`]`<&mut T>>`. + /// + /// [`Pin`]: ../pin/struct.Pin.html #[inline] #[stable(feature = "pin", since = "1.33.0")] pub fn as_pin_mut<'a>(self: Pin<&'a mut Option>) -> Option> { diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index c7c5849a00fa0..54e1c876f4caa 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -32,7 +32,7 @@ use crate::sys_common::{AsInner, IntoInner, FromInner}; /// in each pair are owned strings; the latter are borrowed /// references. /// -/// Note, `OsString` and `OsStr` internally do not necessarily hold strings in +/// Note, `OsString` and [`OsStr`] internally do not necessarily hold strings in /// the form native to the platform; While on Unix, strings are stored as a /// sequence of 8-bit values, on Windows, where strings are 16-bit value based /// as just discussed, strings are also actually stored as a sequence of 8-bit @@ -667,10 +667,11 @@ impl From<&OsStr> for Box { #[stable(feature = "os_string_from_box", since = "1.18.0")] impl From> for OsString { - /// Converts a `Box` into a `OsString` without copying or allocating. + /// Converts a [`Box`]`<`[`OsStr`]`>` into a `OsString` without copying or + /// allocating. /// /// [`Box`]: ../boxed/struct.Box.html - /// [`OsString`]: ../ffi/struct.OsString.html + /// [`OsStr`]: ../ffi/struct.OsStr.html fn from(boxed: Box) -> OsString { boxed.into_os_string() } diff --git a/src/test/ui/c-variadic/variadic-ffi-4.rs b/src/test/ui/c-variadic/variadic-ffi-4.rs index 07c32ecbfc2dc..4a50d352a5b20 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.rs +++ b/src/test/ui/c-variadic/variadic-ffi-4.rs @@ -18,6 +18,7 @@ pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) { pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { *ap0 = ap1; //~ ERROR: mismatched types + //~^ ERROR: mismatched types } pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { @@ -29,5 +30,6 @@ pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ... } pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { - *ap0 = ap1.clone(); //~ ERROR: cannot infer an appropriate lifetime + *ap0 = ap1.clone(); //~ ERROR: mismatched types + //~^ ERROR: mismatched types } diff --git a/src/test/ui/c-variadic/variadic-ffi-4.stderr b/src/test/ui/c-variadic/variadic-ffi-4.stderr index 72d4d8b63445a..7aa510e611304 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-4.stderr @@ -52,6 +52,7 @@ note: the anonymous lifetime #3 defined on the function body at 19:1... | LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1; +LL | | LL | | } | |_^ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 19:1 @@ -59,17 +60,43 @@ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the f | LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1; +LL | | +LL | | } + | |_^ + +error[E0308]: mismatched types + --> $DIR/variadic-ffi-4.rs:20:12 + | +LL | *ap0 = ap1; + | ^^^ lifetime mismatch + | + = note: expected type `core::ffi::VaListImpl<'_>` + found type `core::ffi::VaListImpl<'_>` +note: the anonymous lifetime #2 defined on the function body at 19:1... + --> $DIR/variadic-ffi-4.rs:19:1 + | +LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | | *ap0 = ap1; +LL | | +LL | | } + | |_^ +note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 19:1 + --> $DIR/variadic-ffi-4.rs:19:1 + | +LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | | *ap0 = ap1; +LL | | LL | | } | |_^ error[E0490]: a value of type `core::ffi::VaListImpl<'_>` is borrowed for too long - --> $DIR/variadic-ffi-4.rs:24:11 + --> $DIR/variadic-ffi-4.rs:25:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ | -note: the type is valid for the anonymous lifetime #1 defined on the function body at 23:1 - --> $DIR/variadic-ffi-4.rs:23:1 +note: the type is valid for the anonymous lifetime #1 defined on the function body at 24:1 + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -79,8 +106,8 @@ LL | | LL | | LL | | } | |_^ -note: but the borrow lasts for the anonymous lifetime #3 defined on the function body at 23:1 - --> $DIR/variadic-ffi-4.rs:23:1 +note: but the borrow lasts for the anonymous lifetime #3 defined on the function body at 24:1 + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -92,15 +119,15 @@ LL | | } | |_^ error[E0308]: mismatched types - --> $DIR/variadic-ffi-4.rs:24:11 + --> $DIR/variadic-ffi-4.rs:25:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ lifetime mismatch | = note: expected type `&mut core::ffi::VaListImpl<'_>` found type `&mut core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #3 defined on the function body at 23:1... - --> $DIR/variadic-ffi-4.rs:23:1 +note: the anonymous lifetime #3 defined on the function body at 24:1... + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -110,8 +137,8 @@ LL | | LL | | LL | | } | |_^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 23:1 - --> $DIR/variadic-ffi-4.rs:23:1 +note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 24:1 + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -123,15 +150,15 @@ LL | | } | |_^ error[E0308]: mismatched types - --> $DIR/variadic-ffi-4.rs:24:11 + --> $DIR/variadic-ffi-4.rs:25:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ lifetime mismatch | = note: expected type `&mut core::ffi::VaListImpl<'_>` found type `&mut core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #2 defined on the function body at 23:1... - --> $DIR/variadic-ffi-4.rs:23:1 +note: the anonymous lifetime #2 defined on the function body at 24:1... + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -141,8 +168,8 @@ LL | | LL | | LL | | } | |_^ -note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 23:1 - --> $DIR/variadic-ffi-4.rs:23:1 +note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 24:1 + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -154,13 +181,13 @@ LL | | } | |_^ error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements - --> $DIR/variadic-ffi-4.rs:24:11 + --> $DIR/variadic-ffi-4.rs:25:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the function body at 23:1... - --> $DIR/variadic-ffi-4.rs:23:1 +note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the function body at 24:1... + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -171,12 +198,12 @@ LL | | LL | | } | |_^ note: ...so that the type `core::ffi::VaListImpl<'_>` is not borrowed for too long - --> $DIR/variadic-ffi-4.rs:24:11 + --> $DIR/variadic-ffi-4.rs:25:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ -note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the function body at 23:1... - --> $DIR/variadic-ffi-4.rs:23:1 +note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the function body at 24:1... + --> $DIR/variadic-ffi-4.rs:24:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; @@ -187,39 +214,62 @@ LL | | LL | | } | |_^ note: ...so that reference does not outlive borrowed content - --> $DIR/variadic-ffi-4.rs:24:11 + --> $DIR/variadic-ffi-4.rs:25:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ -error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements - --> $DIR/variadic-ffi-4.rs:32:16 +error[E0308]: mismatched types + --> $DIR/variadic-ffi-4.rs:33:12 | LL | *ap0 = ap1.clone(); - | ^^^^^ + | ^^^^^^^^^^^ lifetime mismatch | -note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the function body at 31:1... - --> $DIR/variadic-ffi-4.rs:31:1 + = note: expected type `core::ffi::VaListImpl<'_>` + found type `core::ffi::VaListImpl<'_>` +note: the anonymous lifetime #3 defined on the function body at 32:1... + --> $DIR/variadic-ffi-4.rs:32:1 | LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1.clone(); +LL | | LL | | } | |_^ - = note: ...so that the types are compatible: - expected &core::ffi::VaListImpl<'_> - found &core::ffi::VaListImpl<'_> -note: but, the lifetime must be valid for the anonymous lifetime #2 defined on the function body at 31:1... - --> $DIR/variadic-ffi-4.rs:31:1 +note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 32:1 + --> $DIR/variadic-ffi-4.rs:32:1 | LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1.clone(); +LL | | +LL | | } + | |_^ + +error[E0308]: mismatched types + --> $DIR/variadic-ffi-4.rs:33:12 + | +LL | *ap0 = ap1.clone(); + | ^^^^^^^^^^^ lifetime mismatch + | + = note: expected type `core::ffi::VaListImpl<'_>` + found type `core::ffi::VaListImpl<'_>` +note: the anonymous lifetime #2 defined on the function body at 32:1... + --> $DIR/variadic-ffi-4.rs:32:1 + | +LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | | *ap0 = ap1.clone(); +LL | | +LL | | } + | |_^ +note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 32:1 + --> $DIR/variadic-ffi-4.rs:32:1 + | +LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | | *ap0 = ap1.clone(); +LL | | LL | | } | |_^ - = note: ...so that the expression is assignable: - expected core::ffi::VaListImpl<'_> - found core::ffi::VaListImpl<'_> -error: aborting due to 9 previous errors +error: aborting due to 11 previous errors Some errors have detailed explanations: E0308, E0621. For more information about an error, try `rustc --explain E0308`.