Skip to content

Commit 29cbcc6

Browse files
committed
Fix .ok() usage
1 parent 8612db8 commit 29cbcc6

File tree

9 files changed

+28
-37
lines changed

9 files changed

+28
-37
lines changed

compiler/rustc_data_structures/src/jobserver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static GLOBAL_CLIENT: SyncLazy<Client> = SyncLazy::new(|| unsafe {
2222
Client::from_env().unwrap_or_else(|| {
2323
let client = Client::new(32).expect("failed to create jobserver");
2424
// Acquire a token for the main thread which we can release later
25-
client.acquire_raw().ok();
25+
client.acquire_raw().expect("failed to acquire token");
2626
client
2727
})
2828
});
@@ -32,9 +32,9 @@ pub fn client() -> Client {
3232
}
3333

3434
pub fn acquire_thread() {
35-
GLOBAL_CLIENT.acquire_raw().ok();
35+
GLOBAL_CLIENT.acquire_raw().expect("failed to acquire");
3636
}
3737

3838
pub fn release_thread() {
39-
GLOBAL_CLIENT.release_raw().ok();
39+
GLOBAL_CLIENT.release_raw().expect("failed to release");
4040
}

compiler/rustc_interface/src/queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'tcx> Queries<'tcx> {
148148
// load before dep_graph() is called, but it also can't happen
149149
// until after rustc_incremental::prepare_session_directory() is
150150
// called, which happens within passes::register_plugins().
151-
self.dep_graph_future().ok();
151+
self.dep_graph_future()?;
152152

153153
result
154154
})
@@ -273,7 +273,7 @@ impl<'tcx> Queries<'tcx> {
273273
self.ongoing_codegen.compute(|| {
274274
let outputs = self.prepare_outputs()?;
275275
self.global_ctxt()?.peek_mut().enter(|tcx| {
276-
tcx.analysis(LOCAL_CRATE).ok();
276+
tcx.analysis(LOCAL_CRATE)?;
277277

278278
// Don't do code generation if there were any errors
279279
self.session().compile_status()?;

compiler/rustc_parse/src/validate_attr.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) {
2727
_ => {
2828
if let MacArgs::Eq(..) = attr.get_normal_item().args {
2929
// All key-value attributes are restricted to meta-item syntax.
30-
parse_meta(sess, attr)
31-
.map_err(|mut err| {
32-
err.emit();
33-
})
34-
.ok();
30+
let _ = parse_meta(sess, attr).map_err(|mut err| {
31+
err.emit();
32+
});
3533
}
3634
}
3735
}

library/alloc/src/collections/btree/set/tests.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,12 @@ fn test_drain_filter_drop_panic_leak() {
355355
set.insert(D(4));
356356
set.insert(D(8));
357357

358-
catch_unwind(move || {
358+
let _ = catch_unwind(move || {
359359
drop(set.drain_filter(|d| {
360360
PREDS.fetch_add(1u32 << d.0, Ordering::SeqCst);
361361
true
362362
}))
363-
})
364-
.ok();
363+
});
365364

366365
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
367366
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
@@ -385,16 +384,15 @@ fn test_drain_filter_pred_panic_leak() {
385384
set.insert(D(4));
386385
set.insert(D(8));
387386

388-
catch_unwind(AssertUnwindSafe(|| {
387+
let _ = catch_unwind(AssertUnwindSafe(|| {
389388
drop(set.drain_filter(|d| {
390389
PREDS.fetch_add(1u32 << d.0, Ordering::SeqCst);
391390
match d.0 {
392391
0 => true,
393392
_ => panic!(),
394393
}
395394
}))
396-
}))
397-
.ok();
395+
}));
398396

399397
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
400398
assert_eq!(DROPS.load(Ordering::SeqCst), 1);

library/alloc/tests/binary_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn test_drain_sorted_leak() {
315315
D(5, false),
316316
]);
317317

318-
catch_unwind(AssertUnwindSafe(|| drop(q.drain_sorted()))).ok();
318+
let _ = catch_unwind(AssertUnwindSafe(|| drop(q.drain_sorted())));
319319

320320
assert_eq!(DROPS.load(Ordering::SeqCst), 6);
321321
}

library/alloc/tests/linked_list.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ fn drain_filter_drop_panic_leak() {
559559
q.push_front(D(true));
560560
q.push_front(D(false));
561561

562-
catch_unwind(AssertUnwindSafe(|| drop(q.drain_filter(|_| true)))).ok();
562+
let _ = catch_unwind(AssertUnwindSafe(|| drop(q.drain_filter(|_| true))));
563563

564564
assert_eq!(unsafe { DROPS }, 8);
565565
assert!(q.is_empty());
@@ -590,10 +590,9 @@ fn drain_filter_pred_panic_leak() {
590590
q.push_front(D(1));
591591
q.push_front(D(0));
592592

593-
catch_unwind(AssertUnwindSafe(|| {
593+
let _ = catch_unwind(AssertUnwindSafe(|| {
594594
drop(q.drain_filter(|item| if item.0 >= 2 { panic!() } else { true }))
595-
}))
596-
.ok();
595+
}));
597596

598597
assert_eq!(unsafe { DROPS }, 2); // 0 and 1
599598
assert_eq!(q.len(), 6);
@@ -699,7 +698,7 @@ fn test_drop_panic() {
699698
q.push_front(D(false));
700699
q.push_front(D(true));
701700

702-
catch_unwind(move || drop(q)).ok();
701+
let _ = catch_unwind(move || drop(q));
703702

704703
assert_eq!(unsafe { DROPS }, 8);
705704
}

library/alloc/tests/vec.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,9 @@ fn test_drain_leak() {
707707
D(6, false),
708708
];
709709

710-
catch_unwind(AssertUnwindSafe(|| {
710+
let _ = catch_unwind(AssertUnwindSafe(|| {
711711
v.drain(2..=5);
712-
}))
713-
.ok();
712+
}));
714713

715714
assert_eq!(unsafe { DROPS }, 4);
716715
assert_eq!(v, vec![D(0, false), D(1, false), D(6, false),]);
@@ -891,7 +890,7 @@ fn test_into_iter_leak() {
891890

892891
let v = vec![D(false), D(true), D(false)];
893892

894-
catch_unwind(move || drop(v.into_iter())).ok();
893+
let _ = catch_unwind(move || drop(v.into_iter()));
895894

896895
assert_eq!(unsafe { DROPS }, 3);
897896
}

library/alloc/tests/vec_deque.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ fn test_drop_panic() {
752752
q.push_front(D(false));
753753
q.push_front(D(true));
754754

755-
catch_unwind(move || drop(q)).ok();
755+
let _ = catch_unwind(move || drop(q));
756756

757757
assert_eq!(unsafe { DROPS }, 8);
758758
}
@@ -1616,7 +1616,7 @@ fn truncate_leak() {
16161616
q.push_front(D(false));
16171617
q.push_front(D(false));
16181618

1619-
catch_unwind(AssertUnwindSafe(|| q.truncate(1))).ok();
1619+
let _ = catch_unwind(AssertUnwindSafe(|| q.truncate(1)));
16201620

16211621
assert_eq!(unsafe { DROPS }, 7);
16221622
}
@@ -1649,10 +1649,9 @@ fn test_drain_leak() {
16491649
v.push_front(D(1, false));
16501650
v.push_front(D(0, false));
16511651

1652-
catch_unwind(AssertUnwindSafe(|| {
1652+
let _ = catch_unwind(AssertUnwindSafe(|| {
16531653
v.drain(1..=4);
1654-
}))
1655-
.ok();
1654+
}));
16561655

16571656
assert_eq!(unsafe { DROPS }, 4);
16581657
assert_eq!(v.len(), 3);

library/std/src/collections/hash/set/tests.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,12 @@ fn test_drain_filter_drop_panic_leak() {
445445

446446
let mut set = (0..3).map(|i| D(i)).collect::<HashSet<_>>();
447447

448-
catch_unwind(move || {
448+
let _ = catch_unwind(move || {
449449
drop(set.drain_filter(|_| {
450450
PREDS.fetch_add(1, Ordering::SeqCst);
451451
true
452452
}))
453-
})
454-
.ok();
453+
});
455454

456455
assert_eq!(PREDS.load(Ordering::SeqCst), 3);
457456
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
@@ -472,13 +471,12 @@ fn test_drain_filter_pred_panic_leak() {
472471

473472
let mut set: HashSet<_> = (0..3).map(|_| D).collect();
474473

475-
catch_unwind(AssertUnwindSafe(|| {
474+
let _ = catch_unwind(AssertUnwindSafe(|| {
476475
drop(set.drain_filter(|_| match PREDS.fetch_add(1, Ordering::SeqCst) {
477476
0 => true,
478477
_ => panic!(),
479478
}))
480-
}))
481-
.ok();
479+
}));
482480

483481
assert_eq!(PREDS.load(Ordering::SeqCst), 1);
484482
assert_eq!(DROPS.load(Ordering::SeqCst), 3);

0 commit comments

Comments
 (0)