Skip to content

Commit 26c7e55

Browse files
committed
Auto merge of rust-lang#83454 - JohnTitor:rollup-9ae0565, r=JohnTitor
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
2 parents 07e0e2e + 67436c1 commit 26c7e55

File tree

13 files changed

+96
-141
lines changed

13 files changed

+96
-141
lines changed

RELEASES.md

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Compiler
3434
`aarch64-unknown-linux-gnu_ilp32`, and `aarch64_be-unknown-linux-gnu_ilp32` targets.][81455]
3535
- [Added tier 3 support for `i386-unknown-linux-gnu` and `i486-unknown-linux-gnu` targets.][80662]
3636
- [The `target-cpu=native` option will now detect individual features of CPUs.][80749]
37-
- [Rust now uses `inline-asm` for stack probes when used with LLVM 11.0.1+][77885]
3837

3938
\* Refer to Rust's [platform support page][forge-platform-support] for more
4039
information on Rust's tiered platform support.
@@ -146,7 +145,6 @@ Internal Only
146145
[80764]: https://github.com/rust-lang/rust/pull/80764
147146
[80749]: https://github.com/rust-lang/rust/pull/80749
148147
[80662]: https://github.com/rust-lang/rust/pull/80662
149-
[77885]: https://github.com/rust-lang/rust/pull/77885
150148
[cargo/8997]: https://github.com/rust-lang/cargo/pull/8997
151149
[cargo/9112]: https://github.com/rust-lang/cargo/pull/9112
152150
[feature-resolver@2.0]: https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-resolver-version-2

compiler/rustc_errors/src/emitter.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -434,34 +434,31 @@ pub trait Emitter {
434434
span: &mut MultiSpan,
435435
children: &mut Vec<SubDiagnostic>,
436436
) {
437+
let source_map = if let Some(ref sm) = source_map {
438+
sm
439+
} else {
440+
return;
441+
};
437442
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
438-
for span in iter::once(&mut *span).chain(children.iter_mut().map(|child| &mut child.span)) {
439-
self.fix_multispan_in_extern_macros(source_map, span);
443+
self.fix_multispan_in_extern_macros(source_map, span);
444+
for child in children.iter_mut() {
445+
self.fix_multispan_in_extern_macros(source_map, &mut child.span);
440446
}
441447
debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children);
442448
}
443449

444450
// This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros.
445451
// Since these locations are often difficult to read,
446452
// we move these spans from the external macros to their corresponding use site.
447-
fn fix_multispan_in_extern_macros(
448-
&self,
449-
source_map: &Option<Lrc<SourceMap>>,
450-
span: &mut MultiSpan,
451-
) {
452-
let sm = match source_map {
453-
Some(ref sm) => sm,
454-
None => return,
455-
};
456-
453+
fn fix_multispan_in_extern_macros(&self, source_map: &Lrc<SourceMap>, span: &mut MultiSpan) {
457454
// First, find all the spans in external macros and point instead at their use site.
458455
let replacements: Vec<(Span, Span)> = span
459456
.primary_spans()
460457
.iter()
461458
.copied()
462459
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
463460
.filter_map(|sp| {
464-
if !sp.is_dummy() && sm.is_imported(sp) {
461+
if !sp.is_dummy() && source_map.is_imported(sp) {
465462
let maybe_callsite = sp.source_callsite();
466463
if sp != maybe_callsite {
467464
return Some((sp, maybe_callsite));
@@ -1232,7 +1229,6 @@ impl EmitterWriter {
12321229
is_secondary: bool,
12331230
) -> io::Result<()> {
12341231
let mut buffer = StyledBuffer::new();
1235-
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
12361232

12371233
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
12381234
{
@@ -1257,6 +1253,7 @@ impl EmitterWriter {
12571253
buffer.append(0, &code, Style::Level(*level));
12581254
buffer.append(0, "]", Style::Level(*level));
12591255
}
1256+
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
12601257
if *level != Level::FailureNote {
12611258
buffer.append(0, ": ", header_style);
12621259
}
@@ -1470,9 +1467,7 @@ impl EmitterWriter {
14701467
let mut to_add = FxHashMap::default();
14711468

14721469
for (depth, style) in depths {
1473-
if multilines.get(&depth).is_some() {
1474-
multilines.remove(&depth);
1475-
} else {
1470+
if multilines.remove(&depth).is_none() {
14761471
to_add.insert(depth, style);
14771472
}
14781473
}
@@ -1726,14 +1721,13 @@ impl EmitterWriter {
17261721
if !self.short_message {
17271722
draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
17281723
}
1729-
match emit_to_destination(
1724+
if let Err(e) = emit_to_destination(
17301725
&buffer.render(),
17311726
level,
17321727
&mut self.dst,
17331728
self.short_message,
17341729
) {
1735-
Ok(()) => (),
1736-
Err(e) => panic!("failed to emit error: {}", e),
1730+
panic!("failed to emit error: {}", e)
17371731
}
17381732
}
17391733
if !self.short_message {

compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h

-7
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
(LLVM_VERSION_MAJOR > (major) || \
3434
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
3535

36-
#define LLVM_VERSION_EQ(major, minor) \
37-
(LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
38-
39-
#define LLVM_VERSION_LE(major, minor) \
40-
(LLVM_VERSION_MAJOR < (major) || \
41-
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
42-
4336
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
4437

4538
#include "llvm/IR/LegacyPassManager.h"

library/core/src/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
//! [`Rc<T>`]: ../../std/rc/struct.Rc.html
189189
//! [`RwLock<T>`]: ../../std/sync/struct.RwLock.html
190190
//! [`Mutex<T>`]: ../../std/sync/struct.Mutex.html
191-
//! [`atomic`]: ../../core/sync/atomic/index.html
191+
//! [`atomic`]: crate::sync::atomic
192192
193193
#![stable(feature = "rust1", since = "1.0.0")]
194194

library/core/src/fmt/builders.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
165165
/// # Examples
166166
///
167167
/// ```
168-
/// # #![feature(debug_non_exhaustive)]
169168
/// use std::fmt;
170169
///
171170
/// struct Bar {
@@ -186,7 +185,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
186185
/// "Bar { bar: 10, .. }",
187186
/// );
188187
/// ```
189-
#[unstable(feature = "debug_non_exhaustive", issue = "67364")]
188+
#[stable(feature = "debug_non_exhaustive", since = "1.53.0")]
190189
pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
191190
self.result = self.result.and_then(|_| {
192191
// Draw non-exhaustive dots (`..`), and open brace if necessary (no fields).

library/core/src/option.rs

+1-93
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
use crate::iter::{FromIterator, FusedIterator, TrustedLen};
151151
use crate::pin::Pin;
152152
use crate::{
153-
fmt, hint, mem,
153+
hint, mem,
154154
ops::{self, Deref, DerefMut},
155155
};
156156

@@ -1121,90 +1121,6 @@ impl<T: Clone> Option<&mut T> {
11211121
}
11221122
}
11231123

1124-
impl<T: fmt::Debug> Option<T> {
1125-
/// Consumes `self` while expecting [`None`] and returning nothing.
1126-
///
1127-
/// # Panics
1128-
///
1129-
/// Panics if the value is a [`Some`], with a panic message including the
1130-
/// passed message, and the content of the [`Some`].
1131-
///
1132-
/// # Examples
1133-
///
1134-
/// ```
1135-
/// #![feature(option_expect_none)]
1136-
///
1137-
/// use std::collections::HashMap;
1138-
/// let mut squares = HashMap::new();
1139-
/// for i in -10..=10 {
1140-
/// // This will not panic, since all keys are unique.
1141-
/// squares.insert(i, i * i).expect_none("duplicate key");
1142-
/// }
1143-
/// ```
1144-
///
1145-
/// ```should_panic
1146-
/// #![feature(option_expect_none)]
1147-
///
1148-
/// use std::collections::HashMap;
1149-
/// let mut sqrts = HashMap::new();
1150-
/// for i in -10..=10 {
1151-
/// // This will panic, since both negative and positive `i` will
1152-
/// // insert the same `i * i` key, returning the old `Some(i)`.
1153-
/// sqrts.insert(i * i, i).expect_none("duplicate key");
1154-
/// }
1155-
/// ```
1156-
#[inline]
1157-
#[track_caller]
1158-
#[unstable(feature = "option_expect_none", reason = "newly added", issue = "62633")]
1159-
pub fn expect_none(self, msg: &str) {
1160-
if let Some(val) = self {
1161-
expect_none_failed(msg, &val);
1162-
}
1163-
}
1164-
1165-
/// Consumes `self` while expecting [`None`] and returning nothing.
1166-
///
1167-
/// # Panics
1168-
///
1169-
/// Panics if the value is a [`Some`], with a custom panic message provided
1170-
/// by the [`Some`]'s value.
1171-
///
1172-
/// [`Some(v)`]: Some
1173-
///
1174-
/// # Examples
1175-
///
1176-
/// ```
1177-
/// #![feature(option_unwrap_none)]
1178-
///
1179-
/// use std::collections::HashMap;
1180-
/// let mut squares = HashMap::new();
1181-
/// for i in -10..=10 {
1182-
/// // This will not panic, since all keys are unique.
1183-
/// squares.insert(i, i * i).unwrap_none();
1184-
/// }
1185-
/// ```
1186-
///
1187-
/// ```should_panic
1188-
/// #![feature(option_unwrap_none)]
1189-
///
1190-
/// use std::collections::HashMap;
1191-
/// let mut sqrts = HashMap::new();
1192-
/// for i in -10..=10 {
1193-
/// // This will panic, since both negative and positive `i` will
1194-
/// // insert the same `i * i` key, returning the old `Some(i)`.
1195-
/// sqrts.insert(i * i, i).unwrap_none();
1196-
/// }
1197-
/// ```
1198-
#[inline]
1199-
#[track_caller]
1200-
#[unstable(feature = "option_unwrap_none", reason = "newly added", issue = "62633")]
1201-
pub fn unwrap_none(self) {
1202-
if let Some(val) = self {
1203-
expect_none_failed("called `Option::unwrap_none()` on a `Some` value", &val);
1204-
}
1205-
}
1206-
}
1207-
12081124
impl<T: Default> Option<T> {
12091125
/// Returns the contained [`Some`] value or a default
12101126
///
@@ -1321,14 +1237,6 @@ fn expect_failed(msg: &str) -> ! {
13211237
panic!("{}", msg)
13221238
}
13231239

1324-
// This is a separate function to reduce the code size of .expect_none() itself.
1325-
#[inline(never)]
1326-
#[cold]
1327-
#[track_caller]
1328-
fn expect_none_failed(msg: &str, value: &dyn fmt::Debug) -> ! {
1329-
panic!("{}: {:?}", msg, value)
1330-
}
1331-
13321240
/////////////////////////////////////////////////////////////////////////////
13331241
// Trait implementations
13341242
/////////////////////////////////////////////////////////////////////////////

library/core/src/result.rs

+36
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,42 @@ impl<T, E: Into<!>> Result<T, E> {
11671167
}
11681168
}
11691169

1170+
#[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")]
1171+
impl<T: Into<!>, E> Result<T, E> {
1172+
/// Returns the contained [`Err`] value, but never panics.
1173+
///
1174+
/// Unlike [`unwrap_err`], this method is known to never panic on the
1175+
/// result types it is implemented for. Therefore, it can be used
1176+
/// instead of `unwrap_err` as a maintainability safeguard that will fail
1177+
/// to compile if the ok type of the `Result` is later changed
1178+
/// to a type that can actually occur.
1179+
///
1180+
/// [`unwrap_err`]: Result::unwrap_err
1181+
///
1182+
/// # Examples
1183+
///
1184+
/// Basic usage:
1185+
///
1186+
/// ```
1187+
/// # #![feature(never_type)]
1188+
/// # #![feature(unwrap_infallible)]
1189+
///
1190+
/// fn only_bad_news() -> Result<!, String> {
1191+
/// Err("Oops, it failed".into())
1192+
/// }
1193+
///
1194+
/// let error: String = only_bad_news().into_err();
1195+
/// println!("{}", error);
1196+
/// ```
1197+
#[inline]
1198+
pub fn into_err(self) -> E {
1199+
match self {
1200+
Ok(x) => x.into(),
1201+
Err(e) => e,
1202+
}
1203+
}
1204+
}
1205+
11701206
impl<T: Deref, E> Result<T, E> {
11711207
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&<T as Deref>::Target, &E>`.
11721208
///

library/core/tests/iter/adapters/chain.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ fn test_iterator_chain_size_hint() {
174174
fn test_iterator_chain_unfused() {
175175
// Chain shouldn't be fused in its second iterator, depending on direction
176176
let mut iter = NonFused::new(empty()).chain(Toggle { is_empty: true });
177-
iter.next().unwrap_none();
178-
iter.next().unwrap();
179-
iter.next().unwrap_none();
177+
assert!(iter.next().is_none());
178+
assert!(iter.next().is_some());
179+
assert!(iter.next().is_none());
180180

181181
let mut iter = Toggle { is_empty: true }.chain(NonFused::new(empty()));
182-
iter.next_back().unwrap_none();
183-
iter.next_back().unwrap();
184-
iter.next_back().unwrap_none();
182+
assert!(iter.next_back().is_none());
183+
assert!(iter.next_back().is_some());
184+
assert!(iter.next_back().is_none());
185185
}
186186

187187
#[test]

library/core/tests/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![feature(core_intrinsics)]
2121
#![feature(core_private_bignum)]
2222
#![feature(core_private_diy_float)]
23-
#![feature(debug_non_exhaustive)]
2423
#![feature(dec2flt)]
2524
#![feature(div_duration)]
2625
#![feature(duration_consts_2)]
@@ -68,7 +67,6 @@
6867
#![feature(unwrap_infallible)]
6968
#![feature(option_result_unwrap_unchecked)]
7069
#![feature(result_into_ok_or_err)]
71-
#![feature(option_unwrap_none)]
7270
#![feature(peekable_peek_mut)]
7371
#![cfg_attr(not(bootstrap), feature(ptr_metadata))]
7472
#![feature(once_cell)]

library/core/tests/result.rs

+22
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,28 @@ pub fn test_into_ok() {
225225
assert_eq!(infallible_op2().into_ok(), 667);
226226
}
227227

228+
#[test]
229+
pub fn test_into_err() {
230+
fn until_error_op() -> Result<!, isize> {
231+
Err(666)
232+
}
233+
234+
assert_eq!(until_error_op().into_err(), 666);
235+
236+
enum MyNeverToken {}
237+
impl From<MyNeverToken> for ! {
238+
fn from(never: MyNeverToken) -> ! {
239+
match never {}
240+
}
241+
}
242+
243+
fn until_error_op2() -> Result<MyNeverToken, isize> {
244+
Err(667)
245+
}
246+
247+
assert_eq!(until_error_op2().into_err(), 667);
248+
}
249+
228250
#[test]
229251
fn test_try() {
230252
fn try_result_some() -> Option<u8> {

library/test/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#![feature(nll)]
2626
#![feature(available_concurrency)]
2727
#![feature(internal_output_capture)]
28-
#![feature(option_unwrap_none)]
2928
#![feature(panic_unwind)]
3029
#![feature(staged_api)]
3130
#![feature(termination_trait_lib)]
@@ -298,8 +297,9 @@ where
298297
let test = remaining.pop().unwrap();
299298
let event = TestEvent::TeWait(test.desc.clone());
300299
notify_about_test_event(event)?;
301-
run_test(opts, !opts.run_tests, test, run_strategy, tx.clone(), Concurrent::No)
302-
.unwrap_none();
300+
let join_handle =
301+
run_test(opts, !opts.run_tests, test, run_strategy, tx.clone(), Concurrent::No);
302+
assert!(join_handle.is_none());
303303
let completed_test = rx.recv().unwrap();
304304

305305
let event = TestEvent::TeResult(completed_test);

0 commit comments

Comments
 (0)