Skip to content

Add #[must_use] annotation to Result::ok #139138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_data_structures/src/jobserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn default_client() -> Client {
let client = Client::new(32).expect("failed to create jobserver");

// Acquire a token for the main thread which we can release later
client.acquire_raw().ok();
let _ = client.acquire_raw().ok();

client
}
Expand All @@ -62,7 +62,7 @@ pub fn initialize_checked(report_warning: impl FnOnce(&'static str)) {
default_client()
}
};
GLOBAL_CLIENT_CHECKED.set(client_checked).ok();
let _ = GLOBAL_CLIENT_CHECKED.set(client_checked);
}

const ACCESS_ERROR: &str = "jobserver check should have been called earlier";
Expand All @@ -72,9 +72,9 @@ pub fn client() -> Client {
}

pub fn acquire_thread() {
GLOBAL_CLIENT_CHECKED.get().expect(ACCESS_ERROR).acquire_raw().ok();
let _ = GLOBAL_CLIENT_CHECKED.get().expect(ACCESS_ERROR).acquire_raw();
}

pub fn release_thread() {
GLOBAL_CLIENT_CHECKED.get().expect(ACCESS_ERROR).release_raw().ok();
let _ = GLOBAL_CLIENT_CHECKED.get().expect(ACCESS_ERROR).release_raw();
}
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sync/worker_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Registry {
drop(threads);
panic!("Thread already has a registry");
}
registry.set(self.clone()).ok();
let _ = registry.set(self.clone());
THREAD_DATA.with(|data| {
data.registry_id.set(self.id());
data.index.set(*threads);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/query/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where

#[inline]
fn complete(&self, _key: (), value: V, index: DepNodeIndex) {
self.cache.set((value, index)).ok();
let _ = self.cache.set((value, index));
}

fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
Expand Down
1 change: 1 addition & 0 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ impl<T, E> Result<T, E> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "result_ok_method"]
#[must_use]
pub fn ok(self) -> Option<T> {
match self {
Ok(x) => Some(x),
Expand Down
10 changes: 4 additions & 6 deletions library/std/src/collections/hash/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,13 @@ fn test_extract_if_drop_panic_leak() {

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

catch_unwind(move || {
let _ = catch_unwind(move || {
set.extract_if(|_| {
PREDS.fetch_add(1, Ordering::SeqCst);
true
})
.for_each(drop)
})
.ok();
});

assert_eq!(PREDS.load(Ordering::SeqCst), 2);
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
Expand All @@ -475,14 +474,13 @@ fn test_extract_if_pred_panic_leak() {

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

catch_unwind(AssertUnwindSafe(|| {
let _ = catch_unwind(AssertUnwindSafe(|| {
set.extract_if(|_| match PREDS.fetch_add(1, Ordering::SeqCst) {
0 => true,
_ => panic!(),
})
.for_each(drop)
}))
.ok();
}));

assert_eq!(PREDS.load(Ordering::SeqCst), 1);
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn default_hook(info: &PanicHookInfo<'_>) {

if let Ok(Some(local)) = try_set_output_capture(None) {
write(&mut *local.lock().unwrap_or_else(|e| e.into_inner()));
try_set_output_capture(Some(local)).ok();
let _ = try_set_output_capture(Some(local));
} else if let Some(mut out) = panic_output() {
write(&mut out);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// If old_fd and new_fd point to the same description, then `dup_fd` ensures we keep the underlying file description alive.
if let Some(old_new_fd) = this.machine.fds.fds.insert(new_fd_num, fd) {
// Ignore close error (not interpreter's) according to dup2() doc.
old_new_fd.close_ref(this.machine.communicate(), this)?.ok();
let _ = old_new_fd.close_ref(this.machine.communicate(), this)?;
}
}
interp_ok(Scalar::from_i32(new_fd_num))
Expand Down
Loading