Skip to content

Commit

Permalink
Auto merge of rust-lang#83454 - JohnTitor:rollup-9ae0565, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - rust-lang#83041 (stabilize debug_non_exhaustive)
 - rust-lang#83349 (Remove Option::{unwrap_none, expect_none}.)
 - rust-lang#83420 (Add documentation for rustdoc-gui tests)
 - rust-lang#83421 (Add Result::into_err where the Ok variant is the never type)
 - rust-lang#83427 (small cleanups in rustc_errors / emitter)
 - rust-lang#83434 (Update RELEASES.md)
 - rust-lang#83440 (Use intra-doc link in core::cell)
 - rust-lang#83442 (LLVMWrapper: attractive nuisance macros)

Failed merges:

 - rust-lang#83438 (Update RELEASES.md)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 25, 2021
2 parents 07e0e2e + 67436c1 commit 26c7e55
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 141 deletions.
2 changes: 0 additions & 2 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Compiler
`aarch64-unknown-linux-gnu_ilp32`, and `aarch64_be-unknown-linux-gnu_ilp32` targets.][81455]
- [Added tier 3 support for `i386-unknown-linux-gnu` and `i486-unknown-linux-gnu` targets.][80662]
- [The `target-cpu=native` option will now detect individual features of CPUs.][80749]
- [Rust now uses `inline-asm` for stack probes when used with LLVM 11.0.1+][77885]

\* Refer to Rust's [platform support page][forge-platform-support] for more
information on Rust's tiered platform support.
Expand Down Expand Up @@ -146,7 +145,6 @@ Internal Only
[80764]: https://github.com/rust-lang/rust/pull/80764
[80749]: https://github.com/rust-lang/rust/pull/80749
[80662]: https://github.com/rust-lang/rust/pull/80662
[77885]: https://github.com/rust-lang/rust/pull/77885
[cargo/8997]: https://github.com/rust-lang/cargo/pull/8997
[cargo/9112]: https://github.com/rust-lang/cargo/pull/9112
[feature-resolver@2.0]: https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-resolver-version-2
Expand Down
34 changes: 14 additions & 20 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,34 +434,31 @@ pub trait Emitter {
span: &mut MultiSpan,
children: &mut Vec<SubDiagnostic>,
) {
let source_map = if let Some(ref sm) = source_map {
sm
} else {
return;
};
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
for span in iter::once(&mut *span).chain(children.iter_mut().map(|child| &mut child.span)) {
self.fix_multispan_in_extern_macros(source_map, span);
self.fix_multispan_in_extern_macros(source_map, span);
for child in children.iter_mut() {
self.fix_multispan_in_extern_macros(source_map, &mut child.span);
}
debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children);
}

// This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros.
// Since these locations are often difficult to read,
// we move these spans from the external macros to their corresponding use site.
fn fix_multispan_in_extern_macros(
&self,
source_map: &Option<Lrc<SourceMap>>,
span: &mut MultiSpan,
) {
let sm = match source_map {
Some(ref sm) => sm,
None => return,
};

fn fix_multispan_in_extern_macros(&self, source_map: &Lrc<SourceMap>, span: &mut MultiSpan) {
// First, find all the spans in external macros and point instead at their use site.
let replacements: Vec<(Span, Span)> = span
.primary_spans()
.iter()
.copied()
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
.filter_map(|sp| {
if !sp.is_dummy() && sm.is_imported(sp) {
if !sp.is_dummy() && source_map.is_imported(sp) {
let maybe_callsite = sp.source_callsite();
if sp != maybe_callsite {
return Some((sp, maybe_callsite));
Expand Down Expand Up @@ -1232,7 +1229,6 @@ impl EmitterWriter {
is_secondary: bool,
) -> io::Result<()> {
let mut buffer = StyledBuffer::new();
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };

if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
{
Expand All @@ -1257,6 +1253,7 @@ impl EmitterWriter {
buffer.append(0, &code, Style::Level(*level));
buffer.append(0, "]", Style::Level(*level));
}
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
if *level != Level::FailureNote {
buffer.append(0, ": ", header_style);
}
Expand Down Expand Up @@ -1470,9 +1467,7 @@ impl EmitterWriter {
let mut to_add = FxHashMap::default();

for (depth, style) in depths {
if multilines.get(&depth).is_some() {
multilines.remove(&depth);
} else {
if multilines.remove(&depth).is_none() {
to_add.insert(depth, style);
}
}
Expand Down Expand Up @@ -1726,14 +1721,13 @@ impl EmitterWriter {
if !self.short_message {
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
}
match emit_to_destination(
if let Err(e) = emit_to_destination(
&buffer.render(),
level,
&mut self.dst,
self.short_message,
) {
Ok(()) => (),
Err(e) => panic!("failed to emit error: {}", e),
panic!("failed to emit error: {}", e)
}
}
if !self.short_message {
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
(LLVM_VERSION_MAJOR > (major) || \
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))

#define LLVM_VERSION_EQ(major, minor) \
(LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))

#define LLVM_VERSION_LE(major, minor) \
(LLVM_VERSION_MAJOR < (major) || \
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))

#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))

#include "llvm/IR/LegacyPassManager.h"
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
//! [`Rc<T>`]: ../../std/rc/struct.Rc.html
//! [`RwLock<T>`]: ../../std/sync/struct.RwLock.html
//! [`Mutex<T>`]: ../../std/sync/struct.Mutex.html
//! [`atomic`]: ../../core/sync/atomic/index.html
//! [`atomic`]: crate::sync::atomic

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
3 changes: 1 addition & 2 deletions library/core/src/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
/// # Examples
///
/// ```
/// # #![feature(debug_non_exhaustive)]
/// use std::fmt;
///
/// struct Bar {
Expand All @@ -186,7 +185,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
/// "Bar { bar: 10, .. }",
/// );
/// ```
#[unstable(feature = "debug_non_exhaustive", issue = "67364")]
#[stable(feature = "debug_non_exhaustive", since = "1.53.0")]
pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
self.result = self.result.and_then(|_| {
// Draw non-exhaustive dots (`..`), and open brace if necessary (no fields).
Expand Down
94 changes: 1 addition & 93 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
use crate::iter::{FromIterator, FusedIterator, TrustedLen};
use crate::pin::Pin;
use crate::{
fmt, hint, mem,
hint, mem,
ops::{self, Deref, DerefMut},
};

Expand Down Expand Up @@ -1121,90 +1121,6 @@ impl<T: Clone> Option<&mut T> {
}
}

impl<T: fmt::Debug> Option<T> {
/// Consumes `self` while expecting [`None`] and returning nothing.
///
/// # Panics
///
/// Panics if the value is a [`Some`], with a panic message including the
/// passed message, and the content of the [`Some`].
///
/// # Examples
///
/// ```
/// #![feature(option_expect_none)]
///
/// use std::collections::HashMap;
/// let mut squares = HashMap::new();
/// for i in -10..=10 {
/// // This will not panic, since all keys are unique.
/// squares.insert(i, i * i).expect_none("duplicate key");
/// }
/// ```
///
/// ```should_panic
/// #![feature(option_expect_none)]
///
/// use std::collections::HashMap;
/// let mut sqrts = HashMap::new();
/// for i in -10..=10 {
/// // This will panic, since both negative and positive `i` will
/// // insert the same `i * i` key, returning the old `Some(i)`.
/// sqrts.insert(i * i, i).expect_none("duplicate key");
/// }
/// ```
#[inline]
#[track_caller]
#[unstable(feature = "option_expect_none", reason = "newly added", issue = "62633")]
pub fn expect_none(self, msg: &str) {
if let Some(val) = self {
expect_none_failed(msg, &val);
}
}

/// Consumes `self` while expecting [`None`] and returning nothing.
///
/// # Panics
///
/// Panics if the value is a [`Some`], with a custom panic message provided
/// by the [`Some`]'s value.
///
/// [`Some(v)`]: Some
///
/// # Examples
///
/// ```
/// #![feature(option_unwrap_none)]
///
/// use std::collections::HashMap;
/// let mut squares = HashMap::new();
/// for i in -10..=10 {
/// // This will not panic, since all keys are unique.
/// squares.insert(i, i * i).unwrap_none();
/// }
/// ```
///
/// ```should_panic
/// #![feature(option_unwrap_none)]
///
/// use std::collections::HashMap;
/// let mut sqrts = HashMap::new();
/// for i in -10..=10 {
/// // This will panic, since both negative and positive `i` will
/// // insert the same `i * i` key, returning the old `Some(i)`.
/// sqrts.insert(i * i, i).unwrap_none();
/// }
/// ```
#[inline]
#[track_caller]
#[unstable(feature = "option_unwrap_none", reason = "newly added", issue = "62633")]
pub fn unwrap_none(self) {
if let Some(val) = self {
expect_none_failed("called `Option::unwrap_none()` on a `Some` value", &val);
}
}
}

impl<T: Default> Option<T> {
/// Returns the contained [`Some`] value or a default
///
Expand Down Expand Up @@ -1321,14 +1237,6 @@ fn expect_failed(msg: &str) -> ! {
panic!("{}", msg)
}

// This is a separate function to reduce the code size of .expect_none() itself.
#[inline(never)]
#[cold]
#[track_caller]
fn expect_none_failed(msg: &str, value: &dyn fmt::Debug) -> ! {
panic!("{}: {:?}", msg, value)
}

/////////////////////////////////////////////////////////////////////////////
// Trait implementations
/////////////////////////////////////////////////////////////////////////////
Expand Down
36 changes: 36 additions & 0 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,42 @@ impl<T, E: Into<!>> Result<T, E> {
}
}

#[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")]
impl<T: Into<!>, E> Result<T, E> {
/// Returns the contained [`Err`] value, but never panics.
///
/// Unlike [`unwrap_err`], this method is known to never panic on the
/// result types it is implemented for. Therefore, it can be used
/// instead of `unwrap_err` as a maintainability safeguard that will fail
/// to compile if the ok type of the `Result` is later changed
/// to a type that can actually occur.
///
/// [`unwrap_err`]: Result::unwrap_err
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # #![feature(never_type)]
/// # #![feature(unwrap_infallible)]
///
/// fn only_bad_news() -> Result<!, String> {
/// Err("Oops, it failed".into())
/// }
///
/// let error: String = only_bad_news().into_err();
/// println!("{}", error);
/// ```
#[inline]
pub fn into_err(self) -> E {
match self {
Ok(x) => x.into(),
Err(e) => e,
}
}
}

impl<T: Deref, E> Result<T, E> {
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&<T as Deref>::Target, &E>`.
///
Expand Down
12 changes: 6 additions & 6 deletions library/core/tests/iter/adapters/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ fn test_iterator_chain_size_hint() {
fn test_iterator_chain_unfused() {
// Chain shouldn't be fused in its second iterator, depending on direction
let mut iter = NonFused::new(empty()).chain(Toggle { is_empty: true });
iter.next().unwrap_none();
iter.next().unwrap();
iter.next().unwrap_none();
assert!(iter.next().is_none());
assert!(iter.next().is_some());
assert!(iter.next().is_none());

let mut iter = Toggle { is_empty: true }.chain(NonFused::new(empty()));
iter.next_back().unwrap_none();
iter.next_back().unwrap();
iter.next_back().unwrap_none();
assert!(iter.next_back().is_none());
assert!(iter.next_back().is_some());
assert!(iter.next_back().is_none());
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![feature(core_intrinsics)]
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
#![feature(debug_non_exhaustive)]
#![feature(dec2flt)]
#![feature(div_duration)]
#![feature(duration_consts_2)]
Expand Down Expand Up @@ -68,7 +67,6 @@
#![feature(unwrap_infallible)]
#![feature(option_result_unwrap_unchecked)]
#![feature(result_into_ok_or_err)]
#![feature(option_unwrap_none)]
#![feature(peekable_peek_mut)]
#![cfg_attr(not(bootstrap), feature(ptr_metadata))]
#![feature(once_cell)]
Expand Down
22 changes: 22 additions & 0 deletions library/core/tests/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ pub fn test_into_ok() {
assert_eq!(infallible_op2().into_ok(), 667);
}

#[test]
pub fn test_into_err() {
fn until_error_op() -> Result<!, isize> {
Err(666)
}

assert_eq!(until_error_op().into_err(), 666);

enum MyNeverToken {}
impl From<MyNeverToken> for ! {
fn from(never: MyNeverToken) -> ! {
match never {}
}
}

fn until_error_op2() -> Result<MyNeverToken, isize> {
Err(667)
}

assert_eq!(until_error_op2().into_err(), 667);
}

#[test]
fn test_try() {
fn try_result_some() -> Option<u8> {
Expand Down
6 changes: 3 additions & 3 deletions library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#![feature(nll)]
#![feature(available_concurrency)]
#![feature(internal_output_capture)]
#![feature(option_unwrap_none)]
#![feature(panic_unwind)]
#![feature(staged_api)]
#![feature(termination_trait_lib)]
Expand Down Expand Up @@ -298,8 +297,9 @@ where
let test = remaining.pop().unwrap();
let event = TestEvent::TeWait(test.desc.clone());
notify_about_test_event(event)?;
run_test(opts, !opts.run_tests, test, run_strategy, tx.clone(), Concurrent::No)
.unwrap_none();
let join_handle =
run_test(opts, !opts.run_tests, test, run_strategy, tx.clone(), Concurrent::No);
assert!(join_handle.is_none());
let completed_test = rx.recv().unwrap();

let event = TestEvent::TeResult(completed_test);
Expand Down
Loading

0 comments on commit 26c7e55

Please sign in to comment.