mirror of
https://gitee.com/openharmony/third_party_rust_slab
synced 2024-11-26 23:20:39 +00:00
Use #[track_caller] on Rust 1.46+
This commit is contained in:
parent
ad47e0ca6d
commit
42c7f1ad97
5
build.rs
5
build.rs
@ -4,7 +4,7 @@ fn main() {
|
||||
Err(e) => {
|
||||
// If we couldn't detect the compiler version and features, just
|
||||
// print a warning. This isn't a fatal error: we can still build
|
||||
// Tokio, we just can't enable cfgs automatically.
|
||||
// Slab, we just can't enable cfgs automatically.
|
||||
println!(
|
||||
"cargo:warning=slab: failed to detect compiler features: {}",
|
||||
e
|
||||
@ -18,4 +18,7 @@ fn main() {
|
||||
if !cfg.probe_rustc_version(1, 39) {
|
||||
println!("cargo:rustc-cfg=slab_no_const_vec_new");
|
||||
}
|
||||
if !cfg.probe_rustc_version(1, 46) {
|
||||
println!("cargo:rustc-cfg=slab_no_track_caller");
|
||||
}
|
||||
}
|
||||
|
@ -898,6 +898,7 @@ impl<T> Slab<T> {
|
||||
/// slab.key_of(bad); // this will panic
|
||||
/// unreachable!();
|
||||
/// ```
|
||||
#[cfg_attr(not(slab_no_track_caller), track_caller)]
|
||||
pub fn key_of(&self, present_element: &T) -> usize {
|
||||
let element_ptr = present_element as *const T as usize;
|
||||
let base_ptr = self.entries.as_ptr() as usize;
|
||||
@ -1066,6 +1067,7 @@ impl<T> Slab<T> {
|
||||
/// assert_eq!(slab.remove(hello), "hello");
|
||||
/// assert!(!slab.contains(hello));
|
||||
/// ```
|
||||
#[cfg_attr(not(slab_no_track_caller), track_caller)]
|
||||
pub fn remove(&mut self, key: usize) -> T {
|
||||
self.try_remove(key).expect("invalid key")
|
||||
}
|
||||
@ -1173,6 +1175,7 @@ impl<T> Slab<T> {
|
||||
impl<T> ops::Index<usize> for Slab<T> {
|
||||
type Output = T;
|
||||
|
||||
#[cfg_attr(not(slab_no_track_caller), track_caller)]
|
||||
fn index(&self, key: usize) -> &T {
|
||||
match self.entries.get(key) {
|
||||
Some(&Entry::Occupied(ref v)) => v,
|
||||
@ -1182,6 +1185,7 @@ impl<T> ops::Index<usize> for Slab<T> {
|
||||
}
|
||||
|
||||
impl<T> ops::IndexMut<usize> for Slab<T> {
|
||||
#[cfg_attr(not(slab_no_track_caller), track_caller)]
|
||||
fn index_mut(&mut self, key: usize) -> &mut T {
|
||||
match self.entries.get_mut(key) {
|
||||
Some(&mut Entry::Occupied(ref mut v)) => v,
|
||||
|
Loading…
Reference in New Issue
Block a user