Skip to content

Commit b8967b0

Browse files
committed
Auto merge of #94225 - matthiaskrgr:rollup-0728x8n, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #91192 (Some improvements to the async docs) - #94143 (rustc_const_eval: adopt let else in more places) - #94156 (Gracefully handle non-UTF-8 string slices when pretty printing) - #94186 (Update pin_static_ref stabilization version.) - #94189 (Implement LowerHex on Scalar to clean up their display in rustdoc) - #94190 (Use Metadata::modified instead of FileTime::from_last_modification_ti…) - #94203 (CTFE engine: Scalar: expose size-generic to_(u)int methods) - #94211 (Better error if the user tries to do assignment ... else) - #94215 (trait system: comments and small nonfunctional changes) - #94220 (Correctly handle miniz_oxide extern crate declaration) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 03a8cc7 + ed35309 commit b8967b0

File tree

36 files changed

+260
-244
lines changed

36 files changed

+260
-244
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,8 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
231231
// Catch such calls and evaluate them instead of trying to load a constant's MIR.
232232
if let ty::InstanceDef::Intrinsic(def_id) = key.value.instance.def {
233233
let ty = key.value.instance.ty(tcx, key.param_env);
234-
let substs = match ty.kind() {
235-
ty::FnDef(_, substs) => substs,
236-
_ => bug!("intrinsic with type {:?}", ty),
234+
let ty::FnDef(_, substs) = ty.kind() else {
235+
bug!("intrinsic with type {:?}", ty);
237236
};
238237
return eval_nullary_intrinsic(tcx, key.param_env, def_id, substs).map_err(|error| {
239238
let span = tcx.def_span(def_id);

compiler/rustc_const_eval/src/const_eval/machine.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,12 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
318318
let intrinsic_name = ecx.tcx.item_name(instance.def_id());
319319

320320
// CTFE-specific intrinsics.
321-
let (dest, ret) = match ret {
322-
None => {
323-
return Err(ConstEvalErrKind::NeedsRfc(format!(
324-
"calling intrinsic `{}`",
325-
intrinsic_name
326-
))
327-
.into());
328-
}
329-
Some(p) => p,
321+
let Some((dest, ret)) = ret else {
322+
return Err(ConstEvalErrKind::NeedsRfc(format!(
323+
"calling intrinsic `{}`",
324+
intrinsic_name
325+
))
326+
.into());
330327
};
331328
match intrinsic_name {
332329
sym::ptr_guaranteed_eq | sym::ptr_guaranteed_ne => {

compiler/rustc_const_eval/src/interpret/eval_context.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
631631
// the last field). Can't have foreign types here, how would we
632632
// adjust alignment and size for them?
633633
let field = layout.field(self, layout.fields.count() - 1);
634-
let (unsized_size, unsized_align) =
635-
match self.size_and_align_of(metadata, &field)? {
636-
Some(size_and_align) => size_and_align,
637-
None => {
638-
// A field with an extern type. We don't know the actual dynamic size
639-
// or the alignment.
640-
return Ok(None);
641-
}
642-
};
634+
let Some((unsized_size, unsized_align)) = self.size_and_align_of(metadata, &field)? else {
635+
// A field with an extern type. We don't know the actual dynamic size
636+
// or the alignment.
637+
return Ok(None);
638+
};
643639

644640
// FIXME (#26403, #27023): We should be adding padding
645641
// to `sized_size` (to accommodate the `unsized_align`

compiler/rustc_const_eval/src/interpret/intern.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,19 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
8484
trace!("intern_shallow {:?} with {:?}", alloc_id, mode);
8585
// remove allocation
8686
let tcx = ecx.tcx;
87-
let (kind, mut alloc) = match ecx.memory.alloc_map.remove(&alloc_id) {
88-
Some(entry) => entry,
89-
None => {
90-
// Pointer not found in local memory map. It is either a pointer to the global
91-
// map, or dangling.
92-
// If the pointer is dangling (neither in local nor global memory), we leave it
93-
// to validation to error -- it has the much better error messages, pointing out where
94-
// in the value the dangling reference lies.
95-
// The `delay_span_bug` ensures that we don't forget such a check in validation.
96-
if tcx.get_global_alloc(alloc_id).is_none() {
97-
tcx.sess.delay_span_bug(ecx.tcx.span, "tried to intern dangling pointer");
98-
}
99-
// treat dangling pointers like other statics
100-
// just to stop trying to recurse into them
101-
return Some(IsStaticOrFn);
87+
let Some((kind, mut alloc)) = ecx.memory.alloc_map.remove(&alloc_id) else {
88+
// Pointer not found in local memory map. It is either a pointer to the global
89+
// map, or dangling.
90+
// If the pointer is dangling (neither in local nor global memory), we leave it
91+
// to validation to error -- it has the much better error messages, pointing out where
92+
// in the value the dangling reference lies.
93+
// The `delay_span_bug` ensures that we don't forget such a check in validation.
94+
if tcx.get_global_alloc(alloc_id).is_none() {
95+
tcx.sess.delay_span_bug(ecx.tcx.span, "tried to intern dangling pointer");
10296
}
97+
// treat dangling pointers like other statics
98+
// just to stop trying to recurse into them
99+
return Some(IsStaticOrFn);
103100
};
104101
// This match is just a canary for future changes to `MemoryKind`, which most likely need
105102
// changes in this function.

compiler/rustc_const_eval/src/interpret/memory.rs

+27-33
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
291291
);
292292
}
293293

294-
let (alloc_kind, mut alloc) = match self.alloc_map.remove(&alloc_id) {
295-
Some(alloc) => alloc,
296-
None => {
297-
// Deallocating global memory -- always an error
298-
return Err(match self.tcx.get_global_alloc(alloc_id) {
299-
Some(GlobalAlloc::Function(..)) => {
300-
err_ub_format!("deallocating {}, which is a function", alloc_id)
301-
}
302-
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
303-
err_ub_format!("deallocating {}, which is static memory", alloc_id)
304-
}
305-
None => err_ub!(PointerUseAfterFree(alloc_id)),
294+
let Some((alloc_kind, mut alloc)) = self.alloc_map.remove(&alloc_id) else {
295+
// Deallocating global memory -- always an error
296+
return Err(match self.tcx.get_global_alloc(alloc_id) {
297+
Some(GlobalAlloc::Function(..)) => {
298+
err_ub_format!("deallocating {}, which is a function", alloc_id)
306299
}
307-
.into());
300+
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
301+
err_ub_format!("deallocating {}, which is static memory", alloc_id)
302+
}
303+
None => err_ub!(PointerUseAfterFree(alloc_id)),
308304
}
305+
.into());
309306
};
310307

311308
if alloc.mutability == Mutability::Not {
@@ -957,9 +954,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
957954
ptr: Pointer<Option<M::PointerTag>>,
958955
size: Size,
959956
) -> InterpResult<'tcx, &[u8]> {
960-
let alloc_ref = match self.get(ptr, size, Align::ONE)? {
961-
Some(a) => a,
962-
None => return Ok(&[]), // zero-sized access
957+
let Some(alloc_ref) = self.get(ptr, size, Align::ONE)? else {
958+
// zero-sized access
959+
return Ok(&[]);
963960
};
964961
// Side-step AllocRef and directly access the underlying bytes more efficiently.
965962
// (We are staying inside the bounds here so all is good.)
@@ -983,17 +980,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
983980
assert_eq!(lower, len, "can only write iterators with a precise length");
984981

985982
let size = Size::from_bytes(len);
986-
let alloc_ref = match self.get_mut(ptr, size, Align::ONE)? {
987-
Some(alloc_ref) => alloc_ref,
988-
None => {
989-
// zero-sized access
990-
assert_matches!(
991-
src.next(),
992-
None,
993-
"iterator said it was empty but returned an element"
994-
);
995-
return Ok(());
996-
}
983+
let Some(alloc_ref) = self.get_mut(ptr, size, Align::ONE)? else {
984+
// zero-sized access
985+
assert_matches!(
986+
src.next(),
987+
None,
988+
"iterator said it was empty but returned an element"
989+
);
990+
return Ok(());
997991
};
998992

999993
// Side-step AllocRef and directly access the underlying bytes more efficiently.
@@ -1043,18 +1037,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
10431037
// and once below to get the underlying `&[mut] Allocation`.
10441038

10451039
// Source alloc preparations and access hooks.
1046-
let (src_alloc_id, src_offset, src) = match src_parts {
1047-
None => return Ok(()), // Zero-sized *source*, that means dst is also zero-sized and we have nothing to do.
1048-
Some(src_ptr) => src_ptr,
1040+
let Some((src_alloc_id, src_offset, src)) = src_parts else {
1041+
// Zero-sized *source*, that means dst is also zero-sized and we have nothing to do.
1042+
return Ok(());
10491043
};
10501044
let src_alloc = self.get_raw(src_alloc_id)?;
10511045
let src_range = alloc_range(src_offset, size);
10521046
M::memory_read(&self.extra, &src_alloc.extra, src.provenance, src_range)?;
10531047
// We need the `dest` ptr for the next operation, so we get it now.
10541048
// We already did the source checks and called the hooks so we are good to return early.
1055-
let (dest_alloc_id, dest_offset, dest) = match dest_parts {
1056-
None => return Ok(()), // Zero-sized *destiantion*.
1057-
Some(dest_ptr) => dest_ptr,
1049+
let Some((dest_alloc_id, dest_offset, dest)) = dest_parts else {
1050+
// Zero-sized *destination*.
1051+
return Ok(());
10581052
};
10591053

10601054
// This checks relocation edges on the src, which needs to happen before

compiler/rustc_const_eval/src/interpret/operand.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
258258
return Ok(None);
259259
}
260260

261-
let alloc = match self.get_alloc(mplace)? {
262-
Some(ptr) => ptr,
263-
None => {
264-
return Ok(Some(ImmTy {
265-
// zero-sized type
266-
imm: Scalar::ZST.into(),
267-
layout: mplace.layout,
268-
}));
269-
}
261+
let Some(alloc) = self.get_alloc(mplace)? else {
262+
return Ok(Some(ImmTy {
263+
// zero-sized type
264+
imm: Scalar::ZST.into(),
265+
layout: mplace.layout,
266+
}));
270267
};
271268

272269
match mplace.layout.abi {

compiler/rustc_const_eval/src/interpret/place.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,8 @@ where
420420
) -> InterpResult<'tcx, impl Iterator<Item = InterpResult<'tcx, MPlaceTy<'tcx, Tag>>> + 'a>
421421
{
422422
let len = base.len(self)?; // also asserts that we have a type where this makes sense
423-
let stride = match base.layout.fields {
424-
FieldsShape::Array { stride, .. } => stride,
425-
_ => span_bug!(self.cur_span(), "mplace_array_fields: expected an array layout"),
423+
let FieldsShape::Array { stride, .. } = base.layout.fields else {
424+
span_bug!(self.cur_span(), "mplace_array_fields: expected an array layout");
426425
};
427426
let layout = base.layout.field(self, 0);
428427
let dl = &self.tcx.data_layout;
@@ -747,9 +746,9 @@ where
747746

748747
// Invalid places are a thing: the return place of a diverging function
749748
let tcx = *self.tcx;
750-
let mut alloc = match self.get_alloc_mut(dest)? {
751-
Some(a) => a,
752-
None => return Ok(()), // zero-sized access
749+
let Some(mut alloc) = self.get_alloc_mut(dest)? else {
750+
// zero-sized access
751+
return Ok(());
753752
};
754753

755754
// FIXME: We should check that there are dest.layout.size many bytes available in

compiler/rustc_const_eval/src/interpret/step.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4646
return Ok(false);
4747
}
4848

49-
let loc = match self.frame().loc {
50-
Ok(loc) => loc,
51-
Err(_) => {
52-
// We are unwinding and this fn has no cleanup code.
53-
// Just go on unwinding.
54-
trace!("unwinding: skipping frame");
55-
self.pop_stack_frame(/* unwinding */ true)?;
56-
return Ok(true);
57-
}
49+
let Ok(loc) = self.frame().loc else {
50+
// We are unwinding and this fn has no cleanup code.
51+
// Just go on unwinding.
52+
trace!("unwinding: skipping frame");
53+
self.pop_stack_frame(/* unwinding */ true)?;
54+
return Ok(true);
5855
};
5956
let basic_block = &self.body().basic_blocks()[loc.block];
6057

compiler/rustc_const_eval/src/interpret/terminator.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
321321
| ty::InstanceDef::CloneShim(..)
322322
| ty::InstanceDef::Item(_) => {
323323
// We need MIR for this fn
324-
let (body, instance) =
325-
match M::find_mir_or_eval_fn(self, instance, caller_abi, args, ret, unwind)? {
326-
Some(body) => body,
327-
None => return Ok(()),
324+
let Some((body, instance)) =
325+
M::find_mir_or_eval_fn(self, instance, caller_abi, args, ret, unwind)? else {
326+
return Ok(());
328327
};
329328

330329
// Compute callee information using the `instance` returned by

compiler/rustc_const_eval/src/interpret/validity.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
697697
this.ecx.read_discriminant(op),
698698
this.path,
699699
err_ub!(InvalidTag(val)) =>
700-
{ "{}", val } expected { "a valid enum tag" },
700+
{ "{:x}", val } expected { "a valid enum tag" },
701701
err_ub!(InvalidUninitBytes(None)) =>
702702
{ "uninitialized bytes" } expected { "a valid enum tag" },
703703
err_unsup!(ReadPointerAsBytes) =>
@@ -851,12 +851,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
851851
// to reject those pointers, we just do not have the machinery to
852852
// talk about parts of a pointer.
853853
// We also accept uninit, for consistency with the slow path.
854-
let alloc = match self.ecx.memory.get(mplace.ptr, size, mplace.align)? {
855-
Some(a) => a,
856-
None => {
857-
// Size 0, nothing more to check.
858-
return Ok(());
859-
}
854+
let Some(alloc) = self.ecx.memory.get(mplace.ptr, size, mplace.align)? else {
855+
// Size 0, nothing more to check.
856+
return Ok(());
860857
};
861858

862859
let allow_uninit_and_ptr = !M::enforce_number_validity(self.ecx);

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,8 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
134134
.find(|(_, block)| matches!(block.terminator().kind, TerminatorKind::Return))
135135
.map(|(bb, _)| bb);
136136

137-
let return_block = match return_block {
138-
None => {
139-
return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), tainted_by_errors);
140-
}
141-
Some(bb) => bb,
137+
let Some(return_block) = return_block else {
138+
return qualifs::in_any_value_of_ty(ccx, ccx.body.return_ty(), tainted_by_errors);
142139
};
143140

144141
let return_loc = ccx.body.terminator_loc(return_block);

compiler/rustc_const_eval/src/transform/promote_consts.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -747,15 +747,12 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
747747
if loc.statement_index < num_stmts {
748748
let (mut rvalue, source_info) = {
749749
let statement = &mut self.source[loc.block].statements[loc.statement_index];
750-
let rhs = match statement.kind {
751-
StatementKind::Assign(box (_, ref mut rhs)) => rhs,
752-
_ => {
753-
span_bug!(
754-
statement.source_info.span,
755-
"{:?} is not an assignment",
756-
statement
757-
);
758-
}
750+
let StatementKind::Assign(box (_, ref mut rhs)) = statement.kind else {
751+
span_bug!(
752+
statement.source_info.span,
753+
"{:?} is not an assignment",
754+
statement
755+
);
759756
};
760757

761758
(

compiler/rustc_const_eval/src/util/alignment.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ where
1515
L: HasLocalDecls<'tcx>,
1616
{
1717
debug!("is_disaligned({:?})", place);
18-
let pack = match is_within_packed(tcx, local_decls, place) {
19-
None => {
20-
debug!("is_disaligned({:?}) - not within packed", place);
21-
return false;
22-
}
23-
Some(pack) => pack,
18+
let Some(pack) = is_within_packed(tcx, local_decls, place) else {
19+
debug!("is_disaligned({:?}) - not within packed", place);
20+
return false;
2421
};
2522

2623
let ty = place.ty(local_decls, tcx).ty;

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ type ObligationTreeIdGenerator =
132132
std::iter::Map<std::ops::RangeFrom<usize>, fn(usize) -> ObligationTreeId>;
133133

134134
pub struct ObligationForest<O: ForestObligation> {
135-
/// The list of obligations. In between calls to `process_obligations`,
135+
/// The list of obligations. In between calls to [Self::process_obligations],
136136
/// this list only contains nodes in the `Pending` or `Waiting` state.
137137
///
138138
/// `usize` indices are used here and throughout this module, rather than
139-
/// `rustc_index::newtype_index!` indices, because this code is hot enough
139+
/// [`rustc_index::newtype_index!`] indices, because this code is hot enough
140140
/// that the `u32`-to-`usize` conversions that would be required are
141141
/// significant, and space considerations are not important.
142142
nodes: Vec<Node<O>>,
@@ -146,10 +146,11 @@ pub struct ObligationForest<O: ForestObligation> {
146146

147147
/// A cache of the nodes in `nodes`, indexed by predicate. Unfortunately,
148148
/// its contents are not guaranteed to match those of `nodes`. See the
149-
/// comments in `process_obligation` for details.
149+
/// comments in [`Self::process_obligation` for details.
150150
active_cache: FxHashMap<O::CacheKey, usize>,
151151

152-
/// A vector reused in compress() and find_cycles_from_node(), to avoid allocating new vectors.
152+
/// A vector reused in [Self::compress()] and [Self::find_cycles_from_node()],
153+
/// to avoid allocating new vectors.
153154
reused_node_vec: Vec<usize>,
154155

155156
obligation_tree_id_generator: ObligationTreeIdGenerator,

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
123123
result
124124
}
125125

126-
/// See `infer::region_constraints::RegionConstraintCollector::leak_check`.
126+
/// See [RegionConstraintCollector::leak_check][1].
127+
///
128+
/// [1]: crate::infer::region_constraints::RegionConstraintCollector::leak_check
127129
pub fn leak_check(
128130
&self,
129131
overly_polymorphic: bool,

compiler/rustc_infer/src/infer/region_constraints/leak_check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
100100
struct LeakCheck<'me, 'tcx> {
101101
tcx: TyCtxt<'tcx>,
102102
universe_at_start_of_snapshot: ty::UniverseIndex,
103+
/// Only used when reporting region errors.
103104
overly_polymorphic: bool,
104105
mini_graph: &'me MiniGraph<'tcx>,
105106
rcc: &'me RegionConstraintCollector<'me, 'tcx>,

0 commit comments

Comments
 (0)