Skip to content

Commit 42c7f1a

Browse files
committed
Use #[track_caller] on Rust 1.46+
1 parent ad47e0c commit 42c7f1a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44
Err(e) => {
55
// If we couldn't detect the compiler version and features, just
66
// print a warning. This isn't a fatal error: we can still build
7-
// Tokio, we just can't enable cfgs automatically.
7+
// Slab, we just can't enable cfgs automatically.
88
println!(
99
"cargo:warning=slab: failed to detect compiler features: {}",
1010
e
@@ -18,4 +18,7 @@ fn main() {
1818
if !cfg.probe_rustc_version(1, 39) {
1919
println!("cargo:rustc-cfg=slab_no_const_vec_new");
2020
}
21+
if !cfg.probe_rustc_version(1, 46) {
22+
println!("cargo:rustc-cfg=slab_no_track_caller");
23+
}
2124
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ impl<T> Slab<T> {
898898
/// slab.key_of(bad); // this will panic
899899
/// unreachable!();
900900
/// ```
901+
#[cfg_attr(not(slab_no_track_caller), track_caller)]
901902
pub fn key_of(&self, present_element: &T) -> usize {
902903
let element_ptr = present_element as *const T as usize;
903904
let base_ptr = self.entries.as_ptr() as usize;
@@ -1066,6 +1067,7 @@ impl<T> Slab<T> {
10661067
/// assert_eq!(slab.remove(hello), "hello");
10671068
/// assert!(!slab.contains(hello));
10681069
/// ```
1070+
#[cfg_attr(not(slab_no_track_caller), track_caller)]
10691071
pub fn remove(&mut self, key: usize) -> T {
10701072
self.try_remove(key).expect("invalid key")
10711073
}
@@ -1173,6 +1175,7 @@ impl<T> Slab<T> {
11731175
impl<T> ops::Index<usize> for Slab<T> {
11741176
type Output = T;
11751177

1178+
#[cfg_attr(not(slab_no_track_caller), track_caller)]
11761179
fn index(&self, key: usize) -> &T {
11771180
match self.entries.get(key) {
11781181
Some(&Entry::Occupied(ref v)) => v,
@@ -1182,6 +1185,7 @@ impl<T> ops::Index<usize> for Slab<T> {
11821185
}
11831186

11841187
impl<T> ops::IndexMut<usize> for Slab<T> {
1188+
#[cfg_attr(not(slab_no_track_caller), track_caller)]
11851189
fn index_mut(&mut self, key: usize) -> &mut T {
11861190
match self.entries.get_mut(key) {
11871191
Some(&mut Entry::Occupied(ref mut v)) => v,

0 commit comments

Comments
 (0)