mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #7266
7266: Make printin the backtrace more convenient r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
022d031b7f
5 changed files with 29 additions and 26 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1197,7 +1197,6 @@ name = "profile"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arena",
|
"arena",
|
||||||
"backtrace",
|
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
@ -1566,6 +1565,9 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stdx"
|
name = "stdx"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"backtrace",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
|
|
|
@ -13,7 +13,6 @@ doctest = false
|
||||||
once_cell = "1.3.1"
|
once_cell = "1.3.1"
|
||||||
cfg-if = "1"
|
cfg-if = "1"
|
||||||
libc = "0.2.73"
|
libc = "0.2.73"
|
||||||
backtrace = { version = "0.3.44", optional = true }
|
|
||||||
|
|
||||||
arena = { path = "../arena", version = "0.0.0" }
|
arena = { path = "../arena", version = "0.0.0" }
|
||||||
|
|
||||||
|
@ -24,5 +23,4 @@ perf-event = "0.4"
|
||||||
cpu_profiler = []
|
cpu_profiler = []
|
||||||
|
|
||||||
# Uncomment to enable for the whole crate graph
|
# Uncomment to enable for the whole crate graph
|
||||||
# default = [ "backtrace" ]
|
|
||||||
# default = [ "cpu_profiler" ]
|
# default = [ "cpu_profiler" ]
|
||||||
|
|
|
@ -15,21 +15,6 @@ pub use crate::{
|
||||||
stop_watch::{StopWatch, StopWatchSpan},
|
stop_watch::{StopWatch, StopWatchSpan},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Prints backtrace to stderr, useful for debugging.
|
|
||||||
#[cfg(feature = "backtrace")]
|
|
||||||
pub fn print_backtrace() {
|
|
||||||
let bt = backtrace::Backtrace::new();
|
|
||||||
eprintln!("{:?}", bt);
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "backtrace"))]
|
|
||||||
pub fn print_backtrace() {
|
|
||||||
eprintln!(
|
|
||||||
r#"enable the backtrace feature:
|
|
||||||
profile = {{ path = "../profile", features = [ "backtrace"] }}
|
|
||||||
"#
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false));
|
thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false));
|
||||||
|
|
||||||
/// Allows to check if the current code is withing some dynamic scope, can be
|
/// Allows to check if the current code is withing some dynamic scope, can be
|
||||||
|
|
|
@ -10,4 +10,9 @@ edition = "2018"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
backtrace = { version = "0.3.44", optional = true }
|
||||||
# Think twice before adding anything here
|
# Think twice before adding anything here
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# Uncomment to enable for the whole crate graph
|
||||||
|
# default = [ "backtrace" ]
|
||||||
|
|
|
@ -25,6 +25,27 @@ pub fn timeit(label: &'static str) -> impl Drop {
|
||||||
Guard { label, start: Instant::now() }
|
Guard { label, start: Instant::now() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prints backtrace to stderr, useful for debugging.
|
||||||
|
#[cfg(feature = "backtrace")]
|
||||||
|
pub fn print_backtrace() {
|
||||||
|
let bt = backtrace::Backtrace::new();
|
||||||
|
eprintln!("{:?}", bt);
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "backtrace"))]
|
||||||
|
pub fn print_backtrace() {
|
||||||
|
eprintln!(
|
||||||
|
r#"Enable the backtrace feature.
|
||||||
|
Uncomment `default = [ "backtrace" ]` in `crates/stdx/Cargo.toml`.
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_lower_snake_case(s: &str) -> String {
|
||||||
|
to_snake_case(s, char::to_ascii_lowercase)
|
||||||
|
}
|
||||||
|
pub fn to_upper_snake_case(s: &str) -> String {
|
||||||
|
to_snake_case(s, char::to_ascii_uppercase)
|
||||||
|
}
|
||||||
fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String {
|
fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String {
|
||||||
let mut buf = String::with_capacity(s.len());
|
let mut buf = String::with_capacity(s.len());
|
||||||
let mut prev = false;
|
let mut prev = false;
|
||||||
|
@ -43,14 +64,6 @@ fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String {
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_lower_snake_case(s: &str) -> String {
|
|
||||||
to_snake_case(s, char::to_ascii_lowercase)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_upper_snake_case(s: &str) -> String {
|
|
||||||
to_snake_case(s, char::to_ascii_uppercase)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn replace(buf: &mut String, from: char, to: &str) {
|
pub fn replace(buf: &mut String, from: char, to: &str) {
|
||||||
if !buf.contains(from) {
|
if !buf.contains(from) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue