1
Fork 0

Auto merge of #83454 - JohnTitor:rollup-9ae0565, r=JohnTitor

Rollup of 8 pull requests

Successful merges:

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

Failed merges:

 - #83438 (Update RELEASES.md)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2021-03-25 02:26:19 +00:00
commit 26c7e55f47
13 changed files with 96 additions and 141 deletions

View file

@ -34,7 +34,6 @@ Compiler
`aarch64-unknown-linux-gnu_ilp32`, and `aarch64_be-unknown-linux-gnu_ilp32` targets.][81455] `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] - [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] - [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 \* Refer to Rust's [platform support page][forge-platform-support] for more
information on Rust's tiered platform support. information on Rust's tiered platform support.
@ -146,7 +145,6 @@ Internal Only
[80764]: https://github.com/rust-lang/rust/pull/80764 [80764]: https://github.com/rust-lang/rust/pull/80764
[80749]: https://github.com/rust-lang/rust/pull/80749 [80749]: https://github.com/rust-lang/rust/pull/80749
[80662]: https://github.com/rust-lang/rust/pull/80662 [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/8997]: https://github.com/rust-lang/cargo/pull/8997
[cargo/9112]: https://github.com/rust-lang/cargo/pull/9112 [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 [feature-resolver@2.0]: https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-resolver-version-2

View file

@ -434,9 +434,15 @@ pub trait Emitter {
span: &mut MultiSpan, span: &mut MultiSpan,
children: &mut Vec<SubDiagnostic>, 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); 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); debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children);
} }
@ -444,16 +450,7 @@ pub trait Emitter {
// This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros. // This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros.
// Since these locations are often difficult to read, // Since these locations are often difficult to read,
// we move these spans from the external macros to their corresponding use site. // we move these spans from the external macros to their corresponding use site.
fn fix_multispan_in_extern_macros( fn fix_multispan_in_extern_macros(&self, source_map: &Lrc<SourceMap>, span: &mut MultiSpan) {
&self,
source_map: &Option<Lrc<SourceMap>>,
span: &mut MultiSpan,
) {
let sm = match source_map {
Some(ref sm) => sm,
None => return,
};
// First, find all the spans in external macros and point instead at their use site. // First, find all the spans in external macros and point instead at their use site.
let replacements: Vec<(Span, Span)> = span let replacements: Vec<(Span, Span)> = span
.primary_spans() .primary_spans()
@ -461,7 +458,7 @@ pub trait Emitter {
.copied() .copied()
.chain(span.span_labels().iter().map(|sp_label| sp_label.span)) .chain(span.span_labels().iter().map(|sp_label| sp_label.span))
.filter_map(|sp| { .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(); let maybe_callsite = sp.source_callsite();
if sp != maybe_callsite { if sp != maybe_callsite {
return Some((sp, maybe_callsite)); return Some((sp, maybe_callsite));
@ -1232,7 +1229,6 @@ impl EmitterWriter {
is_secondary: bool, is_secondary: bool,
) -> io::Result<()> { ) -> io::Result<()> {
let mut buffer = StyledBuffer::new(); 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 if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
{ {
@ -1257,6 +1253,7 @@ impl EmitterWriter {
buffer.append(0, &code, Style::Level(*level)); buffer.append(0, &code, Style::Level(*level));
buffer.append(0, "]", Style::Level(*level)); buffer.append(0, "]", Style::Level(*level));
} }
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
if *level != Level::FailureNote { if *level != Level::FailureNote {
buffer.append(0, ": ", header_style); buffer.append(0, ": ", header_style);
} }
@ -1470,9 +1467,7 @@ impl EmitterWriter {
let mut to_add = FxHashMap::default(); let mut to_add = FxHashMap::default();
for (depth, style) in depths { for (depth, style) in depths {
if multilines.get(&depth).is_some() { if multilines.remove(&depth).is_none() {
multilines.remove(&depth);
} else {
to_add.insert(depth, style); to_add.insert(depth, style);
} }
} }
@ -1726,14 +1721,13 @@ impl EmitterWriter {
if !self.short_message { if !self.short_message {
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1); 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(), &buffer.render(),
level, level,
&mut self.dst, &mut self.dst,
self.short_message, self.short_message,
) { ) {
Ok(()) => (), panic!("failed to emit error: {}", e)
Err(e) => panic!("failed to emit error: {}", e),
} }
} }
if !self.short_message { if !self.short_message {

View file

@ -33,13 +33,6 @@
(LLVM_VERSION_MAJOR > (major) || \ (LLVM_VERSION_MAJOR > (major) || \
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor)) 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))) #define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"

View file

@ -188,7 +188,7 @@
//! [`Rc<T>`]: ../../std/rc/struct.Rc.html //! [`Rc<T>`]: ../../std/rc/struct.Rc.html
//! [`RwLock<T>`]: ../../std/sync/struct.RwLock.html //! [`RwLock<T>`]: ../../std/sync/struct.RwLock.html
//! [`Mutex<T>`]: ../../std/sync/struct.Mutex.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")] #![stable(feature = "rust1", since = "1.0.0")]

View file

@ -165,7 +165,6 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #![feature(debug_non_exhaustive)]
/// use std::fmt; /// use std::fmt;
/// ///
/// struct Bar { /// struct Bar {
@ -186,7 +185,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
/// "Bar { bar: 10, .. }", /// "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 { pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
self.result = self.result.and_then(|_| { self.result = self.result.and_then(|_| {
// Draw non-exhaustive dots (`..`), and open brace if necessary (no fields). // Draw non-exhaustive dots (`..`), and open brace if necessary (no fields).

View file

@ -150,7 +150,7 @@
use crate::iter::{FromIterator, FusedIterator, TrustedLen}; use crate::iter::{FromIterator, FusedIterator, TrustedLen};
use crate::pin::Pin; use crate::pin::Pin;
use crate::{ use crate::{
fmt, hint, mem, hint, mem,
ops::{self, Deref, DerefMut}, ops::{self, Deref, DerefMut},
}; };
@ -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> { impl<T: Default> Option<T> {
/// Returns the contained [`Some`] value or a default /// Returns the contained [`Some`] value or a default
/// ///
@ -1321,14 +1237,6 @@ fn expect_failed(msg: &str) -> ! {
panic!("{}", msg) 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 // Trait implementations
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View file

@ -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> { impl<T: Deref, E> Result<T, E> {
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&<T as Deref>::Target, &E>`. /// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&<T as Deref>::Target, &E>`.
/// ///

View file

@ -174,14 +174,14 @@ fn test_iterator_chain_size_hint() {
fn test_iterator_chain_unfused() { fn test_iterator_chain_unfused() {
// Chain shouldn't be fused in its second iterator, depending on direction // Chain shouldn't be fused in its second iterator, depending on direction
let mut iter = NonFused::new(empty()).chain(Toggle { is_empty: true }); let mut iter = NonFused::new(empty()).chain(Toggle { is_empty: true });
iter.next().unwrap_none(); assert!(iter.next().is_none());
iter.next().unwrap(); assert!(iter.next().is_some());
iter.next().unwrap_none(); assert!(iter.next().is_none());
let mut iter = Toggle { is_empty: true }.chain(NonFused::new(empty())); let mut iter = Toggle { is_empty: true }.chain(NonFused::new(empty()));
iter.next_back().unwrap_none(); assert!(iter.next_back().is_none());
iter.next_back().unwrap(); assert!(iter.next_back().is_some());
iter.next_back().unwrap_none(); assert!(iter.next_back().is_none());
} }
#[test] #[test]

View file

@ -20,7 +20,6 @@
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(core_private_bignum)] #![feature(core_private_bignum)]
#![feature(core_private_diy_float)] #![feature(core_private_diy_float)]
#![feature(debug_non_exhaustive)]
#![feature(dec2flt)] #![feature(dec2flt)]
#![feature(div_duration)] #![feature(div_duration)]
#![feature(duration_consts_2)] #![feature(duration_consts_2)]
@ -68,7 +67,6 @@
#![feature(unwrap_infallible)] #![feature(unwrap_infallible)]
#![feature(option_result_unwrap_unchecked)] #![feature(option_result_unwrap_unchecked)]
#![feature(result_into_ok_or_err)] #![feature(result_into_ok_or_err)]
#![feature(option_unwrap_none)]
#![feature(peekable_peek_mut)] #![feature(peekable_peek_mut)]
#![cfg_attr(not(bootstrap), feature(ptr_metadata))] #![cfg_attr(not(bootstrap), feature(ptr_metadata))]
#![feature(once_cell)] #![feature(once_cell)]

View file

@ -225,6 +225,28 @@ pub fn test_into_ok() {
assert_eq!(infallible_op2().into_ok(), 667); 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] #[test]
fn test_try() { fn test_try() {
fn try_result_some() -> Option<u8> { fn try_result_some() -> Option<u8> {

View file

@ -25,7 +25,6 @@
#![feature(nll)] #![feature(nll)]
#![feature(available_concurrency)] #![feature(available_concurrency)]
#![feature(internal_output_capture)] #![feature(internal_output_capture)]
#![feature(option_unwrap_none)]
#![feature(panic_unwind)] #![feature(panic_unwind)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(termination_trait_lib)] #![feature(termination_trait_lib)]
@ -298,8 +297,9 @@ where
let test = remaining.pop().unwrap(); let test = remaining.pop().unwrap();
let event = TestEvent::TeWait(test.desc.clone()); let event = TestEvent::TeWait(test.desc.clone());
notify_about_test_event(event)?; notify_about_test_event(event)?;
run_test(opts, !opts.run_tests, test, run_strategy, tx.clone(), Concurrent::No) let join_handle =
.unwrap_none(); 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 completed_test = rx.recv().unwrap();
let event = TestEvent::TeResult(completed_test); let event = TestEvent::TeResult(completed_test);

View file

@ -0,0 +1,12 @@
The tests present here are used to test the generated HTML from rustdoc. The
goal is to prevent unsound/unexpected GUI changes.
This is using the [browser-ui-test] framework to do so. It works as follows:
It wraps [puppeteer] to send commands to a web browser in order to navigate and
test what's being currently displayed in the web page.
You can find more information and its documentation in its [repository][browser-ui-test].
[browser-ui-test]: https://github.com/GuillaumeGomez/browser-UI-test/
[puppeteer]: https://pptr.dev/

View file

@ -3,7 +3,6 @@
// revisions: default mir-opt // revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=4 //[mir-opt] compile-flags: -Zmir-opt-level=4
#![feature(option_expect_none, option_unwrap_none)]
#![allow(unconditional_panic)] #![allow(unconditional_panic)]
//! Test that panic locations for `#[track_caller]` functions in std have the correct //! Test that panic locations for `#[track_caller]` functions in std have the correct
@ -32,10 +31,6 @@ fn main() {
assert_panicked(|| nope.unwrap()); assert_panicked(|| nope.unwrap());
assert_panicked(|| nope.expect("")); assert_panicked(|| nope.expect(""));
let yep: Option<()> = Some(());
assert_panicked(|| yep.unwrap_none());
assert_panicked(|| yep.expect_none(""));
let oops: Result<(), ()> = Err(()); let oops: Result<(), ()> = Err(());
assert_panicked(|| oops.unwrap()); assert_panicked(|| oops.unwrap());
assert_panicked(|| oops.expect("")); assert_panicked(|| oops.expect(""));