Skip to content

Commit 2960971

Browse files
authored
Rollup merge of #82759 - m-ou-se:remove-unwrap-none, r=petrochenkov
Remove unwrap_none/expect_none from compiler/. We're not going to stabilize `Option::{unwrap_none, expect_none}`. (See #62633.) This removes the usage of those unstable methods from `compiler/`.
2 parents 4abcd40 + cfb4ad4 commit 2960971

File tree

10 files changed

+38
-23
lines changed

10 files changed

+38
-23
lines changed

Diff for: compiler/rustc_codegen_ssa/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2+
#![feature(assert_matches)]
23
#![feature(bool_to_option)]
3-
#![feature(option_expect_none)]
44
#![feature(box_patterns)]
55
#![feature(drain_filter)]
66
#![feature(try_blocks)]

Diff for: compiler/rustc_middle/src/ich/impls_syntax.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> {
4545
item.hash_stable(self, hasher);
4646
style.hash_stable(self, hasher);
4747
span.hash_stable(self, hasher);
48-
tokens.as_ref().expect_none("Tokens should have been removed during lowering!");
48+
assert_matches!(
49+
tokens.as_ref(),
50+
None,
51+
"Tokens should have been removed during lowering!"
52+
);
4953
} else {
5054
unreachable!();
5155
}

Diff for: compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2626
#![feature(array_windows)]
27+
#![feature(assert_matches)]
2728
#![feature(assoc_char_funcs)]
2829
#![feature(backtrace)]
2930
#![feature(bool_to_option)]
@@ -38,7 +39,6 @@
3839
#![feature(extern_types)]
3940
#![feature(nll)]
4041
#![feature(once_cell)]
41-
#![feature(option_expect_none)]
4242
#![feature(or_patterns)]
4343
#![feature(min_specialization)]
4444
#![feature(trusted_len)]

Diff for: compiler/rustc_middle/src/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
339339
for dest in bytes {
340340
*dest = src.next().expect("iterator was shorter than it said it would be");
341341
}
342-
src.next().expect_none("iterator was longer than it said it would be");
342+
assert_matches!(src.next(), None, "iterator was longer than it said it would be");
343343
Ok(())
344344
}
345345

Diff for: compiler/rustc_mir/src/interpret/memory.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
854854
Some(ptr) => ptr,
855855
None => {
856856
// zero-sized access
857-
src.next().expect_none("iterator said it was empty but returned an element");
857+
assert_matches!(
858+
src.next(),
859+
None,
860+
"iterator said it was empty but returned an element"
861+
);
858862
return Ok(());
859863
}
860864
};
@@ -880,7 +884,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
880884
Some(ptr) => ptr,
881885
None => {
882886
// zero-sized access
883-
src.next().expect_none("iterator said it was empty but returned an element");
887+
assert_matches!(
888+
src.next(),
889+
None,
890+
"iterator said it was empty but returned an element"
891+
);
884892
return Ok(());
885893
}
886894
};
@@ -894,7 +902,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
894902
let offset_ptr = ptr.offset(Size::from_bytes(idx) * 2, &tcx)?; // `Size` multiplication
895903
allocation.write_scalar(&tcx, offset_ptr, val.into(), Size::from_bytes(2))?;
896904
}
897-
src.next().expect_none("iterator was longer than it said it would be");
905+
assert_matches!(src.next(), None, "iterator was longer than it said it would be");
898906
Ok(())
899907
}
900908

Diff for: compiler/rustc_mir/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Rust MIR: a lowered representation of Rust.
77
#![feature(nll)]
88
#![feature(in_band_lifetimes)]
99
#![feature(array_windows)]
10+
#![feature(assert_matches)]
1011
#![feature(bindings_after_at)]
1112
#![feature(bool_to_option)]
1213
#![feature(box_patterns)]
@@ -18,13 +19,13 @@ Rust MIR: a lowered representation of Rust.
1819
#![feature(exact_size_is_empty)]
1920
#![feature(exhaustive_patterns)]
2021
#![feature(never_type)]
22+
#![feature(map_try_insert)]
2123
#![feature(min_specialization)]
2224
#![feature(trusted_len)]
2325
#![feature(try_blocks)]
2426
#![feature(associated_type_defaults)]
2527
#![feature(stmt_expr_attributes)]
2628
#![feature(trait_alias)]
27-
#![feature(option_expect_none)]
2829
#![feature(option_get_or_insert_default)]
2930
#![feature(or_patterns)]
3031
#![feature(once_cell)]

Diff for: compiler/rustc_mir/src/transform/coverage/debug.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,8 @@ impl DebugCounters {
285285
),
286286
};
287287
counters
288-
.insert(id, DebugCounter::new(counter_kind.clone(), some_block_label))
289-
.expect_none(
290-
"attempt to add the same counter_kind to DebugCounters more than once",
291-
);
288+
.try_insert(id, DebugCounter::new(counter_kind.clone(), some_block_label))
289+
.expect("attempt to add the same counter_kind to DebugCounters more than once");
292290
}
293291
}
294292

@@ -479,9 +477,9 @@ impl GraphvizData {
479477
counter_kind: &CoverageKind,
480478
) {
481479
if let Some(edge_to_counter) = self.some_edge_to_counter.as_mut() {
482-
edge_to_counter.insert((from_bcb, to_bb), counter_kind.clone()).expect_none(
483-
"invalid attempt to insert more than one edge counter for the same edge",
484-
);
480+
edge_to_counter
481+
.try_insert((from_bcb, to_bb), counter_kind.clone())
482+
.expect("invalid attempt to insert more than one edge counter for the same edge");
485483
}
486484
}
487485

Diff for: compiler/rustc_mir/src/transform/deduplicate_blocks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn find_duplicates<'a, 'tcx>(body: &'a Body<'tcx>) -> FxHashMap<BasicBlock, Basi
8686
// The basic block was already in the hashmap, which means we have a duplicate
8787
let value = *occupied.get();
8888
debug!("Inserting {:?} -> {:?}", bb, value);
89-
duplicates.insert(bb, value).expect_none("key was already inserted");
89+
duplicates.try_insert(bb, value).expect("key was already inserted");
9090
}
9191
Entry::Vacant(vacant) => {
9292
vacant.insert(bb);

Diff for: compiler/rustc_span/src/hygiene.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ impl ExpnId {
118118
HygieneData::with(|data| {
119119
let old_expn_data = &mut data.expn_data[self.0 as usize];
120120
assert!(old_expn_data.is_none(), "expansion data is reset for an expansion ID");
121-
expn_data.orig_id.replace(self.as_u32()).expect_none("orig_id should be None");
121+
assert_eq!(expn_data.orig_id, None);
122+
expn_data.orig_id = Some(self.as_u32());
122123
*old_expn_data = Some(expn_data);
123124
});
124125
update_disambiguator(self)
@@ -202,7 +203,8 @@ impl HygieneData {
202203
fn fresh_expn(&mut self, mut expn_data: Option<ExpnData>) -> ExpnId {
203204
let raw_id = self.expn_data.len() as u32;
204205
if let Some(data) = expn_data.as_mut() {
205-
data.orig_id.replace(raw_id).expect_none("orig_id should be None");
206+
assert_eq!(data.orig_id, None);
207+
data.orig_id = Some(raw_id);
206208
}
207209
self.expn_data.push(expn_data);
208210
ExpnId(raw_id)
@@ -1410,9 +1412,11 @@ fn update_disambiguator(expn_id: ExpnId) {
14101412
let new_hash: Fingerprint = hasher.finish();
14111413

14121414
HygieneData::with(|data| {
1413-
data.expn_data_disambiguators
1414-
.get(&new_hash)
1415-
.expect_none("Hash collision after disambiguator update!");
1415+
assert_eq!(
1416+
data.expn_data_disambiguators.get(&new_hash),
1417+
None,
1418+
"Hash collision after disambiguator update!",
1419+
);
14161420
});
14171421
};
14181422
}

Diff for: compiler/rustc_span/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#![feature(negative_impls)]
2222
#![feature(nll)]
2323
#![feature(min_specialization)]
24-
#![feature(option_expect_none)]
2524

2625
#[macro_use]
2726
extern crate rustc_macros;
@@ -1996,7 +1995,8 @@ impl<CTX: HashStableContext> HashStable<CTX> for ExpnId {
19961995
if cache.len() < new_len {
19971996
cache.resize(new_len, None);
19981997
}
1999-
cache[index].replace(sub_hash).expect_none("Cache slot was filled");
1998+
let prev = cache[index].replace(sub_hash);
1999+
assert_eq!(prev, None, "Cache slot was filled");
20002000
});
20012001
sub_hash.hash_stable(ctx, hasher);
20022002
}

0 commit comments

Comments
 (0)