Skip to content

Commit d3d145e

Browse files
committed
Auto merge of rust-lang#121770 - matthiaskrgr:rollup-wdher8r, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#110543 (Make `ReentrantLock` public) - rust-lang#121689 ([rustdoc] Prevent inclusion of whitespace character after macro_rules ident) - rust-lang#121724 (Use `LitKind::Err` for malformed floats) - rust-lang#121735 (pattern analysis: Don't panic when encountering unexpected constructor) - rust-lang#121743 (Opportunistically resolve regions when processing region outlives obligations) Failed merges: - rust-lang#121326 (Detect empty leading where clauses on type aliases) - rust-lang#121416 (Improve error messages for generics with default parameters) - rust-lang#121669 (Count stashed errors again) - rust-lang#121723 (Two diagnostic things) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c475e23 + 9f9daed commit d3d145e

File tree

19 files changed

+600
-396
lines changed

19 files changed

+600
-396
lines changed

compiler/rustc_infer/src/infer/outlives/obligations.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@
6262
use crate::infer::outlives::components::{push_outlives_components, Component};
6363
use crate::infer::outlives::env::RegionBoundPairs;
6464
use crate::infer::outlives::verify::VerifyBoundCx;
65+
use crate::infer::resolve::OpportunisticRegionResolver;
6566
use crate::infer::{
6667
self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound,
6768
};
6869
use crate::traits::{ObligationCause, ObligationCauseCode};
6970
use rustc_data_structures::undo_log::UndoLogs;
7071
use rustc_middle::mir::ConstraintCategory;
7172
use rustc_middle::traits::query::NoSolution;
72-
use rustc_middle::ty::{self, GenericArgsRef, Region, Ty, TyCtxt, TypeVisitableExt};
73+
use rustc_middle::ty::{
74+
self, GenericArgsRef, Region, Ty, TyCtxt, TypeFoldable as _, TypeVisitableExt,
75+
};
7376
use rustc_middle::ty::{GenericArgKind, PolyTypeOutlivesPredicate};
7477
use rustc_span::DUMMY_SP;
7578
use smallvec::smallvec;
@@ -176,6 +179,11 @@ impl<'tcx> InferCtxt<'tcx> {
176179
.map_err(|NoSolution| (outlives, origin.clone()))?
177180
.no_bound_vars()
178181
.expect("started with no bound vars, should end with no bound vars");
182+
// `TypeOutlives` is structural, so we should try to opportunistically resolve all
183+
// region vids before processing regions, so we have a better chance to match clauses
184+
// in our param-env.
185+
let (sup_type, sub_region) =
186+
(sup_type, sub_region).fold_with(&mut OpportunisticRegionResolver::new(self));
179187

180188
debug!(?sup_type, ?sub_region, ?origin);
181189

compiler/rustc_parse/src/lexer/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,11 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
501501
(kind, self.symbol_from_to(start, end))
502502
}
503503
rustc_lexer::LiteralKind::Float { base, empty_exponent } => {
504+
let mut kind = token::Float;
504505
if empty_exponent {
505506
let span = self.mk_sp(start, self.pos);
506-
self.dcx().emit_err(errors::EmptyExponentFloat { span });
507+
let guar = self.dcx().emit_err(errors::EmptyExponentFloat { span });
508+
kind = token::Err(guar);
507509
}
508510
let base = match base {
509511
Base::Hexadecimal => Some("hexadecimal"),
@@ -513,9 +515,11 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
513515
};
514516
if let Some(base) = base {
515517
let span = self.mk_sp(start, end);
516-
self.dcx().emit_err(errors::FloatLiteralUnsupportedBase { span, base });
518+
let guar =
519+
self.dcx().emit_err(errors::FloatLiteralUnsupportedBase { span, base });
520+
kind = token::Err(guar)
517521
}
518-
(token::Float, self.symbol_from_to(start, end))
522+
(kind, self.symbol_from_to(start, end))
519523
}
520524
}
521525
}

compiler/rustc_pattern_analysis/src/constructor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ impl<Cx: TypeCx> ConstructorSet<Cx> {
940940
}
941941
ConstructorSet::Variants { variants, non_exhaustive } => {
942942
let mut seen_set = index::IdxSet::new_empty(variants.len());
943-
for idx in seen.iter().map(|c| c.as_variant().unwrap()) {
943+
for idx in seen.iter().filter_map(|c| c.as_variant()) {
944944
seen_set.insert(idx);
945945
}
946946
let mut skipped_a_hidden_variant = false;
@@ -969,7 +969,7 @@ impl<Cx: TypeCx> ConstructorSet<Cx> {
969969
ConstructorSet::Bool => {
970970
let mut seen_false = false;
971971
let mut seen_true = false;
972-
for b in seen.iter().map(|ctor| ctor.as_bool().unwrap()) {
972+
for b in seen.iter().filter_map(|ctor| ctor.as_bool()) {
973973
if b {
974974
seen_true = true;
975975
} else {
@@ -989,7 +989,7 @@ impl<Cx: TypeCx> ConstructorSet<Cx> {
989989
}
990990
ConstructorSet::Integers { range_1, range_2 } => {
991991
let seen_ranges: Vec<_> =
992-
seen.iter().map(|ctor| *ctor.as_int_range().unwrap()).collect();
992+
seen.iter().filter_map(|ctor| ctor.as_int_range()).copied().collect();
993993
for (seen, splitted_range) in range_1.split(seen_ranges.iter().cloned()) {
994994
match seen {
995995
Presence::Unseen => missing.push(IntRange(splitted_range)),
@@ -1006,7 +1006,7 @@ impl<Cx: TypeCx> ConstructorSet<Cx> {
10061006
}
10071007
}
10081008
ConstructorSet::Slice { array_len, subtype_is_empty } => {
1009-
let seen_slices = seen.iter().map(|c| c.as_slice().unwrap());
1009+
let seen_slices = seen.iter().filter_map(|c| c.as_slice());
10101010
let base_slice = Slice::new(*array_len, VarLen(0, 0));
10111011
for (seen, splitted_slice) in base_slice.split(seen_slices) {
10121012
let ctor = Slice(splitted_slice);

library/std/src/io/stdio.rs

+35-10
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use crate::fs::File;
1111
use crate::io::{
1212
self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines, SpecReadByte,
1313
};
14+
use crate::panic::{RefUnwindSafe, UnwindSafe};
1415
use crate::sync::atomic::{AtomicBool, Ordering};
15-
use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard};
16+
use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantLock, ReentrantLockGuard};
1617
use crate::sys::stdio;
1718

1819
type LocalStream = Arc<Mutex<Vec<u8>>>;
@@ -545,7 +546,7 @@ pub struct Stdout {
545546
// FIXME: this should be LineWriter or BufWriter depending on the state of
546547
// stdout (tty or not). Note that if this is not line buffered it
547548
// should also flush-on-panic or some form of flush-on-abort.
548-
inner: &'static ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>,
549+
inner: &'static ReentrantLock<RefCell<LineWriter<StdoutRaw>>>,
549550
}
550551

551552
/// A locked reference to the [`Stdout`] handle.
@@ -567,10 +568,10 @@ pub struct Stdout {
567568
#[must_use = "if unused stdout will immediately unlock"]
568569
#[stable(feature = "rust1", since = "1.0.0")]
569570
pub struct StdoutLock<'a> {
570-
inner: ReentrantMutexGuard<'a, RefCell<LineWriter<StdoutRaw>>>,
571+
inner: ReentrantLockGuard<'a, RefCell<LineWriter<StdoutRaw>>>,
571572
}
572573

573-
static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLock::new();
574+
static STDOUT: OnceLock<ReentrantLock<RefCell<LineWriter<StdoutRaw>>>> = OnceLock::new();
574575

575576
/// Constructs a new handle to the standard output of the current process.
576577
///
@@ -624,7 +625,7 @@ static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLo
624625
pub fn stdout() -> Stdout {
625626
Stdout {
626627
inner: STDOUT
627-
.get_or_init(|| ReentrantMutex::new(RefCell::new(LineWriter::new(stdout_raw())))),
628+
.get_or_init(|| ReentrantLock::new(RefCell::new(LineWriter::new(stdout_raw())))),
628629
}
629630
}
630631

@@ -635,7 +636,7 @@ pub fn cleanup() {
635636
let mut initialized = false;
636637
let stdout = STDOUT.get_or_init(|| {
637638
initialized = true;
638-
ReentrantMutex::new(RefCell::new(LineWriter::with_capacity(0, stdout_raw())))
639+
ReentrantLock::new(RefCell::new(LineWriter::with_capacity(0, stdout_raw())))
639640
});
640641

641642
if !initialized {
@@ -678,6 +679,12 @@ impl Stdout {
678679
}
679680
}
680681

682+
#[stable(feature = "catch_unwind", since = "1.9.0")]
683+
impl UnwindSafe for Stdout {}
684+
685+
#[stable(feature = "catch_unwind", since = "1.9.0")]
686+
impl RefUnwindSafe for Stdout {}
687+
681688
#[stable(feature = "std_debug", since = "1.16.0")]
682689
impl fmt::Debug for Stdout {
683690
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -737,6 +744,12 @@ impl Write for &Stdout {
737744
}
738745
}
739746

747+
#[stable(feature = "catch_unwind", since = "1.9.0")]
748+
impl UnwindSafe for StdoutLock<'_> {}
749+
750+
#[stable(feature = "catch_unwind", since = "1.9.0")]
751+
impl RefUnwindSafe for StdoutLock<'_> {}
752+
740753
#[stable(feature = "rust1", since = "1.0.0")]
741754
impl Write for StdoutLock<'_> {
742755
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
@@ -786,7 +799,7 @@ impl fmt::Debug for StdoutLock<'_> {
786799
/// standard library or via raw Windows API calls, will fail.
787800
#[stable(feature = "rust1", since = "1.0.0")]
788801
pub struct Stderr {
789-
inner: &'static ReentrantMutex<RefCell<StderrRaw>>,
802+
inner: &'static ReentrantLock<RefCell<StderrRaw>>,
790803
}
791804

792805
/// A locked reference to the [`Stderr`] handle.
@@ -808,7 +821,7 @@ pub struct Stderr {
808821
#[must_use = "if unused stderr will immediately unlock"]
809822
#[stable(feature = "rust1", since = "1.0.0")]
810823
pub struct StderrLock<'a> {
811-
inner: ReentrantMutexGuard<'a, RefCell<StderrRaw>>,
824+
inner: ReentrantLockGuard<'a, RefCell<StderrRaw>>,
812825
}
813826

814827
/// Constructs a new handle to the standard error of the current process.
@@ -862,8 +875,8 @@ pub fn stderr() -> Stderr {
862875
// Note that unlike `stdout()` we don't use `at_exit` here to register a
863876
// destructor. Stderr is not buffered, so there's no need to run a
864877
// destructor for flushing the buffer
865-
static INSTANCE: ReentrantMutex<RefCell<StderrRaw>> =
866-
ReentrantMutex::new(RefCell::new(stderr_raw()));
878+
static INSTANCE: ReentrantLock<RefCell<StderrRaw>> =
879+
ReentrantLock::new(RefCell::new(stderr_raw()));
867880

868881
Stderr { inner: &INSTANCE }
869882
}
@@ -898,6 +911,12 @@ impl Stderr {
898911
}
899912
}
900913

914+
#[stable(feature = "catch_unwind", since = "1.9.0")]
915+
impl UnwindSafe for Stderr {}
916+
917+
#[stable(feature = "catch_unwind", since = "1.9.0")]
918+
impl RefUnwindSafe for Stderr {}
919+
901920
#[stable(feature = "std_debug", since = "1.16.0")]
902921
impl fmt::Debug for Stderr {
903922
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -957,6 +976,12 @@ impl Write for &Stderr {
957976
}
958977
}
959978

979+
#[stable(feature = "catch_unwind", since = "1.9.0")]
980+
impl UnwindSafe for StderrLock<'_> {}
981+
982+
#[stable(feature = "catch_unwind", since = "1.9.0")]
983+
impl RefUnwindSafe for StderrLock<'_> {}
984+
960985
#[stable(feature = "rust1", since = "1.0.0")]
961986
impl Write for StderrLock<'_> {
962987
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {

library/std/src/sync/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ pub use self::lazy_lock::LazyLock;
184184
#[stable(feature = "once_cell", since = "1.70.0")]
185185
pub use self::once_lock::OnceLock;
186186

187-
pub(crate) use self::remutex::{ReentrantMutex, ReentrantMutexGuard};
187+
#[unstable(feature = "reentrant_lock", issue = "121440")]
188+
pub use self::reentrant_lock::{ReentrantLock, ReentrantLockGuard};
188189

189190
pub mod mpsc;
190191

@@ -196,5 +197,5 @@ mod mutex;
196197
pub(crate) mod once;
197198
mod once_lock;
198199
mod poison;
199-
mod remutex;
200+
mod reentrant_lock;
200201
mod rwlock;

0 commit comments

Comments
 (0)