Skip to content

Commit f4796ea

Browse files
authored
Rename core::assert to avoid possible conflicts in user crate (rust-lang#2005)
1 parent 438e582 commit f4796ea

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

library/std/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
// re-export all std symbols
1313
pub use std::*;
1414

15+
// Bind `core::assert` to a different name to avoid possible name conflicts if a
16+
// crate uses `extern crate std as core`. See
17+
// https://github.com/model-checking/kani/issues/1949
18+
#[allow(unused_imports)]
19+
use core::assert as __kani__workaround_core_assert;
20+
1521
// Override process calls with stubs.
1622
pub mod process;
1723

@@ -54,7 +60,7 @@ macro_rules! assert {
5460
// strategy, which is tracked in
5561
// https://github.com/model-checking/kani/issues/692
5662
if false {
57-
::core::assert!(true, $($arg)+);
63+
__kani__workaround_core_assert!(true, $($arg)+);
5864
}
5965
}};
6066
}
@@ -158,7 +164,7 @@ macro_rules! unreachable {
158164
// handle.
159165
($fmt:expr, $($arg:tt)*) => {{
160166
if false {
161-
::core::assert!(true, $fmt, $($arg)+);
167+
__kani__workaround_core_assert!(true, $fmt, $($arg)+);
162168
}
163169
kani::panic(concat!("internal error: entered unreachable code: ",
164170
stringify!($fmt, $($arg)*)))}};
@@ -190,7 +196,7 @@ macro_rules! panic {
190196
// `panic!("Error: {}", code);`
191197
($($arg:tt)+) => {{
192198
if false {
193-
::core::assert!(true, $($arg)+);
199+
__kani__workaround_core_assert!(true, $($arg)+);
194200
}
195201
kani::panic(stringify!($($arg)+));
196202
}};

tests/kani/Panic/extern_core.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! This test checks that the panic macro does not cause a "recursion limit
5+
//! reached" compiler error if the user crate contains an `extern crate std as
6+
//! core` line (see https://github.com/model-checking/kani/issues/1949)
7+
8+
extern crate std as core;
9+
10+
#[kani::proof]
11+
fn main() {
12+
let x = if kani::any() { 11 } else { 33 };
13+
if x < 10 {
14+
panic!("x is {}", x);
15+
}
16+
}

0 commit comments

Comments
 (0)