Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0797712
Stabilize Option::deref and Option::deref_mut
SimonSapin Sep 23, 2019
f1835bc
Stabilize UdpSocket::peer_addr
messense Sep 24, 2019
1d06058
std: Reduce checks for `feature = "backtrace"`
alexcrichton Sep 25, 2019
1de6f74
Update src/libstd/net/udp.rs
Sep 26, 2019
e8796ca
Do not ICE when dereferencing non-Copy raw pointer
estebank Oct 2, 2019
1222cc9
permit asyncawait-ondeck to be added by anyone
nikomatsakis Oct 3, 2019
1fcbd90
Update triagebot.toml
nikomatsakis Oct 3, 2019
ed60cf2
When encountering chained operators use heuristics to recover from ba…
estebank Sep 30, 2019
6c9f298
review comments
estebank Sep 30, 2019
d7dceaa
Account for missing turbofish in paths too
estebank Sep 30, 2019
d27683a
Prove bad turbofish parser recovery in test
estebank Sep 30, 2019
dfdc369
review comments
estebank Oct 1, 2019
f1499a8
review comments
estebank Oct 1, 2019
02f57f8
review comments
estebank Oct 3, 2019
76456e7
review comments
estebank Oct 4, 2019
2d87bac
replace GeneratorSubsts with SubstsRef
csmoe Oct 3, 2019
fa7a87b
generate GeneratorSubsts from SubstsRef
csmoe Oct 3, 2019
774ea80
replace GeneratorSubsts inside related types
csmoe Oct 3, 2019
ef9fe10
remove GeneratorSubsts visitors
csmoe Oct 3, 2019
afc0bb9
clean up GeneratorSubsts
csmoe Oct 3, 2019
e9009c8
[const-prop] Fix ICE when trying to eval polymorphic promoted MIR
wesleywiser Oct 3, 2019
91a096a
move middle::liveness to rustc_passes
Mark-Simulacrum Oct 4, 2019
bb70782
middle::dead -> rustc_passes
Mark-Simulacrum Oct 4, 2019
82bfd8e
middle::entry -> rustc_passes
Mark-Simulacrum Oct 4, 2019
7c3f65b
middle::intrinsicck -> rustc_passes
Mark-Simulacrum Oct 4, 2019
d0a6805
Allow unused attributes to avoid incremental bug
Mark-Simulacrum Oct 4, 2019
d152d48
Fix lonely backtick
Qwaz Oct 4, 2019
c5f80aa
Remove unneeded visit_statement definition
spastorino Oct 4, 2019
8bb5c12
Update the documented default of -Z mutable-noalias
cuviper Oct 4, 2019
5f94a53
Account for macro invocation in `let mut $pat` diagnostic.
Centril Oct 5, 2019
173958a
Replaces some instances of `as *[const | mut] _` with `.cast()`
memoryruins Oct 5, 2019
318ff30
Fix typo on `now()` comments
Oct 5, 2019
080aa86
lint: extern non-exhaustive types are improper
davidtwco Oct 5, 2019
d16b7f7
Revert "Auto merge of #63649 - tlively:emscripten-upstream-upgrade, r…
tmandry Oct 6, 2019
0085263
Rollup merge of #64708 - SimonSapin:option-deref, r=Centril
tmandry Oct 6, 2019
019b5b5
Rollup merge of #64728 - messense:udp-peer-addr, r=dtolnay
tmandry Oct 6, 2019
ae2a720
Rollup merge of #64765 - alexcrichton:less-check-backtrace, r=sfackler
tmandry Oct 6, 2019
c7d7e37
Rollup merge of #64909 - estebank:turbofish-reloaded, r=Centril
tmandry Oct 6, 2019
2b225ba
Rollup merge of #65011 - estebank:ice-o-matic, r=zackmdavis
tmandry Oct 6, 2019
df471c1
Rollup merge of #65064 - rust-lang:permit-asyncawait-ondeck-by-anyone…
tmandry Oct 6, 2019
f14d374
Rollup merge of #65066 - wesleywiser:fix_const_prop_ice_on_polymorphi…
tmandry Oct 6, 2019
7739f17
Rollup merge of #65100 - csmoe:generator, r=nikomatsakis
tmandry Oct 6, 2019
2c8cbcc
Rollup merge of #65105 - Mark-Simulacrum:split-librustc, r=nikomatsakis
tmandry Oct 6, 2019
f80656c
Rollup merge of #65106 - Mark-Simulacrum:unused-attr-allow, r=Centril
tmandry Oct 6, 2019
1ac1407
Rollup merge of #65113 - Qwaz:master, r=jonas-schievink
tmandry Oct 6, 2019
2f4b471
Rollup merge of #65116 - spastorino:remove-unneeded-fn, r=oli-obk
tmandry Oct 6, 2019
a1eac17
Rollup merge of #65118 - cuviper:Zmutable-noalias-default, r=rkruppe
tmandry Oct 6, 2019
f5c8e12
Rollup merge of #65123 - Centril:mac-invoc-in-mut-pat, r=estebank
tmandry Oct 6, 2019
42caed9
Rollup merge of #65124 - memoryruins:castaway, r=petrochenkov
tmandry Oct 6, 2019
d54082e
Rollup merge of #65126 - BO41:time_typo, r=kennytm
tmandry Oct 6, 2019
485f5c9
Rollup merge of #65130 - davidtwco:rfc-2008-improper-ctypes, r=petroc…
tmandry Oct 6, 2019
69598dc
Rollup merge of #65151 - tmandry:revert-emscripten-upgrade, r=tmandry
tmandry Oct 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
std: Reduce checks for feature = "backtrace"
This is a stylistic change to libstd to reduce the number of checks of
`feature = "backtrace"` now that we unconditionally depend on the
`backtrace` crate and rely on it having an empty implementation.
otherwise.
  • Loading branch information
alexcrichton committed Sep 25, 2019
commit 1d06058a77beffb6347c77b51e12889b7bd9fc76
34 changes: 15 additions & 19 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ use crate::intrinsics;
use crate::mem;
use crate::ptr;
use crate::raw;
use crate::sync::atomic::{AtomicBool, Ordering};
use crate::sys::stdio::panic_output;
use crate::sys_common::rwlock::RWLock;
use crate::sys_common::{thread_info, util, backtrace};
use crate::sys_common::{thread_info, util};
use crate::sys_common::backtrace::{self, RustBacktrace};
use crate::thread;

#[cfg(not(test))]
Expand Down Expand Up @@ -158,16 +160,10 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
fn default_hook(info: &PanicInfo<'_>) {
// If this is a double panic, make sure that we print a backtrace
// for this panic. Otherwise only print it if logging is enabled.
let log_backtrace = if cfg!(feature = "backtrace") {
let panics = update_panic_count(0);

if panics >= 2 {
Some(backtrace_rs::PrintFmt::Full)
} else {
backtrace::log_enabled()
}
let backtrace_env = if update_panic_count(0) >= 2 {
RustBacktrace::Print(backtrace_rs::PrintFmt::Full)
} else {
None
backtrace::rust_backtrace_env()
};

// The current implementation always returns `Some`.
Expand All @@ -187,16 +183,16 @@ fn default_hook(info: &PanicInfo<'_>) {
let _ = writeln!(err, "thread '{}' panicked at '{}', {}",
name, msg, location);

if cfg!(feature = "backtrace") {
use crate::sync::atomic::{AtomicBool, Ordering};

static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);

if let Some(format) = log_backtrace {
let _ = backtrace::print(err, format);
} else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {
let _ = writeln!(err, "note: run with `RUST_BACKTRACE=1` \
environment variable to display a backtrace.");
match backtrace_env {
RustBacktrace::Print(format) => drop(backtrace::print(err, format)),
RustBacktrace::Disabled => {}
RustBacktrace::RuntimeDisabled => {
if FIRST_PANIC.swap(false, Ordering::SeqCst) {
let _ = writeln!(err, "note: run with `RUST_BACKTRACE=1` \
environment variable to display a backtrace.");
}
}
}
};
Expand Down
3 changes: 0 additions & 3 deletions src/libstd/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ fn lang_start_internal(main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindS
sys::args::init(argc, argv);

// Let's run some code!
#[cfg(feature = "backtrace")]
let exit_code = panic::catch_unwind(|| {
sys_common::backtrace::__rust_begin_short_backtrace(move || main())
});
#[cfg(not(feature = "backtrace"))]
let exit_code = panic::catch_unwind(move || main());

sys_common::cleanup();
exit_code.unwrap_or(101) as isize
Expand Down
60 changes: 35 additions & 25 deletions src/libstd/sys_common/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::io;
use crate::borrow::Cow;
use crate::io::prelude::*;
use crate::path::{self, Path, PathBuf};
use crate::sync::atomic::{self, Ordering};
use crate::sys::mutex::Mutex;

use backtrace_rs::{BacktraceFmt, BytesOrWideString, PrintFmt};
Expand Down Expand Up @@ -115,8 +116,10 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
Ok(())
}

/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`.
#[inline(never)]
/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`. Note that
/// this is only inline(never) when backtraces in libstd are enabled, otherwise
/// it's fine to optimize away.
#[cfg_attr(feature = "backtrace", inline(never))]
pub fn __rust_begin_short_backtrace<F, T>(f: F) -> T
where
F: FnOnce() -> T,
Expand All @@ -126,42 +129,49 @@ where
f()
}

pub enum RustBacktrace {
Print(PrintFmt),
Disabled,
RuntimeDisabled,
}

// For now logging is turned off by default, and this function checks to see
// whether the magical environment variable is present to see if it's turned on.
pub fn log_enabled() -> Option<PrintFmt> {
use crate::sync::atomic::{self, Ordering};
pub fn rust_backtrace_env() -> RustBacktrace {
// If the `backtrace` feature of this crate isn't enabled quickly return
// `None` so this can be constant propagated all over the place to turn
// optimize away callers.
if !cfg!(feature = "backtrace") {
return RustBacktrace::Disabled;
}

// Setting environment variables for Fuchsia components isn't a standard
// or easily supported workflow. For now, always display backtraces.
if cfg!(target_os = "fuchsia") {
return Some(PrintFmt::Full);
return RustBacktrace::Print(PrintFmt::Full);
}

static ENABLED: atomic::AtomicIsize = atomic::AtomicIsize::new(0);
match ENABLED.load(Ordering::SeqCst) {
0 => {}
1 => return None,
2 => return Some(PrintFmt::Short),
_ => return Some(PrintFmt::Full),
1 => return RustBacktrace::RuntimeDisabled,
2 => return RustBacktrace::Print(PrintFmt::Short),
_ => return RustBacktrace::Print(PrintFmt::Full),
}

let val = env::var_os("RUST_BACKTRACE").and_then(|x| {
if &x == "0" {
None
} else if &x == "full" {
Some(PrintFmt::Full)
} else {
Some(PrintFmt::Short)
}
});
ENABLED.store(
match val {
Some(v) => v as isize,
None => 1,
},
Ordering::SeqCst,
);
val
let (format, cache) = env::var_os("RUST_BACKTRACE")
.map(|x| {
if &x == "0" {
(RustBacktrace::RuntimeDisabled, 1)
} else if &x == "full" {
(RustBacktrace::Print(PrintFmt::Full), 3)
} else {
(RustBacktrace::Print(PrintFmt::Short), 2)
}
})
.unwrap_or((RustBacktrace::RuntimeDisabled, 1));
ENABLED.store(cache, Ordering::SeqCst);
format
}

/// Prints the filename of the backtrace frame.
Expand Down
3 changes: 0 additions & 3 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,9 @@ impl Builder {
}

thread_info::set(imp::guard::current(), their_thread);
#[cfg(feature = "backtrace")]
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
crate::sys_common::backtrace::__rust_begin_short_backtrace(f)
}));
#[cfg(not(feature = "backtrace"))]
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
*their_packet.get() = Some(try_result);
};

Expand Down