2016-01-21 17:19:23 -06:00
|
|
|
[package]
|
|
|
|
name = "core"
|
|
|
|
version = "0.0.0"
|
2021-02-20 12:18:01 -06:00
|
|
|
license = "MIT OR Apache-2.0"
|
|
|
|
repository = "https://github.com/rust-lang/rust.git"
|
|
|
|
description = "The Rust Core Library"
|
2018-05-10 13:02:19 -05:00
|
|
|
autotests = false
|
|
|
|
autobenches = false
|
2022-02-02 00:48:04 -06:00
|
|
|
# If you update this, be sure to update it in a bunch of other places too!
|
2024-03-25 13:02:02 -05:00
|
|
|
# As of 2024, it was src/tools/opt-dist, the core-no-fp-fmt-parse test and
|
|
|
|
# the version of the prelude imported in core/lib.rs.
|
2021-12-17 07:53:28 -06:00
|
|
|
edition = "2021"
|
2016-01-21 17:19:23 -06:00
|
|
|
|
|
|
|
[lib]
|
|
|
|
test = false
|
2016-11-25 15:13:59 -06:00
|
|
|
bench = false
|
2016-04-29 16:23:15 -05:00
|
|
|
|
|
|
|
[[test]]
|
2017-04-03 09:53:04 -05:00
|
|
|
name = "coretests"
|
2020-06-11 21:31:49 -05:00
|
|
|
path = "tests/lib.rs"
|
2016-11-25 15:13:59 -06:00
|
|
|
|
2017-02-03 17:04:22 -06:00
|
|
|
[[bench]]
|
2017-02-06 04:38:47 -06:00
|
|
|
name = "corebenches"
|
2020-06-11 21:31:49 -05:00
|
|
|
path = "benches/lib.rs"
|
2020-06-08 11:09:21 -05:00
|
|
|
test = true
|
2018-02-26 11:07:16 -06:00
|
|
|
|
|
|
|
[dev-dependencies]
|
2022-11-20 18:55:41 -06:00
|
|
|
rand = { version = "0.8.5", default-features = false }
|
|
|
|
rand_xorshift = { version = "0.3.0", default-features = false }
|
2018-11-29 15:06:10 -06:00
|
|
|
|
|
|
|
[features]
|
|
|
|
# Make panics and failed asserts immediately abort without formatting any message
|
|
|
|
panic_immediate_abort = []
|
2024-05-11 07:07:19 -05:00
|
|
|
# Choose algorithms that are optimized for binary size instead of runtime performance
|
|
|
|
optimize_for_size = []
|
Add `debug-refcell` feature to libcore
See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Attaching.20backtraces.20to.20RefCell/near/226273614
for some background discussion
This PR adds a new off-by-default feature `debug-refcell` to libcore.
When enabled, this feature stores additional debugging information in
`RefCell`. This information is included in the panic message when
`borrow()` or `borrow_mut()` panics, to make it easier to track down the
source of the issue.
Currently, we store the caller location for the earliest active borrow.
This has a number of advantages:
* There is only a constant amount of overhead per `RefCell`
* We don't need any heap memory, so it can easily be implemented in core
* Since we are storing the *earliest* active borrow, we don't need any
extra logic in the `Drop` implementation for `Ref` and `RefMut`
Limitations:
* We only store the caller location, not a full `Backtrace`. Until
we get support for `Backtrace` in libcore, this is the best tha we can
do.
* The captured location is only displayed when `borrow()` or
`borrow_mut()` panics. If a crate calls `try_borrow().unwrap()`
or `try_borrow_mut().unwrap()`, this extra information will be lost.
To make testing easier, I've enabled the `debug-refcell` feature by
default. I'm not sure how to write a test for this feature - we would
need to rebuild core from the test framework, and create a separate
sysroot.
Since this feature will be off-by-default, users will need to use
`xargo` or `cargo -Z build-std` to enable this feature. For users using
a prebuilt standard library, this feature will be disabled with zero
overhead.
I've created a simple test program:
```rust
use std::cell::RefCell;
fn main() {
let _ = std::panic::catch_unwind(|| {
let val = RefCell::new(true);
let _first = val.borrow();
let _second = val.borrow();
let _third = val.borrow_mut();
});
let _ = std::panic::catch_unwind(|| {
let val = RefCell::new(true);
let first = val.borrow_mut();
drop(first);
let _second = val.borrow_mut();
let _thid = val.borrow();
});
}
```
which produces the following output:
```
thread 'main' panicked at 'already borrowed: BorrowMutError { location: Location { file: "refcell_test.rs", line: 6, col: 26 } }', refcell_test.rs:8:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'already mutably borrowed: BorrowError { location: Location { file: "refcell_test.rs", line: 16, col: 27 } }', refcell_test.rs:18:25
```
2021-02-17 20:30:39 -06:00
|
|
|
# Make `RefCell` store additional debugging information, which is printed out when
|
|
|
|
# a borrow error occurs
|
|
|
|
debug_refcell = []
|
2024-05-19 18:08:59 -05:00
|
|
|
|
|
|
|
[lints.rust.unexpected_cfgs]
|
|
|
|
level = "warn"
|
|
|
|
check-cfg = [
|
|
|
|
'cfg(bootstrap)',
|
2024-05-20 10:08:28 -05:00
|
|
|
'cfg(no_fp_fmt_parse)',
|
2024-05-19 18:08:59 -05:00
|
|
|
'cfg(stdarch_intel_sde)',
|
2023-08-21 12:03:17 -05:00
|
|
|
# #[cfg(bootstrap)] rtems
|
|
|
|
'cfg(target_os, values("rtems"))',
|
2024-05-23 08:20:25 -05:00
|
|
|
# core use #[path] imports to portable-simd `core_simd` crate
|
|
|
|
# and to stdarch `core_arch` crate which messes-up with Cargo list
|
|
|
|
# of declared features, we therefor expect any feature cfg
|
2024-05-20 10:06:14 -05:00
|
|
|
'cfg(feature, values(any()))',
|
2024-05-19 18:08:59 -05:00
|
|
|
]
|