Skip to content

Commit a357411

Browse files
committed
Auto merge of #128719 - matthiaskrgr:rollup-rbjs7bc, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #122792 (Stabilize `min_exhaustive_patterns`) - #124944 (On trait bound mismatch, detect multiple crate versions in dep tree) - #128273 (Improve `Ord` violation help) - #128406 (implement BufReader::peek) - #128539 (Forbid unused unsafe in vxworks-specific std modules) - #128692 (Add a triagebot mention for `library/Cargo.lock`) - #128710 (Don't ICE when getting an input file name's stem fails) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8c7e0e1 + db95a01 commit a357411

File tree

116 files changed

+1477
-1070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+1477
-1070
lines changed

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

+1
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ pub enum E2<X> {
585585
V4,
586586
}
587587

588+
#[allow(unreachable_patterns)]
588589
fn check_niche_behavior() {
589590
if let E1::V2 { .. } = (E1::V1 { f: true }) {
590591
intrinsics::abort();

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

+1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ pub enum E2<X> {
430430
V4,
431431
}
432432

433+
#[allow(unreachable_patterns)]
433434
fn check_niche_behavior () {
434435
if let E1::V2 { .. } = (E1::V1 { f: true }) {
435436
intrinsics::abort();

compiler/rustc_errors/src/diagnostic.rs

+21
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,16 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
741741
self
742742
}
743743

744+
#[rustc_lint_diagnostics]
745+
pub fn highlighted_span_note(
746+
&mut self,
747+
span: impl Into<MultiSpan>,
748+
msg: Vec<StringPart>,
749+
) -> &mut Self {
750+
self.sub_with_highlights(Level::Note, msg, span.into());
751+
self
752+
}
753+
744754
/// This is like [`Diag::note()`], but it's only printed once.
745755
#[rustc_lint_diagnostics]
746756
pub fn note_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
@@ -815,6 +825,17 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
815825
self
816826
}
817827

828+
/// Add a help message attached to this diagnostic with a customizable highlighted message.
829+
#[rustc_lint_diagnostics]
830+
pub fn highlighted_span_help(
831+
&mut self,
832+
span: impl Into<MultiSpan>,
833+
msg: Vec<StringPart>,
834+
) -> &mut Self {
835+
self.sub_with_highlights(Level::Help, msg, span.into());
836+
self
837+
}
838+
818839
/// Prints the span with some help above it.
819840
/// This is like [`Diag::help()`], but it gets its own span.
820841
#[rustc_lint_diagnostics]

compiler/rustc_errors/src/diagnostic_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ macro_rules! into_diag_arg_for_number {
6666
impl IntoDiagArg for $ty {
6767
fn into_diag_arg(self) -> DiagArgValue {
6868
// Convert to a string if it won't fit into `Number`.
69+
#[allow(irrefutable_let_patterns)]
6970
if let Ok(n) = TryInto::<i32>::try_into(self) {
7071
DiagArgValue::Number(n)
7172
} else {

compiler/rustc_errors/src/emitter.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ impl HumanEmitter {
13461346
buffer.append(0, ": ", header_style);
13471347
label_width += 2;
13481348
}
1349-
for (text, _) in msgs.iter() {
1349+
for (text, style) in msgs.iter() {
13501350
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
13511351
// Account for newlines to align output to its label.
13521352
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
@@ -1357,7 +1357,10 @@ impl HumanEmitter {
13571357
if line == 0 { String::new() } else { " ".repeat(label_width) },
13581358
text
13591359
),
1360-
header_style,
1360+
match style {
1361+
Style::Highlight => *style,
1362+
_ => header_style,
1363+
},
13611364
);
13621365
}
13631366
}

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ declare_features! (
267267
(accepted, min_const_generics, "1.51.0", Some(74878)),
268268
/// Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions.
269269
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607)),
270+
/// Allows exhaustive pattern matching on uninhabited types when matched by value.
271+
(accepted, min_exhaustive_patterns, "CURRENT_RUSTC_VERSION", Some(119612)),
270272
/// Allows using `Self` and associated types in struct expressions and patterns.
271273
(accepted, more_struct_aliases, "1.16.0", Some(37544)),
272274
/// Allows using the MOVBE target feature.

compiler/rustc_feature/src/unstable.rs

-3
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,6 @@ declare_features! (
519519
(unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)),
520520
/// Allows `#[marker]` on certain traits allowing overlapping implementations.
521521
(unstable, marker_trait_attr, "1.30.0", Some(29864)),
522-
/// Allows exhaustive pattern matching on types that contain uninhabited types in cases that are
523-
/// unambiguously sound.
524-
(unstable, min_exhaustive_patterns, "1.77.0", Some(119612)),
525522
/// A minimal, sound subset of specialization intended to be used by the
526523
/// standard library until the soundness issues with specialization
527524
/// are fixed.

compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![allow(rustc::diagnostic_outside_of_impl)]
2929
#![allow(rustc::potential_query_instability)]
3030
#![allow(rustc::untranslatable_diagnostic)]
31+
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
3132
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3233
#![doc(rust_logo)]
3334
#![feature(allocator_api)]
@@ -48,7 +49,6 @@
4849
#![feature(iter_from_coroutine)]
4950
#![feature(let_chains)]
5051
#![feature(macro_metavar_expr)]
51-
#![feature(min_exhaustive_patterns)]
5252
#![feature(min_specialization)]
5353
#![feature(negative_impls)]
5454
#![feature(never_type)]

compiler/rustc_mir_build/src/build/matches/match_pair.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,11 @@ impl<'pat, 'tcx> MatchPairTree<'pat, 'tcx> {
208208
subpairs = cx.field_match_pairs(downcast_place, subpatterns);
209209

210210
let irrefutable = adt_def.variants().iter_enumerated().all(|(i, v)| {
211-
i == variant_index || {
212-
(cx.tcx.features().exhaustive_patterns
213-
|| cx.tcx.features().min_exhaustive_patterns)
214-
&& !v
215-
.inhabited_predicate(cx.tcx, adt_def)
216-
.instantiate(cx.tcx, args)
217-
.apply_ignore_module(cx.tcx, cx.param_env)
218-
}
211+
i == variant_index
212+
|| !v
213+
.inhabited_predicate(cx.tcx, adt_def)
214+
.instantiate(cx.tcx, args)
215+
.apply_ignore_module(cx.tcx, cx.param_env)
219216
}) && (adt_def.did().is_local()
220217
|| !adt_def.is_variant_list_non_exhaustive());
221218
if irrefutable {

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
695695

696696
// Emit an extra note if the first uncovered witness would be uninhabited
697697
// if we disregard visibility.
698-
let witness_1_is_privately_uninhabited = if (self.tcx.features().exhaustive_patterns
699-
|| self.tcx.features().min_exhaustive_patterns)
700-
&& let Some(witness_1) = witnesses.get(0)
698+
let witness_1_is_privately_uninhabited = if let Some(witness_1) = witnesses.get(0)
701699
&& let ty::Adt(adt, args) = witness_1.ty().kind()
702700
&& adt.is_enum()
703701
&& let Constructor::Variant(variant_index) = witness_1.ctor()
@@ -1059,7 +1057,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
10591057
err.note("`&str` cannot be matched exhaustively, so a wildcard `_` is necessary");
10601058
} else if cx.is_foreign_non_exhaustive_enum(ty) {
10611059
err.note(format!("`{ty}` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively"));
1062-
} else if cx.is_uninhabited(ty.inner()) && cx.tcx.features().min_exhaustive_patterns {
1060+
} else if cx.is_uninhabited(ty.inner()) {
10631061
// The type is uninhabited yet there is a witness: we must be in the `MaybeInvalid`
10641062
// case.
10651063
err.note(format!("`{ty}` is uninhabited but is not being matched by value, so a wildcard `_` is required"));

compiler/rustc_pattern_analysis/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub trait PatCx: Sized + fmt::Debug {
5454
type PatData: Clone;
5555

5656
fn is_exhaustive_patterns_feature_on(&self) -> bool;
57-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool;
5857

5958
/// The number of fields for this constructor.
6059
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;

compiler/rustc_pattern_analysis/src/rustc.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
237237
let tys = cx.variant_sub_tys(ty, variant).map(|(field, ty)| {
238238
let is_visible =
239239
adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
240-
let is_uninhabited = (cx.tcx.features().exhaustive_patterns
241-
|| cx.tcx.features().min_exhaustive_patterns)
242-
&& cx.is_uninhabited(*ty);
240+
let is_uninhabited = cx.is_uninhabited(*ty);
243241
let skip = is_uninhabited && (!is_visible || is_non_exhaustive);
244242
(ty, PrivateUninhabitedField(skip))
245243
});
@@ -925,9 +923,6 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
925923
fn is_exhaustive_patterns_feature_on(&self) -> bool {
926924
self.tcx.features().exhaustive_patterns
927925
}
928-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
929-
self.tcx.features().min_exhaustive_patterns
930-
}
931926

932927
fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: &Self::Ty) -> usize {
933928
self.ctor_arity(ctor, *ty)

compiler/rustc_pattern_analysis/src/usefulness.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,11 @@
543543
//! recurse into subpatterns. That second part is done through [`PlaceValidity`], most notably
544544
//! [`PlaceValidity::specialize`].
545545
//!
546-
//! Having said all that, in practice we don't fully follow what's been presented in this section.
547-
//! Let's call "toplevel exception" the case where the match scrutinee itself has type `!` or
548-
//! `EmptyEnum`. First, on stable rust, we require `_` patterns for empty types in all cases apart
549-
//! from the toplevel exception. The `exhaustive_patterns` and `min_exaustive_patterns` allow
550-
//! omitting patterns in the cases described above. There's a final detail: in the toplevel
551-
//! exception or with the `exhaustive_patterns` feature, we ignore place validity when checking
552-
//! whether a pattern is required for exhaustiveness. I (Nadrieril) hope to deprecate this behavior.
546+
//! Having said all that, we don't fully follow what's been presented in this section. For
547+
//! backwards-compatibility, we ignore place validity when checking whether a pattern is required
548+
//! for exhaustiveness in two cases: when the `exhaustive_patterns` feature gate is on, or when the
549+
//! match scrutinee itself has type `!` or `EmptyEnum`. I (Nadrieril) hope to deprecate this
550+
//! exception.
553551
//!
554552
//!
555553
//!
@@ -953,13 +951,10 @@ impl<Cx: PatCx> PlaceInfo<Cx> {
953951
self.is_scrutinee && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
954952
// Whether empty patterns are counted as useful or not. We only warn an empty arm unreachable if
955953
// it is guaranteed unreachable by the opsem (i.e. if the place is `known_valid`).
956-
let empty_arms_are_unreachable = self.validity.is_known_valid()
957-
&& (is_toplevel_exception
958-
|| cx.is_exhaustive_patterns_feature_on()
959-
|| cx.is_min_exhaustive_patterns_feature_on());
954+
let empty_arms_are_unreachable = self.validity.is_known_valid();
960955
// Whether empty patterns can be omitted for exhaustiveness. We ignore place validity in the
961956
// toplevel exception and `exhaustive_patterns` cases for backwards compatibility.
962-
let can_omit_empty_arms = empty_arms_are_unreachable
957+
let can_omit_empty_arms = self.validity.is_known_valid()
963958
|| is_toplevel_exception
964959
|| cx.is_exhaustive_patterns_feature_on();
965960

compiler/rustc_pattern_analysis/tests/common/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ impl PatCx for Cx {
152152
false
153153
}
154154

155-
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
156-
true
157-
}
158-
159155
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize {
160156
ty.sub_tys(ctor).len()
161157
}

compiler/rustc_session/src/config.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,14 @@ pub enum Input {
838838

839839
impl Input {
840840
pub fn filestem(&self) -> &str {
841-
match *self {
842-
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap(),
843-
Input::Str { .. } => "rust_out",
841+
if let Input::File(ifile) = self {
842+
// If for some reason getting the file stem as a UTF-8 string fails,
843+
// then fallback to a fixed name.
844+
if let Some(name) = ifile.file_stem().and_then(OsStr::to_str) {
845+
return name;
846+
}
844847
}
848+
"rust_out"
845849
}
846850

847851
pub fn source_name(&self) -> FileName {

compiler/rustc_target/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
1010
// tidy-alphabetical-start
1111
#![allow(internal_features)]
12+
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
1213
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1314
#![doc(rust_logo)]
1415
#![feature(assert_matches)]
1516
#![feature(iter_intersperse)]
1617
#![feature(let_chains)]
17-
#![feature(min_exhaustive_patterns)]
1818
#![feature(rustc_attrs)]
1919
#![feature(rustdoc_internals)]
2020
// tidy-alphabetical-end

0 commit comments

Comments
 (0)