Rollup merge of #70234 - anp:tracked-std-traits, r=Amanieu
#[track_caller] on core::ops::{Index, IndexMut}.
Applies the attribute to `core::ops::Index(Mut)` and enough std internals to cover the [functions listed in "tier 1" in the original RFC](https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md#survey-of-panicking-standard-functions).
Split out from #69251 to allow separate assessment of perf impact.
To my knowledge, this is the last piece of implementing RFC 2091.
Tracking issue: https://github.com/rust-lang/rust/issues/47809
This commit is contained in:
commit
50d2f302cb
4 changed files with 32 additions and 0 deletions
|
|
@ -2,10 +2,14 @@
|
|||
// ignore-wasm32-bare compiled with panic=abort by default
|
||||
|
||||
#![feature(option_expect_none, option_unwrap_none)]
|
||||
#![allow(unconditional_panic)]
|
||||
|
||||
//! Test that panic locations for `#[track_caller]` functions in std have the correct
|
||||
//! location reported.
|
||||
|
||||
use std::collections::{BTreeMap, HashMap, VecDeque};
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
fn main() {
|
||||
// inspect the `PanicInfo` we receive to ensure the right file is the source
|
||||
std::panic::set_hook(Box::new(|info| {
|
||||
|
|
@ -35,4 +39,22 @@ fn main() {
|
|||
let fine: Result<(), ()> = Ok(());
|
||||
assert_panicked(|| fine.unwrap_err());
|
||||
assert_panicked(|| fine.expect_err(""));
|
||||
|
||||
let mut small = [0]; // the implementation backing str, vec, etc
|
||||
assert_panicked(move || { small.index(1); });
|
||||
assert_panicked(move || { small[1]; });
|
||||
assert_panicked(move || { small.index_mut(1); });
|
||||
assert_panicked(move || { small[1] += 1; });
|
||||
|
||||
let sorted: BTreeMap<bool, bool> = Default::default();
|
||||
assert_panicked(|| { sorted.index(&false); });
|
||||
assert_panicked(|| { sorted[&false]; });
|
||||
|
||||
let unsorted: HashMap<bool, bool> = Default::default();
|
||||
assert_panicked(|| { unsorted.index(&false); });
|
||||
assert_panicked(|| { unsorted[&false]; });
|
||||
|
||||
let weirdo: VecDeque<()> = Default::default();
|
||||
assert_panicked(|| { weirdo.index(1); });
|
||||
assert_panicked(|| { weirdo[1]; });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue