Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #83454

Merged
merged 19 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
73ddfa0
stabilize debug_non_exhaustive
guswynn Mar 11, 2021
b8e4981
Update library/core/src/fmt/builders.rs
guswynn Mar 12, 2021
8dc0ae2
Remove Option::{unwrap_none, expect_none}.
m-ou-se Mar 14, 2021
c8dbb59
Add documentation for rustdoc-gui tests
GuillaumeGomez Mar 23, 2021
593f929
Add Result::into_err where the Ok variant can never happen
faern Mar 23, 2021
3bf076e
Add test for Result::into_err
faern Mar 23, 2021
f180721
small cleanups in rustc_errors / emitter
llogiq Mar 23, 2021
0381d67
Update RELEASES.md
wesleywiser Mar 24, 2021
c0fe54f
Use intra-doc link in core::cell
fee1-dead Mar 24, 2021
04961d2
LLVMWrapper: attractive nuisance macros
durin42 Mar 24, 2021
b1fac3a
Bump debug_non_exhaustive stabilization to 1.53.
m-ou-se Mar 24, 2021
a6ababb
Rollup merge of #83041 - guswynn:stable_debug_struct, r=m-ou-se
JohnTitor Mar 25, 2021
29e64e9
Rollup merge of #83349 - m-ou-se:unwrap-none, r=dtolnay
JohnTitor Mar 25, 2021
72a2d0e
Rollup merge of #83420 - GuillaumeGomez:rustdoc-gui-tests-doc, r=Craf…
JohnTitor Mar 25, 2021
921a820
Rollup merge of #83421 - faern:add-into-err, r=joshtriplett
JohnTitor Mar 25, 2021
5ca3f0d
Rollup merge of #83427 - llogiq:refactor-emitter, r=estebank
JohnTitor Mar 25, 2021
5a525c3
Rollup merge of #83434 - wesleywiser:update_releases, r=Mark-Simulacrum
JohnTitor Mar 25, 2021
ee34453
Rollup merge of #83440 - fee1-dead:core-cell-intralink, r=jyn514
JohnTitor Mar 25, 2021
67436c1
Rollup merge of #83442 - durin42:remove-questionable-macros, r=cuviper
JohnTitor Mar 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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