Use #[track_caller] on Rust 1.46+

This commit is contained in:
Taiki Endo 2022-07-10 02:09:58 +09:00
parent ad47e0ca6d
commit 42c7f1ad97
2 changed files with 8 additions and 1 deletions

View File

@ -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");
}
}

View File

@ -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,