Skip to content

Commit eab4238

Browse files
authored
Merge branch 'main' into llm_contracts_iterator_get_unchecked
2 parents 616a43c + e4dcb19 commit eab4238

9 files changed

Lines changed: 169 additions & 5 deletions

File tree

library/core/src/panic/location.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use crate::cmp::Ordering;
12
use crate::ffi::CStr;
23
use crate::fmt;
4+
use crate::hash::{Hash, Hasher};
35
use crate::marker::PhantomData;
46
use crate::ptr::NonNull;
57

@@ -32,7 +34,7 @@ use crate::ptr::NonNull;
3234
/// Files are compared as strings, not `Path`, which could be unexpected.
3335
/// See [`Location::file`]'s documentation for more discussion.
3436
#[lang = "panic_location"]
35-
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
37+
#[derive(Copy, Clone)]
3638
#[stable(feature = "panic_hooks", since = "1.10.0")]
3739
pub struct Location<'a> {
3840
// A raw pointer is used rather than a reference because the pointer is valid for one more byte
@@ -44,6 +46,44 @@ pub struct Location<'a> {
4446
_filename: PhantomData<&'a str>,
4547
}
4648

49+
#[stable(feature = "panic_hooks", since = "1.10.0")]
50+
impl PartialEq for Location<'_> {
51+
fn eq(&self, other: &Self) -> bool {
52+
// Compare col / line first as they're cheaper to compare and more likely to differ,
53+
// while not impacting the result.
54+
self.col == other.col && self.line == other.line && self.file() == other.file()
55+
}
56+
}
57+
58+
#[stable(feature = "panic_hooks", since = "1.10.0")]
59+
impl Eq for Location<'_> {}
60+
61+
#[stable(feature = "panic_hooks", since = "1.10.0")]
62+
impl Ord for Location<'_> {
63+
fn cmp(&self, other: &Self) -> Ordering {
64+
self.file()
65+
.cmp(other.file())
66+
.then_with(|| self.line.cmp(&other.line))
67+
.then_with(|| self.col.cmp(&other.col))
68+
}
69+
}
70+
71+
#[stable(feature = "panic_hooks", since = "1.10.0")]
72+
impl PartialOrd for Location<'_> {
73+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
74+
Some(self.cmp(other))
75+
}
76+
}
77+
78+
#[stable(feature = "panic_hooks", since = "1.10.0")]
79+
impl Hash for Location<'_> {
80+
fn hash<H: Hasher>(&self, state: &mut H) {
81+
self.file().hash(state);
82+
self.line.hash(state);
83+
self.col.hash(state);
84+
}
85+
}
86+
4787
#[stable(feature = "panic_hooks", since = "1.10.0")]
4888
impl fmt::Debug for Location<'_> {
4989
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/coretests/tests/panic/location.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ use core::panic::Location;
33
// Note: Some of the following tests depend on the source location,
44
// so please be careful when editing this file.
55

6+
mod file_a;
7+
mod file_b;
8+
mod file_c;
9+
10+
// A small shuffled set of locations for testing, along with their true order.
11+
const LOCATIONS: [(usize, &'static Location<'_>); 9] = [
12+
(7, file_c::two()),
13+
(0, file_a::one()),
14+
(3, file_b::one()),
15+
(5, file_b::three()),
16+
(8, file_c::three()),
17+
(6, file_c::one()),
18+
(2, file_a::three()),
19+
(4, file_b::two()),
20+
(1, file_a::two()),
21+
];
22+
623
#[test]
724
fn location_const_caller() {
825
const _CALLER_REFERENCE: &Location<'static> = Location::caller();
@@ -20,7 +37,7 @@ fn location_const_file() {
2037
fn location_const_line() {
2138
const CALLER: &Location<'static> = Location::caller();
2239
const LINE: u32 = CALLER.line();
23-
assert_eq!(LINE, 21);
40+
assert_eq!(LINE, 38);
2441
}
2542

2643
#[test]
@@ -34,6 +51,28 @@ fn location_const_column() {
3451
fn location_debug() {
3552
let f = format!("{:?}", Location::caller());
3653
assert!(f.contains(&format!("{:?}", file!())));
37-
assert!(f.contains("35"));
54+
assert!(f.contains("52"));
3855
assert!(f.contains("29"));
3956
}
57+
58+
#[test]
59+
fn location_eq() {
60+
for (i, a) in LOCATIONS {
61+
for (j, b) in LOCATIONS {
62+
if i == j {
63+
assert_eq!(a, b);
64+
} else {
65+
assert_ne!(a, b);
66+
}
67+
}
68+
}
69+
}
70+
71+
#[test]
72+
fn location_ord() {
73+
let mut locations = LOCATIONS.clone();
74+
locations.sort_by_key(|(_o, l)| **l);
75+
for (correct, (order, _l)) in locations.iter().enumerate() {
76+
assert_eq!(correct, *order);
77+
}
78+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use core::panic::Location;
2+
3+
// Used for test super::location_{ord, eq}. Must be in a dedicated file.
4+
5+
pub const fn one() -> &'static Location<'static> {
6+
Location::caller()
7+
}
8+
9+
pub const fn two() -> &'static Location<'static> {
10+
Location::caller()
11+
}
12+
13+
pub const fn three() -> &'static Location<'static> {
14+
Location::caller()
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use core::panic::Location;
2+
3+
// Used for test super::location_{ord, eq}. Must be in a dedicated file.
4+
5+
pub const fn one() -> &'static Location<'static> {
6+
Location::caller()
7+
}
8+
9+
pub const fn two() -> &'static Location<'static> {
10+
Location::caller()
11+
}
12+
13+
pub const fn three() -> &'static Location<'static> {
14+
Location::caller()
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Used for test super::location_{ord, eq}. Must be in a dedicated file.
2+
3+
// This is used for testing column ordering of Location, hence this ugly one-liner.
4+
// We must fmt skip the entire containing module or else tidy will still complain.
5+
#[rustfmt::skip]
6+
mod no_fmt {
7+
use core::panic::Location;
8+
pub const fn one() -> &'static Location<'static> { Location::caller() } pub const fn two() -> &'static Location<'static> { Location::caller() } pub const fn three() -> &'static Location<'static> { Location::caller() }
9+
}
10+
11+
pub use no_fmt::*;

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# standard library we currently track.
33

44
[toolchain]
5-
channel = "nightly-2025-07-30"
5+
channel = "nightly-2025-07-31"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

scripts/kani-std-analysis/metrics-data-core.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,28 @@
534534
"verified_safe_fns_under_contract": 111,
535535
"verified_safe_fns_with_loop_under_contract": 0,
536536
"total_functions_under_contract_all_crates": 381
537+
},
538+
{
539+
"date": "2025-08-03",
540+
"total_unsafe_fns": 7194,
541+
"total_unsafe_fns_with_loop": 22,
542+
"total_safe_abstractions": 1861,
543+
"total_safe_abstractions_with_loop": 65,
544+
"total_safe_fns": 15898,
545+
"total_safe_fns_with_loop": 727,
546+
"unsafe_fns_under_contract": 253,
547+
"unsafe_fns_with_loop_under_contract": 2,
548+
"verified_unsafe_fns_under_contract": 244,
549+
"verified_unsafe_fns_with_loop_under_contract": 1,
550+
"safe_abstractions_under_contract": 77,
551+
"safe_abstractions_with_loop_under_contract": 0,
552+
"verified_safe_abstractions_under_contract": 77,
553+
"verified_safe_abstractions_with_loop_under_contract": 0,
554+
"safe_fns_under_contract": 113,
555+
"safe_fns_with_loop_under_contract": 0,
556+
"verified_safe_fns_under_contract": 111,
557+
"verified_safe_fns_with_loop_under_contract": 0,
558+
"total_functions_under_contract_all_crates": 381
537559
}
538560
]
539561
}

scripts/kani-std-analysis/metrics-data-std.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,28 @@
417417
"verified_safe_fns_under_contract": 0,
418418
"verified_safe_fns_with_loop_under_contract": 0,
419419
"total_functions_under_contract_all_crates": 381
420+
},
421+
{
422+
"date": "2025-08-03",
423+
"total_unsafe_fns": 183,
424+
"total_unsafe_fns_with_loop": 12,
425+
"total_safe_abstractions": 504,
426+
"total_safe_abstractions_with_loop": 47,
427+
"total_safe_fns": 4169,
428+
"total_safe_fns_with_loop": 190,
429+
"unsafe_fns_under_contract": 9,
430+
"unsafe_fns_with_loop_under_contract": 0,
431+
"verified_unsafe_fns_under_contract": 2,
432+
"verified_unsafe_fns_with_loop_under_contract": 0,
433+
"safe_abstractions_under_contract": 0,
434+
"safe_abstractions_with_loop_under_contract": 0,
435+
"verified_safe_abstractions_under_contract": 0,
436+
"verified_safe_abstractions_with_loop_under_contract": 0,
437+
"safe_fns_under_contract": 0,
438+
"safe_fns_with_loop_under_contract": 0,
439+
"verified_safe_fns_under_contract": 0,
440+
"verified_safe_fns_with_loop_under_contract": 0,
441+
"total_functions_under_contract_all_crates": 381
420442
}
421443
]
422444
}

tool_config/kani-version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# incompatible with the verify-std repo.
33

44
[kani]
5-
commit = "1954c10d033221e8085d597464bc413865152e27"
5+
commit = "f76e668b5f86daad11e51d78ab10998426da943b"

0 commit comments

Comments
 (0)