Skip to content

Commit

Permalink
Auto merge of rust-lang#74929 - Manishearth:rollup-z2vflrp, r=Manishe…
Browse files Browse the repository at this point in the history
…arth

Rollup of 10 pull requests

Successful merges:

 - rust-lang#74742 (Remove links to rejected errata 4406 for RFC 4291)
 - rust-lang#74819 (Point towards `format_spec`; it is in other direction)
 - rust-lang#74852 (Explain why inlining default ToString impl)
 - rust-lang#74869 (Make closures and generators a must use types)
 - rust-lang#74873 (symbol mangling: use ty::print::Print for consts)
 - rust-lang#74902 (Remove deprecated unstable `{Box,Rc,Arc}::into_raw_non_null` functions)
 - rust-lang#74904 (Fix some typos in src/librustdoc/clean/auto_trait.rs)
 - rust-lang#74910 (fence docs: fix example Mutex)
 - rust-lang#74912 (Fix broken link in unstable book `plugin`)
 - rust-lang#74927 (Change the target data layout to specify more values)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jul 30, 2020
2 parents 6b269e4 + f4f77d7 commit fb0b123
Show file tree
Hide file tree
Showing 47 changed files with 373 additions and 137 deletions.
46 changes: 1 addition & 45 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ use core::ops::{
CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver,
};
use core::pin::Pin;
use core::ptr::{self, NonNull, Unique};
use core::ptr::{self, Unique};
use core::task::{Context, Poll};

use crate::alloc::{self, AllocInit, AllocRef, Global};
Expand Down Expand Up @@ -451,50 +451,6 @@ impl<T: ?Sized> Box<T> {
Box::leak(b) as *mut T
}

/// Consumes the `Box`, returning the wrapped pointer as `NonNull<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
/// easiest way to do so is to convert the `NonNull<T>` pointer
/// into a raw pointer and 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_raw_non_null(b)`
/// instead of `b.into_raw_non_null()`. 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(box_into_raw_non_null)]
/// #![allow(deprecated)]
///
/// let x = Box::new(5);
/// let ptr = Box::into_raw_non_null(x);
///
/// // Clean up the memory by converting the NonNull pointer back
/// // into a Box and letting the Box be dropped.
/// let x = unsafe { Box::from_raw(ptr.as_ptr()) };
/// ```
#[unstable(feature = "box_into_raw_non_null", issue = "47336")]
#[rustc_deprecated(
since = "1.44.0",
reason = "use `Box::leak(b).into()` or `NonNull::from(Box::leak(b))` instead"
)]
#[inline]
pub fn into_raw_non_null(b: Box<T>) -> NonNull<T> {
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
// raw pointer for the type system. Turning it directly into a raw pointer would not be
// recognized as "releasing" the unique pointer to permit aliased raw accesses,
// so all raw pointer methods go through `leak` which creates a (unique)
// mutable reference. Turning *that* to a raw pointer behaves correctly.
Box::leak(b).into()
}

#[unstable(
feature = "ptr_internals",
issue = "none",
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
//! # Formatting Parameters
//!
//! Each argument being formatted can be transformed by a number of formatting
//! parameters (corresponding to `format_spec` in the syntax above). These
//! parameters (corresponding to `format_spec` in [the syntax](#syntax)). These
//! parameters affect the string representation of what's being formatted.
//!
//! ## Width
Expand Down
23 changes: 0 additions & 23 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,29 +645,6 @@ impl<T: ?Sized> Rc<T> {
unsafe { Self::from_ptr(rc_ptr) }
}

/// Consumes the `Rc`, returning the wrapped pointer as `NonNull<T>`.
///
/// # Examples
///
/// ```
/// #![feature(rc_into_raw_non_null)]
/// #![allow(deprecated)]
///
/// use std::rc::Rc;
///
/// let x = Rc::new("hello".to_owned());
/// let ptr = Rc::into_raw_non_null(x);
/// let deref = unsafe { ptr.as_ref() };
/// assert_eq!(deref, "hello");
/// ```
#[unstable(feature = "rc_into_raw_non_null", issue = "47336")]
#[rustc_deprecated(since = "1.44.0", reason = "use `Rc::into_raw` instead")]
#[inline]
pub fn into_raw_non_null(this: Self) -> NonNull<T> {
// safe because Rc guarantees its pointer is non-null
unsafe { NonNull::new_unchecked(Rc::into_raw(this) as *mut _) }
}

/// Creates a new [`Weak`][weak] pointer to this allocation.
///
/// [weak]: struct.Weak.html
Expand Down
3 changes: 3 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,9 @@ pub trait ToString {
/// since `fmt::Write for String` never returns an error itself.
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Display + ?Sized> ToString for T {
// A common guideline is to not inline generic functions. However,
// remove `#[inline]` from this method causes non-negligible regression.
// See <https://github.com/rust-lang/rust/pull/74852> as last attempt try to remove it.
#[inline]
default fn to_string(&self) -> String {
use fmt::Write;
Expand Down
23 changes: 0 additions & 23 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,29 +646,6 @@ impl<T: ?Sized> Arc<T> {
}
}

/// Consumes the `Arc`, returning the wrapped pointer as `NonNull<T>`.
///
/// # Examples
///
/// ```
/// #![feature(rc_into_raw_non_null)]
/// #![allow(deprecated)]
///
/// use std::sync::Arc;
///
/// let x = Arc::new("hello".to_owned());
/// let ptr = Arc::into_raw_non_null(x);
/// let deref = unsafe { ptr.as_ref() };
/// assert_eq!(deref, "hello");
/// ```
#[unstable(feature = "rc_into_raw_non_null", issue = "47336")]
#[rustc_deprecated(since = "1.44.0", reason = "use `Arc::into_raw` instead")]
#[inline]
pub fn into_raw_non_null(this: Self) -> NonNull<T> {
// safe because Arc guarantees its pointer is non-null
unsafe { NonNull::new_unchecked(Arc::into_raw(this) as *mut _) }
}

/// Creates a new [`Weak`][weak] pointer to this allocation.
///
/// [weak]: struct.Weak.html
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2649,7 +2649,8 @@ unsafe fn atomic_umin<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
/// }
///
/// pub fn lock(&self) {
/// while !self.flag.compare_and_swap(false, true, Ordering::Relaxed) {}
/// // Wait until the old value is `false`.
/// while self.flag.compare_and_swap(false, true, Ordering::Relaxed) != false {}
/// // This fence synchronizes-with store in `unlock`.
/// fence(Ordering::Acquire);
/// }
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,15 +1265,15 @@ impl Ipv6Addr {
/// # See also
///
/// - [IETF RFC 4291 section 2.5.6]
/// - [RFC 4291 errata 4406]
/// - [RFC 4291 errata 4406] (which has been rejected but provides useful
/// insight)
/// - [`is_unicast_link_local()`]
///
/// [IETF RFC 4291]: https://tools.ietf.org/html/rfc4291
/// [IETF RFC 4291 section 2.5.6]: https://tools.ietf.org/html/rfc4291#section-2.5.6
/// [`true`]: ../../std/primitive.bool.html
/// [RFC 4291 errata 4406]: https://www.rfc-editor.org/errata/eid4406
/// [`is_unicast_link_local()`]: ../../std/net/struct.Ipv6Addr.html#method.is_unicast_link_local
///
pub fn is_unicast_link_local_strict(&self) -> bool {
(self.segments()[0] & 0xffff) == 0xfe80
&& (self.segments()[1] & 0xffff) == 0
Expand Down Expand Up @@ -1324,13 +1324,13 @@ impl Ipv6Addr {
/// # See also
///
/// - [IETF RFC 4291 section 2.4]
/// - [RFC 4291 errata 4406]
/// - [RFC 4291 errata 4406] (which has been rejected but provides useful
/// insight)
///
/// [IETF RFC 4291 section 2.4]: https://tools.ietf.org/html/rfc4291#section-2.4
/// [`true`]: ../../std/primitive.bool.html
/// [RFC 4291 errata 4406]: https://www.rfc-editor.org/errata/eid4406
/// [`is_unicast_link_local_strict()`]: ../../std/net/struct.Ipv6Addr.html#method.is_unicast_link_local_strict
///
pub fn is_unicast_link_local(&self) -> bool {
(self.segments()[0] & 0xffc0) == 0xfe80
}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/language-features/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ of a library.
Plugins can extend [Rust's lint
infrastructure](../../reference/attributes/diagnostics.md#lint-check-attributes) with
additional checks for code style, safety, etc. Now let's write a plugin
[`lint_plugin_test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui-fulldeps/auxiliary/lint_plugin_test.rs)
[`lint-plugin-test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs)
that warns about any item named `lintme`.

```rust,ignore
Expand Down
22 changes: 22 additions & 0 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,28 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
// Otherwise, we don't lint, to avoid false positives.
_ => false,
},
ty::Closure(..) => {
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
let mut err = lint.build(&format!(
"unused {}closure{}{} that must be used",
descr_pre, plural_suffix, descr_post,
));
err.note("closures are lazy and do nothing unless called");
err.emit();
});
true
}
ty::Generator(..) => {
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
let mut err = lint.build(&format!(
"unused {}generator{}{} that must be used",
descr_pre, plural_suffix, descr_post,
));
err.note("generators are lazy and do nothing unless resumed");
err.emit();
});
true
}
_ => false,
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_symbol_mangling/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
}
GenericArgKind::Const(c) => {
self.push("K");
// FIXME(const_generics) implement `ty::print::Print` on `ty::Const`.
// self = c.print(self)?;
self = self.print_const(c)?;
self = c.print(self)?;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/thumbv4t_none_eabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn target() -> TargetResult {
* native integers are 32-bit
* All other elements are default
*/
data_layout: "e-S64-p:32:32-i64:64-m:e-n32".to_string(),
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
linker_flavor: LinkerFlavor::Ld,
options: TargetOptions {
linker: Some("arm-none-eabi-ld".to_string()),
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
}

// Converts the calculated ParamEnv and lifetime information to a clean::Generics, suitable for
// display on the docs page. Cleaning the Predicates produces sub-optimal WherePredicate's,
// display on the docs page. Cleaning the Predicates produces sub-optimal `WherePredicate`s,
// so we fix them up:
//
// * Multiple bounds for the same type are coalesced into one: e.g., 'T: Copy', 'T: Debug'
// becomes 'T: Copy + Debug'
// * Fn bounds are handled specially - instead of leaving it as 'T: Fn(), <T as Fn::Output> =
// K', we use the dedicated syntax 'T: Fn() -> K'
// * We explcitly add a '?Sized' bound if we didn't find any 'Sized' predicates for a type
// * We explicitly add a '?Sized' bound if we didn't find any 'Sized' predicates for a type
fn param_env_to_generics(
&self,
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -588,7 +588,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.args;

match args {
// Convert somethiung like '<T as Iterator::Item> = u8'
// Convert something like '<T as Iterator::Item> = u8'
// to 'T: Iterator<Item=u8>'
GenericArgs::AngleBracketed {
ref mut bindings, ..
Expand Down Expand Up @@ -712,7 +712,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
// since FxHasher has different behavior for 32-bit and 64-bit platforms.
//
// Obviously, it's extremely undesirable for documentation rendering
// to be depndent on the platform it's run on. Apart from being confusing
// to be dependent on the platform it's run on. Apart from being confusing
// to end users, it makes writing tests much more difficult, as predicates
// can appear in any order in the final result.
//
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/generator/issue-52398.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ impl A {
fn main() {
// Test that the MIR local with type &A created for the auto-borrow adjustment
// is caught by typeck
move || {
move || { //~ WARN unused generator that must be used
A.test(yield);
};

// Test that the std::cell::Ref temporary returned from the `borrow` call
// is caught by typeck
let y = RefCell::new(true);
static move || {
static move || { //~ WARN unused generator that must be used
yield *y.borrow();
return "Done";
};
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/generator/issue-52398.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
warning: unused generator that must be used
--> $DIR/issue-52398.rs:17:5
|
LL | / move || {
LL | | A.test(yield);
LL | | };
| |______^
|
= note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed

warning: unused generator that must be used
--> $DIR/issue-52398.rs:24:5
|
LL | / static move || {
LL | | yield *y.borrow();
LL | | return "Done";
LL | | };
| |______^
|
= note: generators are lazy and do nothing unless resumed

warning: 2 warnings emitted

2 changes: 1 addition & 1 deletion src/test/ui/generator/issue-57084.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where F: Fn() -> ()

fn main() {
let data = &vec![1];
|| {
|| { //~ WARN unused generator that must be used
let _to_pin = with(move || println!("{:p}", data));
loop {
yield
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/generator/issue-57084.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
warning: unused generator that must be used
--> $DIR/issue-57084.rs:22:5
|
LL | / || {
LL | | let _to_pin = with(move || println!("{:p}", data));
LL | | loop {
LL | | yield
LL | | }
LL | | };
| |______^
|
= note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion src/test/ui/generator/match-bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum Enum {
}

fn main() {
|| {
|| { //~ WARN unused generator that must be used
loop {
if let true = true {
match Enum::A(String::new()) {
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/generator/match-bindings.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
warning: unused generator that must be used
--> $DIR/match-bindings.rs:12:5
|
LL | / || {
LL | | loop {
LL | | if let true = true {
LL | | match Enum::A(String::new()) {
... |
LL | | }
LL | | };
| |______^
|
= note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion src/test/ui/generator/reborrow-mut-upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![feature(generators)]

fn _run(bar: &mut i32) {
|| {
|| { //~ WARN unused generator that must be used
{
let _baz = &*bar;
yield;
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/generator/reborrow-mut-upvar.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
warning: unused generator that must be used
--> $DIR/reborrow-mut-upvar.rs:6:5
|
LL | / || {
LL | | {
LL | | let _baz = &*bar;
LL | | yield;
... |
LL | | *bar = 2;
LL | | };
| |______^
|
= note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed

warning: 1 warning emitted

Loading

0 comments on commit fb0b123

Please sign in to comment.