From eb703f78515db10854d290b2f16e332cbc1c510d Mon Sep 17 00:00:00 2001 From: Florian Hartwig Date: Wed, 17 May 2017 21:27:58 +0200 Subject: [PATCH 1/9] Fix off-by-one error in column number in `explain_span`. --- src/librustc/infer/error_reporting/mod.rs | 2 +- src/test/compile-fail/issue-27942.rs | 4 ++-- .../ex1-return-one-existing-name-if-else.stderr | 4 ++-- .../ui/lifetime-errors/ex2a-push-one-existing-name.stderr | 4 ++-- .../ui/lifetime-errors/ex2b-push-no-existing-names.stderr | 4 ++-- .../ui/lifetime-errors/ex2c-push-inference-variable.stderr | 4 ++-- .../ui/lifetime-errors/ex2d-push-inference-variable-2.stderr | 4 ++-- .../ui/lifetime-errors/ex2e-push-inference-variable-3.stderr | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index c07b3b3c4be90..0515e1cc30435 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -113,7 +113,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { heading: &str, span: Span) -> (String, Option) { let lo = tcx.sess.codemap().lookup_char_pos_adj(span.lo); - (format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize()), + (format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1), Some(span)) } diff --git a/src/test/compile-fail/issue-27942.rs b/src/test/compile-fail/issue-27942.rs index 22e7de3838dc1..0fa4184606e45 100644 --- a/src/test/compile-fail/issue-27942.rs +++ b/src/test/compile-fail/issue-27942.rs @@ -11,7 +11,7 @@ pub trait Resources<'a> {} pub trait Buffer<'a, R: Resources<'a>> { - //~^ NOTE the lifetime 'a as defined on the trait at 13:0... + //~^ NOTE the lifetime 'a as defined on the trait at 13:1... //~| NOTE ...does not necessarily outlive the lifetime 'a as defined on the trait fn select(&self) -> BufferViewHandle; @@ -22,7 +22,7 @@ pub trait Buffer<'a, R: Resources<'a>> { //~| ERROR mismatched types //~| lifetime mismatch //~| NOTE expected type `Resources<'_>` - //~| NOTE the anonymous lifetime #1 defined on the method body at 17:4... + //~| NOTE the anonymous lifetime #1 defined on the method body at 17:5... } pub struct BufferViewHandle<'a, R: 'a+Resources<'a>>(&'a R); diff --git a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.stderr b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.stderr index 55723ee8cd964..f325d10b54873 100644 --- a/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.stderr +++ b/src/test/ui/lifetime-errors/ex1-return-one-existing-name-if-else.stderr @@ -4,14 +4,14 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... 12 | if x > y { x } else { y } | ^ | -note: ...the reference is valid for the lifetime 'a as defined on the function body at 11:0... +note: ...the reference is valid for the lifetime 'a as defined on the function body at 11:1... --> $DIR/ex1-return-one-existing-name-if-else.rs:11:1 | 11 | / fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { 12 | | if x > y { x } else { y } 13 | | } | |_^ -note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the function body at 11:0 +note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the function body at 11:1 --> $DIR/ex1-return-one-existing-name-if-else.rs:11:1 | 11 | / fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { diff --git a/src/test/ui/lifetime-errors/ex2a-push-one-existing-name.stderr b/src/test/ui/lifetime-errors/ex2a-push-one-existing-name.stderr index b7d985feca9f2..df484a14927c7 100644 --- a/src/test/ui/lifetime-errors/ex2a-push-one-existing-name.stderr +++ b/src/test/ui/lifetime-errors/ex2a-push-one-existing-name.stderr @@ -6,14 +6,14 @@ error[E0308]: mismatched types | = note: expected type `Ref<'a, _>` found type `Ref<'_, _>` -note: the anonymous lifetime #2 defined on the function body at 15:0... +note: the anonymous lifetime #2 defined on the function body at 15:1... --> $DIR/ex2a-push-one-existing-name.rs:15:1 | 15 | / fn foo<'a>(x: &mut Vec>, y: Ref) { 16 | | x.push(y); 17 | | } | |_^ -note: ...does not necessarily outlive the lifetime 'a as defined on the function body at 15:0 +note: ...does not necessarily outlive the lifetime 'a as defined on the function body at 15:1 --> $DIR/ex2a-push-one-existing-name.rs:15:1 | 15 | / fn foo<'a>(x: &mut Vec>, y: Ref) { diff --git a/src/test/ui/lifetime-errors/ex2b-push-no-existing-names.stderr b/src/test/ui/lifetime-errors/ex2b-push-no-existing-names.stderr index 3a6e94f2b1c2e..6764c58f4bb59 100644 --- a/src/test/ui/lifetime-errors/ex2b-push-no-existing-names.stderr +++ b/src/test/ui/lifetime-errors/ex2b-push-no-existing-names.stderr @@ -6,14 +6,14 @@ error[E0308]: mismatched types | = note: expected type `Ref<'_, _>` found type `Ref<'_, _>` -note: the anonymous lifetime #3 defined on the function body at 15:0... +note: the anonymous lifetime #3 defined on the function body at 15:1... --> $DIR/ex2b-push-no-existing-names.rs:15:1 | 15 | / fn foo(x: &mut Vec>, y: Ref) { 16 | | x.push(y); 17 | | } | |_^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 15:0 +note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 15:1 --> $DIR/ex2b-push-no-existing-names.rs:15:1 | 15 | / fn foo(x: &mut Vec>, y: Ref) { diff --git a/src/test/ui/lifetime-errors/ex2c-push-inference-variable.stderr b/src/test/ui/lifetime-errors/ex2c-push-inference-variable.stderr index 3d7064a4f71a3..7356fc11862f6 100644 --- a/src/test/ui/lifetime-errors/ex2c-push-inference-variable.stderr +++ b/src/test/ui/lifetime-errors/ex2c-push-inference-variable.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d 16 | let z = Ref { data: y.data }; | ^^^ | -note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:0... +note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:1... --> $DIR/ex2c-push-inference-variable.rs:15:1 | 15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec>, y: Ref<'c, i32>) { @@ -17,7 +17,7 @@ note: ...so that reference does not outlive borrowed content | 16 | let z = Ref { data: y.data }; | ^^^^^^ -note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:0... +note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:1... --> $DIR/ex2c-push-inference-variable.rs:15:1 | 15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec>, y: Ref<'c, i32>) { diff --git a/src/test/ui/lifetime-errors/ex2d-push-inference-variable-2.stderr b/src/test/ui/lifetime-errors/ex2d-push-inference-variable-2.stderr index aced855bf669b..38b0acf9339e0 100644 --- a/src/test/ui/lifetime-errors/ex2d-push-inference-variable-2.stderr +++ b/src/test/ui/lifetime-errors/ex2d-push-inference-variable-2.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d 17 | let b = Ref { data: y.data }; | ^^^ | -note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:0... +note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:1... --> $DIR/ex2d-push-inference-variable-2.rs:15:1 | 15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec>, y: Ref<'c, i32>) { @@ -18,7 +18,7 @@ note: ...so that reference does not outlive borrowed content | 17 | let b = Ref { data: y.data }; | ^^^^^^ -note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:0... +note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:1... --> $DIR/ex2d-push-inference-variable-2.rs:15:1 | 15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec>, y: Ref<'c, i32>) { diff --git a/src/test/ui/lifetime-errors/ex2e-push-inference-variable-3.stderr b/src/test/ui/lifetime-errors/ex2e-push-inference-variable-3.stderr index 07e2316b63d8c..035e516e8628e 100644 --- a/src/test/ui/lifetime-errors/ex2e-push-inference-variable-3.stderr +++ b/src/test/ui/lifetime-errors/ex2e-push-inference-variable-3.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d 17 | let b = Ref { data: y.data }; | ^^^ | -note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:0... +note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:1... --> $DIR/ex2e-push-inference-variable-3.rs:15:1 | 15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec>, y: Ref<'c, i32>) { @@ -18,7 +18,7 @@ note: ...so that reference does not outlive borrowed content | 17 | let b = Ref { data: y.data }; | ^^^^^^ -note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:0... +note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:1... --> $DIR/ex2e-push-inference-variable-3.rs:15:1 | 15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec>, y: Ref<'c, i32>) { From fb195600541c67f91cd6aed5c1d00aa4668ad9c3 Mon Sep 17 00:00:00 2001 From: Dylan Maccora Date: Thu, 18 May 2017 18:26:47 +1000 Subject: [PATCH 2/9] std::env docs --- src/libstd/env.rs | 53 +++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 64eb52e28bc42..061525205ef71 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -13,6 +13,13 @@ //! This module contains functions to inspect various aspects such as //! environment variables, process arguments, the current directory, and various //! other important directories. +//! +//! There are several functions and structs in this module that have a +//! counterpart ending in `os`. Those ending in `os` will return an [`OsString`] +//! and those without will be returning a [`String`]. +//! +//! [`OsString`]: ../../std/ffi/struct.OsString.html +//! [`String`]: ../string/struct.String.html #![stable(feature = "env", since = "1.0.0")] @@ -71,7 +78,8 @@ pub fn set_current_dir>(p: P) -> io::Result<()> { /// An iterator over a snapshot of the environment variables of this process. /// -/// This structure is created through the [`std::env::vars`] function. +/// This structure is created by the [`std::env::vars`] function. See its +/// documentation for more. /// /// [`std::env::vars`]: fn.vars.html #[stable(feature = "env", since = "1.0.0")] @@ -79,7 +87,8 @@ pub struct Vars { inner: VarsOs } /// An iterator over a snapshot of the environment variables of this process. /// -/// This structure is created through the [`std::env::vars_os`] function. +/// This structure is created by the [`std::env::vars_os`] function. See +/// its documentation for more. /// /// [`std::env::vars_os`]: fn.vars_os.html #[stable(feature = "env", since = "1.0.0")] @@ -173,12 +182,10 @@ impl fmt::Debug for VarsOs { /// Fetches the environment variable `key` from the current process. /// -/// The returned result is [`Ok(s)`] if the environment variable is present and is -/// valid unicode. If the environment variable is not present, or it is not -/// valid unicode, then [`Err`] will be returned. +/// # Errors /// -/// [`Ok(s)`]: ../result/enum.Result.html#variant.Ok -/// [`Err`]: ../result/enum.Result.html#variant.Err +/// * Environment variable is not present +/// * Environment variable is not valid unicode /// /// # Examples /// @@ -230,7 +237,8 @@ fn _var_os(key: &OsStr) -> Option { }) } -/// Possible errors from the [`env::var`] function. +/// The error type for operations interacting with environment variables. +/// Possibly returned from the [`env::var`] function. /// /// [`env::var`]: fn.var.html #[derive(Debug, PartialEq, Eq, Clone)] @@ -353,10 +361,13 @@ fn _remove_var(k: &OsStr) { }) } -/// An iterator over `PathBuf` instances for parsing an environment variable -/// according to platform-specific conventions. +/// An iterator that splits an environment variable into paths according to +/// platform-specific conventions. /// -/// This structure is returned from `std::env::split_paths`. +/// This structure is created by the [`std::env::split_paths`] function See its +/// documentation for more. +/// +/// [`std::env::split_paths`]: fn.split_paths.html #[stable(feature = "env", since = "1.0.0")] pub struct SplitPaths<'a> { inner: os_imp::SplitPaths<'a> } @@ -399,8 +410,10 @@ impl<'a> fmt::Debug for SplitPaths<'a> { } } -/// Error type returned from `std::env::join_paths` when paths fail to be -/// joined. +/// The error type for operations on the `PATH` variable. Possibly returned from +/// the [`env::join_paths`] function. +/// +/// [`env::join_paths`]: fn.join_paths.html #[derive(Debug)] #[stable(feature = "env", since = "1.0.0")] pub struct JoinPathsError { @@ -410,15 +423,15 @@ pub struct JoinPathsError { /// Joins a collection of [`Path`]s appropriately for the `PATH` /// environment variable. /// -/// Returns an [`OsString`] on success. +/// # Errors /// -/// Returns an [`Err`][err] (containing an error message) if one of the input +/// Returns an [`Err`] (containing an error message) if one of the input /// [`Path`]s contains an invalid character for constructing the `PATH` /// variable (a double quote on Windows or a colon on Unix). /// /// [`Path`]: ../../std/path/struct.Path.html /// [`OsString`]: ../../std/ffi/struct.OsString.html -/// [err]: ../../std/result/enum.Result.html#variant.Err +/// [`Err`]: ../../std/result/enum.Result.html#variant.Err /// /// # Examples /// @@ -490,12 +503,16 @@ pub fn home_dir() -> Option { /// Returns the path of a temporary directory. /// -/// On Unix, returns the value of the `TMPDIR` environment variable if it is +/// # Unix +/// +/// Returns the value of the `TMPDIR` environment variable if it is /// set, otherwise for non-Android it returns `/tmp`. If Android, since there /// is no global temporary folder (it is usually allocated per-app), it returns /// `/data/local/tmp`. /// -/// On Windows, returns the value of, in order, the `TMP`, `TEMP`, +/// # Windows +/// +/// Returns the value of, in order, the `TMP`, `TEMP`, /// `USERPROFILE` environment variable if any are set and not the empty /// string. Otherwise, `temp_dir` returns the path of the Windows directory. /// This behavior is identical to that of [`GetTempPath`][msdn], which this From fc513861b114dbe9c9c5440c72838b2623a91bb6 Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Fri, 19 May 2017 01:20:48 +0200 Subject: [PATCH 3/9] fix some clippy warnings in librustc_errors --- src/librustc_errors/diagnostic_builder.rs | 4 ++-- src/librustc_errors/emitter.rs | 6 ++---- src/librustc_errors/lib.rs | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index fc5fd44f091f1..0081339a363f7 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -192,8 +192,8 @@ impl<'a> Debug for DiagnosticBuilder<'a> { } } -/// Destructor bomb - a DiagnosticBuilder must be either emitted or cancelled or -/// we emit a bug. +/// Destructor bomb - a `DiagnosticBuilder` must be either emitted or cancelled +/// or we emit a bug. impl<'a> Drop for DiagnosticBuilder<'a> { fn drop(&mut self) { if !panicking() && !self.cancelled() { diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 03f1b94b16937..a9645f9ab7bb2 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1296,10 +1296,8 @@ impl Write for BufferedWriter { } fn flush(&mut self) -> io::Result<()> { let mut stderr = io::stderr(); - let result = (|| { - stderr.write_all(&self.buffer)?; - stderr.flush() - })(); + let result = stderr.write_all(&self.buffer) + .and_then(|_| stderr.flush()); self.buffer.clear(); result } diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 7a561e3a9703f..c91dc9d87978d 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -383,7 +383,7 @@ impl Handler { pub fn span_fatal>(&self, sp: S, msg: &str) -> FatalError { self.emit(&sp.into(), msg, Fatal); self.panic_if_treat_err_as_bug(); - return FatalError; + FatalError } pub fn span_fatal_with_code>(&self, sp: S, @@ -392,7 +392,7 @@ impl Handler { -> FatalError { self.emit_with_code(&sp.into(), msg, code, Fatal); self.panic_if_treat_err_as_bug(); - return FatalError; + FatalError } pub fn span_err>(&self, sp: S, msg: &str) { self.emit(&sp.into(), msg, Error); From e4f9db7b8f36edcc5bc3d9d0e18d7fb0f6b55bc1 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 18 May 2017 23:33:08 -0500 Subject: [PATCH 4/9] core: fix unused_macro warning when compiling the crate for a target with max-atomic-width = 0 fixes #42097 --- src/libcore/sync/atomic.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index c13fd5583543e..d647a94a1efde 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -918,6 +918,7 @@ impl AtomicPtr { } } +#[cfg(target_has_atomic = "ptr")] macro_rules! atomic_int { ($stable:meta, $stable_cxchg:meta, From b69b6413afc770a8652096e8753d77eeb99b23bb Mon Sep 17 00:00:00 2001 From: Dylan Maccora Date: Sat, 20 May 2017 08:32:10 +1000 Subject: [PATCH 5/9] Fixed link issue. --- src/libstd/env.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 061525205ef71..40ed5b5e1c08c 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -425,13 +425,13 @@ pub struct JoinPathsError { /// /// # Errors /// -/// Returns an [`Err`] (containing an error message) if one of the input +/// Returns an [`Err`][err] (containing an error message) if one of the input /// [`Path`]s contains an invalid character for constructing the `PATH` /// variable (a double quote on Windows or a colon on Unix). /// /// [`Path`]: ../../std/path/struct.Path.html /// [`OsString`]: ../../std/ffi/struct.OsString.html -/// [`Err`]: ../../std/result/enum.Result.html#variant.Err +/// [err]: ../../std/result/enum.Result.html#variant.Err /// /// # Examples /// From 6119f9856cd7ed514656c19b56da65ea7bd7dd0a Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Sat, 20 May 2017 15:32:11 -0400 Subject: [PATCH 6/9] Remove unused lifetimes. --- src/libstd/ffi/os_str.rs | 2 +- src/libstd/path.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index eaf0502a577d9..f497734e249c5 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -530,7 +530,7 @@ impl<'a> From<&'a OsStr> for Box { } #[stable(feature = "os_string_from_box", since = "1.18.0")] -impl<'a> From> for OsString { +impl From> for OsString { fn from(boxed: Box) -> OsString { boxed.into_os_string() } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index e7d8c3007f692..e128a4164d74a 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1342,7 +1342,7 @@ impl<'a> From<&'a Path> for Box { } #[stable(feature = "path_buf_from_box", since = "1.18.0")] -impl<'a> From> for PathBuf { +impl From> for PathBuf { fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() } From 892df1db60c3c81c57899ef3712b43f63d971b25 Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Wed, 10 May 2017 12:48:36 -0400 Subject: [PATCH 7/9] expose needs_drop under mem:: --- src/libcore/mem.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index b397aba6b92df..18428d378e3d2 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -302,6 +302,58 @@ pub fn align_of_val(val: &T) -> usize { unsafe { intrinsics::min_align_of_val(val) } } +/// Returns whether dropping values of type `T` matters. +/// +/// This is purely an optimization hint, and may be implemented conservatively. +/// For instance, always returning `true` would be a valid implementation of +/// this function. +/// +/// Low level implementations of things like collections, which need to manually +/// drop their data, should use this function to avoid unnecessarily +/// trying to drop all their contents when they are destroyed. This might not +/// make a difference in release builds (where a loop that has no side-effects +/// is easily detected and eliminated), but is often a big win for debug builds. +/// +/// Note that `ptr::drop_in_place` already performs this check, so if your workload +/// can be reduced to some small number of drop_in_place calls, using this is +/// unnecessary. In particular note that you can drop_in_place a slice, and that +/// will do a single needs_drop check for all the values. +/// +/// Types like Vec therefore just `drop_in_place(&mut self[..])` without using +/// needs_drop explicitly. Types like HashMap, on the other hand, have to drop +/// values one at a time and should use this API. +/// +/// +/// # Examples +/// +/// Here's an example of how a collection might make use of needs_drop: +/// +/// ```ignore +/// #![feature(needs_drop)] +/// use std::{mem, ptr}; +/// +/// pub struct MyCollection { /* ... */ } +/// +/// impl Drop for MyCollection { +/// fn drop(&mut self) { +/// unsafe { +/// // drop the data +/// if mem::needs_drop::() { +/// for x in self.iter_mut() { +/// ptr::drop_in_place(x); +/// } +/// } +/// self.free_buffer(); +/// } +/// } +/// } +/// ``` +#[inline] +#[unstable(feature = "needs_drop", issue = "41890")] +pub fn needs_drop() -> bool { + unsafe { intrinsics::needs_drop::() } +} + /// Creates a value whose bytes are all zero. /// /// This has the same effect as allocating space with From e847d46bcb01c71e18610eeb30db6f2b6a7f3214 Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Wed, 10 May 2017 13:13:42 -0400 Subject: [PATCH 8/9] migrate everything to using mem::needs_drop --- src/libarena/lib.rs | 9 ++++----- src/libstd/collections/hash/table.rs | 3 +-- src/libstd/lib.rs | 1 + src/libstd/sys/redox/fast_thread_local.rs | 7 ++++--- src/libstd/sys/unix/fast_thread_local.rs | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index c4c1635aa2a5a..4338ac7fd022c 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -32,6 +32,7 @@ #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(generic_param_attrs)] +#![feature(needs_drop)] #![cfg_attr(stage0, feature(staged_api))] #![cfg_attr(test, feature(test))] @@ -82,7 +83,7 @@ impl TypedArenaChunk { unsafe fn destroy(&mut self, len: usize) { // The branch on needs_drop() is an -O1 performance optimization. // Without the branch, dropping TypedArena takes linear time. - if intrinsics::needs_drop::() { + if mem::needs_drop::() { let mut start = self.start(); // Destroy all allocated objects. for _ in 0..len { @@ -350,7 +351,7 @@ impl DroplessArena { #[inline] pub fn alloc(&self, object: T) -> &mut T { unsafe { - assert!(!intrinsics::needs_drop::()); + assert!(!mem::needs_drop::()); assert!(mem::size_of::() != 0); self.align_for::(); @@ -379,9 +380,7 @@ impl DroplessArena { #[inline] pub fn alloc_slice(&self, slice: &[T]) -> &mut [T] where T: Copy { - unsafe { - assert!(!intrinsics::needs_drop::()); - } + assert!(!mem::needs_drop::()); assert!(mem::size_of::() != 0); assert!(slice.len() != 0); self.align_for::(); diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index a15269cc87c5d..50c721db849aa 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -12,9 +12,8 @@ use alloc::heap::{allocate, deallocate}; use cmp; use hash::{BuildHasher, Hash, Hasher}; -use intrinsics::needs_drop; use marker; -use mem::{align_of, size_of}; +use mem::{align_of, size_of, needs_drop}; use mem; use ops::{Deref, DerefMut}; use ptr::{self, Unique, Shared}; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a4c3b276efdd2..b0820d6f05a05 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -281,6 +281,7 @@ #![feature(linkage)] #![feature(macro_reexport)] #![feature(needs_panic_runtime)] +#![feature(needs_drop)] #![feature(never_type)] #![feature(num_bits_bytes)] #![feature(old_wrapping)] diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index f6414673dace1..7dc61ce6654b9 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -12,9 +12,10 @@ #![unstable(feature = "thread_local_internals", issue = "0")] use cell::{Cell, UnsafeCell}; -use intrinsics; +use mem; use ptr; + pub struct Key { inner: UnsafeCell>, @@ -37,7 +38,7 @@ impl Key { pub fn get(&'static self) -> Option<&'static UnsafeCell>> { unsafe { - if intrinsics::needs_drop::() && self.dtor_running.get() { + if mem::needs_drop::() && self.dtor_running.get() { return None } self.register_dtor(); @@ -46,7 +47,7 @@ impl Key { } unsafe fn register_dtor(&self) { - if !intrinsics::needs_drop::() || self.dtor_registered.get() { + if !mem::needs_drop::() || self.dtor_registered.get() { return } diff --git a/src/libstd/sys/unix/fast_thread_local.rs b/src/libstd/sys/unix/fast_thread_local.rs index 07d76a93dd150..6b3973de84c97 100644 --- a/src/libstd/sys/unix/fast_thread_local.rs +++ b/src/libstd/sys/unix/fast_thread_local.rs @@ -13,7 +13,7 @@ use cell::{Cell, UnsafeCell}; use fmt; -use intrinsics; +use mem; use ptr; pub struct Key { @@ -44,7 +44,7 @@ impl Key { pub fn get(&'static self) -> Option<&'static UnsafeCell>> { unsafe { - if intrinsics::needs_drop::() && self.dtor_running.get() { + if mem::needs_drop::() && self.dtor_running.get() { return None } self.register_dtor(); @@ -53,7 +53,7 @@ impl Key { } unsafe fn register_dtor(&self) { - if !intrinsics::needs_drop::() || self.dtor_registered.get() { + if !mem::needs_drop::() || self.dtor_registered.get() { return } From 1f01b09ddcd5d5ab0927528b1db0962b4310e3fc Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Thu, 11 May 2017 10:15:56 -0400 Subject: [PATCH 9/9] Add stub entry to unstable book for needs_drop --- src/doc/unstable-book/src/library-features/needs-drop.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/doc/unstable-book/src/library-features/needs-drop.md diff --git a/src/doc/unstable-book/src/library-features/needs-drop.md b/src/doc/unstable-book/src/library-features/needs-drop.md new file mode 100644 index 0000000000000..10ae95695a2db --- /dev/null +++ b/src/doc/unstable-book/src/library-features/needs-drop.md @@ -0,0 +1,7 @@ +# `needs_drop` + +The tracking issue for this feature is: [#41890] + +[#41890]: https://github.com/rust-lang/rust/issues/41890 + +------------------------