/rust/registry/src/index.crates.io-6f17d22bba15001f/thread_local-1.1.8/src/unreachable.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2017 Amanieu d'Antras |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or |
4 | | // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
5 | | // http://opensource.org/licenses/MIT>, at your option. This file may not be |
6 | | // copied, modified, or distributed except according to those terms. |
7 | | |
8 | | use std::hint::unreachable_unchecked; |
9 | | |
10 | | /// An extension trait for `Option<T>` providing unchecked unwrapping methods. |
11 | | pub trait UncheckedOptionExt<T> { |
12 | | /// Get the value out of this Option without checking for None. |
13 | | unsafe fn unchecked_unwrap(self) -> T; |
14 | | |
15 | | /// Assert that this Option is a None to the optimizer. |
16 | | unsafe fn unchecked_unwrap_none(self); |
17 | | } |
18 | | |
19 | | /// An extension trait for `Result<T, E>` providing unchecked unwrapping methods. |
20 | | pub trait UncheckedResultExt<T, E> { |
21 | | /// Get the value out of this Result without checking for Err. |
22 | | unsafe fn unchecked_unwrap_ok(self) -> T; |
23 | | |
24 | | /// Get the error out of this Result without checking for Ok. |
25 | | unsafe fn unchecked_unwrap_err(self) -> E; |
26 | | } |
27 | | |
28 | | impl<T> UncheckedOptionExt<T> for Option<T> { |
29 | 0 | unsafe fn unchecked_unwrap(self) -> T { |
30 | 0 | match self { |
31 | 0 | Some(x) => x, |
32 | 0 | None => unreachable_unchecked(), |
33 | | } |
34 | 0 | } |
35 | | |
36 | 0 | unsafe fn unchecked_unwrap_none(self) { |
37 | 0 | if self.is_some() { |
38 | 0 | unreachable_unchecked() |
39 | 0 | } |
40 | 0 | } |
41 | | } |
42 | | |
43 | | impl<T, E> UncheckedResultExt<T, E> for Result<T, E> { |
44 | 0 | unsafe fn unchecked_unwrap_ok(self) -> T { |
45 | 0 | match self { |
46 | 0 | Ok(x) => x, |
47 | 0 | Err(_) => unreachable_unchecked(), |
48 | | } |
49 | 0 | } Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<_, _> as thread_local::unreachable::UncheckedResultExt<_, _>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<alloc::vec::Vec<tracing_core::metadata::LevelFilter>>, ()>>::unchecked_unwrap_ok Unexecuted instantiation: <core::result::Result<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()> as thread_local::unreachable::UncheckedResultExt<&core::cell::RefCell<tracing_subscriber::registry::stack::SpanStack>, ()>>::unchecked_unwrap_ok |
50 | | |
51 | 0 | unsafe fn unchecked_unwrap_err(self) -> E { |
52 | 0 | match self { |
53 | 0 | Ok(_) => unreachable_unchecked(), |
54 | 0 | Err(e) => e, |
55 | 0 | } |
56 | 0 | } |
57 | | } |