From d259f4364738d911128d6e8ad863d0066733a343 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 20 Jun 2018 00:04:59 +0200 Subject: Fix doc build on unknown windows target --- src/libstd/sys/mod.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/sys/mod.rs b/src/libstd/sys/mod.rs index 1231898ed7e..b5bf4044be4 100644 --- a/src/libstd/sys/mod.rs +++ b/src/libstd/sys/mod.rs @@ -67,6 +67,7 @@ cfg_if! { // (missing things in `libc` which is empty) so just omit everything // with an empty module #[unstable(issue = "0", feature = "std_internals")] + #[allow(missing_docs)] pub mod unix_ext {} } else { // On other platforms like Windows document the bare bones of unix @@ -80,6 +81,7 @@ cfg_if! { cfg_if! { if #[cfg(windows)] { // On windows we'll just be documenting what's already available + #[allow(missing_docs)] pub use self::ext as windows_ext; } else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] { // On CloudABI and wasm right now the shim below doesn't compile, so -- cgit 1.4.1-3-g733a5 From 3bcb85ee658e7a5362f5e381c337f07381f916dc Mon Sep 17 00:00:00 2001 From: Josef Reinhard Brandl Date: Sat, 23 Jun 2018 13:32:53 +0200 Subject: `PinMut`: Add safe `get_mut` and rename unsafe fns to `get_mut_unchecked` and `map_unchecked` --- src/libcore/mem.rs | 14 ++++++++++---- src/libcore/option.rs | 2 +- src/libstd/future.rs | 2 +- src/libstd/panic.rs | 11 +++-------- 4 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 31635ffa53c..08bd9289ab4 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -1119,6 +1119,12 @@ impl<'a, T: ?Sized + Unpin> PinMut<'a, T> { pub fn new(reference: &'a mut T) -> PinMut<'a, T> { PinMut { inner: reference } } + + /// Get a mutable reference to the data inside of this `PinMut`. + #[unstable(feature = "pin", issue = "49150")] + pub fn get_mut(this: PinMut<'a, T>) -> &'a mut T { + this.inner + } } @@ -1150,21 +1156,21 @@ impl<'a, T: ?Sized> PinMut<'a, T> { /// the data out of the mutable reference you receive when you call this /// function. #[unstable(feature = "pin", issue = "49150")] - pub unsafe fn get_mut(this: PinMut<'a, T>) -> &'a mut T { + pub unsafe fn get_mut_unchecked(this: PinMut<'a, T>) -> &'a mut T { this.inner } /// Construct a new pin by mapping the interior value. /// - /// For example, if you wanted to get a `PinMut` of a field of something, you - /// could use this to get access to that field in one line of code. + /// For example, if you wanted to get a `PinMut` of a field of something, + /// you could use this to get access to that field in one line of code. /// /// This function is unsafe. You must guarantee that the data you return /// will not move so long as the argument value does not move (for example, /// because it is one of the fields of that value), and also that you do /// not move out of the argument you receive to the interior function. #[unstable(feature = "pin", issue = "49150")] - pub unsafe fn map(this: PinMut<'a, T>, f: F) -> PinMut<'a, U> where + pub unsafe fn map_unchecked(this: PinMut<'a, T>, f: F) -> PinMut<'a, U> where F: FnOnce(&mut T) -> &mut U { PinMut { inner: f(this.inner) } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 1e615042a6d..70979f631cd 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -275,7 +275,7 @@ impl Option { #[unstable(feature = "pin", issue = "49150")] pub fn as_pin_mut<'a>(self: PinMut<'a, Self>) -> Option> { unsafe { - PinMut::get_mut(self).as_mut().map(|x| PinMut::new_unchecked(x)) + PinMut::get_mut_unchecked(self).as_mut().map(|x| PinMut::new_unchecked(x)) } } diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 2da775fdc94..c1cc36f3b41 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -43,7 +43,7 @@ impl> !Unpin for GenFuture {} impl> Future for GenFuture { type Output = T::Return; fn poll(self: PinMut, cx: &mut task::Context) -> Poll { - set_task_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } { + set_task_cx(cx, || match unsafe { PinMut::get_mut_unchecked(self).0.resume() } { GeneratorState::Yielded(()) => Poll::Pending, GeneratorState::Complete(x) => Poll::Ready(x), }) diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 2c11c262488..451420ae88a 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -327,14 +327,9 @@ impl fmt::Debug for AssertUnwindSafe { impl<'a, F: Future> Future for AssertUnwindSafe { type Output = F::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { - unsafe { - let pinned_field = PinMut::new_unchecked( - &mut PinMut::get_mut(self.reborrow()).0 - ); - - pinned_field.poll(cx) - } + fn poll(self: PinMut, cx: &mut task::Context) -> Poll { + let pinned_field = unsafe { PinMut::map_unchecked(self, |x| &mut x.0) }; + pinned_field.poll(cx) } } -- cgit 1.4.1-3-g733a5 From 2d3c369d87af9f8c7c3a718882762bc8896d5a31 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Tue, 29 May 2018 10:06:13 +0200 Subject: Link the docs of panic!() and compile_error!() Fixes #47275. These two macros are similar, but different, and could do with documentation links to each other. --- src/libstd/macros.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index a856e7736fb..935102f8355 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -38,10 +38,13 @@ /// The multi-argument form of this macro panics with a string and has the /// [`format!`] syntax for building a string. /// +/// See also the macro [`compile_error!`], for raising errors during compilation. +/// /// [runwrap]: ../std/result/enum.Result.html#method.unwrap /// [`Option`]: ../std/option/enum.Option.html#method.unwrap /// [`Result`]: ../std/result/enum.Result.html /// [`format!`]: ../std/macro.format.html +/// [`compile_error!`]: ../std/macro.compile_error.html /// [book]: ../book/second-edition/ch09-01-unrecoverable-errors-with-panic.html /// /// # Current implementation @@ -305,7 +308,8 @@ pub mod builtin { /// Unconditionally causes compilation to fail with the given error message when encountered. /// /// This macro should be used when a crate uses a conditional compilation strategy to provide - /// better error messages for erroneous conditions. + /// better error messages for erroneous conditions. It's the compiler-level form of [`panic!`], + /// which emits an error at *runtime*, rather than during compilation. /// /// # Examples /// @@ -332,6 +336,8 @@ pub mod builtin { /// #[cfg(not(any(feature = "foo", feature = "bar")))] /// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.") /// ``` + /// + /// [`panic!`]: ../std/macro.panic.html #[stable(feature = "compile_error_macro", since = "1.20.0")] #[macro_export] macro_rules! compile_error { -- cgit 1.4.1-3-g733a5 From f85ddfbc3f25b73d41aa9db332dcd72bf70cd985 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Tue, 29 May 2018 10:07:14 +0200 Subject: Add sentence to compile_error!() docs It now details why using compile_error!() is different from just not having the final macro_rules!() branch. --- src/libstd/macros.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 935102f8355..75f038407c1 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -315,7 +315,9 @@ pub mod builtin { /// /// Two such examples are macros and `#[cfg]` environments. /// - /// Emit better compiler error if a macro is passed invalid values. + /// Emit better compiler error if a macro is passed invalid values. Without the final branch, + /// the compiler would still emit an error, but the error's message would not mention the two + /// valid values. /// /// ```compile_fail /// macro_rules! give_me_foo_or_bar { -- cgit 1.4.1-3-g733a5 From 3c6c18d095b7cdafadffcc7ae3c39b037e4e793d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Jun 2018 20:38:29 +0200 Subject: Add missing \[allow(missing_docs)\] --- src/libstd/sys/mod.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd') diff --git a/src/libstd/sys/mod.rs b/src/libstd/sys/mod.rs index b5bf4044be4..c44db3b1072 100644 --- a/src/libstd/sys/mod.rs +++ b/src/libstd/sys/mod.rs @@ -87,6 +87,7 @@ cfg_if! { // On CloudABI and wasm right now the shim below doesn't compile, so // just omit it #[unstable(issue = "0", feature = "std_internals")] + #[allow(missing_docs)] pub mod windows_ext {} } else { // On all other platforms (aka linux/osx/etc) then pull in a "minimal" -- cgit 1.4.1-3-g733a5 From 490f49fd2ab15ae25a6ffeae2de8f667a521f19d Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 25 Jun 2018 12:34:33 -0700 Subject: Remove unnecessary stat64 pointer casts In effect, these just casted `&mut stat64` to `*mut stat64`, twice. That's harmless, but it masked a problem when this was copied to new code calling `fstatat`, which takes a pointer to `struct stat`. That will be fixed by #51785, but let's remove the unnecessary casts here too. --- src/libstd/sys/unix/fs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 774340388e1..93e2f4425b6 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -787,7 +787,7 @@ pub fn stat(p: &Path) -> io::Result { let p = cstr(p)?; let mut stat: stat64 = unsafe { mem::zeroed() }; cvt(unsafe { - stat64(p.as_ptr(), &mut stat as *mut _ as *mut _) + stat64(p.as_ptr(), &mut stat) })?; Ok(FileAttr { stat: stat }) } @@ -796,7 +796,7 @@ pub fn lstat(p: &Path) -> io::Result { let p = cstr(p)?; let mut stat: stat64 = unsafe { mem::zeroed() }; cvt(unsafe { - lstat64(p.as_ptr(), &mut stat as *mut _ as *mut _) + lstat64(p.as_ptr(), &mut stat) })?; Ok(FileAttr { stat: stat }) } -- cgit 1.4.1-3-g733a5