Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #69919

Merged
merged 48 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
71f92bb
[tidy] update documentation from `make check` to `x.py test`
chrissimpkins Mar 1, 2020
8858d71
Put back output-format option for show-coverage
GuillaumeGomez Nov 16, 2019
10492c3
Add support for json output in show-coverage option
GuillaumeGomez Nov 16, 2019
15babed
add tests for rustdoc output-format json
GuillaumeGomez Nov 16, 2019
f1070b1
Replace ToJson with serde
GuillaumeGomez Feb 17, 2020
1c01646
Extend json detection in runtest
GuillaumeGomez Feb 27, 2020
b646627
remove output-format test
GuillaumeGomez Mar 2, 2020
528cbc4
fix memory leak when vec::IntoIter panics during drop
RalfJung Mar 8, 2020
1a9fc18
panic_bounds_check: use caller_location, like PanicFnLangItem
RalfJung Mar 9, 2020
51b60b7
Improve readability
RalfJung Mar 9, 2020
f34e066
remove no-longer needed span from Miri Machine hook
RalfJung Mar 9, 2020
0982c58
update tidy documentation to recommend ./x.py test tidy
chrissimpkins Mar 10, 2020
259b06e
add documentation of x.py tool testing
chrissimpkins Mar 10, 2020
9f734c9
Add documentation of tool testing with x.py script
chrissimpkins Mar 10, 2020
4922b68
remove trailing whitespace (tidy)
chrissimpkins Mar 10, 2020
c60d581
update x.py tidy testing command
chrissimpkins Mar 10, 2020
6f2c01b
Add long error explanation for E0739
Mar 10, 2020
761c8c1
Removed trailing whitespace
Mar 10, 2020
9596dc2
parse_labeled_expr: simplify
Centril Mar 5, 2020
c303c44
use error_block_no_opening_brace more
Centril Mar 5, 2020
883e90d
simplify parse_inner_attributes
Centril Mar 5, 2020
8ee220c
more reuse in block parsing & improve diagnostics.
Centril Mar 5, 2020
055733f
parse: recover on `&'lt $expr` / `'lt $expr`.
Centril Mar 5, 2020
379f318
parse: simplify parse_fn_body
Centril Mar 5, 2020
be86b2d
parse: recover on `fn foo() = expr;`
Centril Mar 5, 2020
addbc5b
unify/improve/simplify attribute parsing
Centril Mar 5, 2020
fe848b4
parse_block_tail: reduce visibility
Centril Mar 5, 2020
e72df7e
parse_labeled_expr: add a suggestion on missing colon.
Centril Mar 6, 2020
83be689
parser/attr: adjust indentation.
Centril Mar 7, 2020
65b7ba5
parser: add note for `'label expr`.
Centril Mar 7, 2020
c01b3e6
block-no-opening-brace: add another statement
Centril Mar 7, 2020
09997e7
error_block_no_opening_brace: handle closures better
Centril Mar 7, 2020
25cd01b
issue 68890: add more minimal repro
Centril Mar 7, 2020
c0b073b
simplify & improve parse_ty_tuple_or_parens
Centril Mar 7, 2020
d1822b3
use check_path more
Centril Mar 7, 2020
ba3ae46
trait-object-lifetime-parens: improve recovery.
Centril Mar 7, 2020
458383d
parse_if_expr: recover on attributes
Centril Mar 7, 2020
0b2329d
also make panic_fmt track_caller
RalfJung Mar 10, 2020
5357f83
[Miri] Use a session variable instead of checking for an env var always
wesleywiser Feb 17, 2020
1106579
librustc_codegen_llvm: Use slices instead of 0-terminated strings
tmiasko Mar 10, 2020
741d4ff
Rollup merge of #66472 - GuillaumeGomez:show-coverage-json, r=ollie27
Centril Mar 11, 2020
dde2484
Rollup merge of #69603 - chrissimpkins:tidy-docs-update, r=petrochenkov
Centril Mar 11, 2020
9674c09
Rollup merge of #69760 - Centril:parse-expr-improve, r=estebank
Centril Mar 11, 2020
080d413
Rollup merge of #69828 - RalfJung:vec-leak, r=kennytm
Centril Mar 11, 2020
3853da7
Rollup merge of #69850 - RalfJung:panic-bounds-check, r=eddyb
Centril Mar 11, 2020
e838383
Rollup merge of #69876 - ayushmishra2005:doc/61137-add-long-error-cod…
Centril Mar 11, 2020
b1471e0
Rollup merge of #69888 - wesleywiser:miri_exception_env_var_to_sessio…
Centril Mar 11, 2020
a77206f
Rollup merge of #69893 - tmiasko:cstr, r=petrochenkov
Centril Mar 11, 2020
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
33 changes: 20 additions & 13 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ use crate::mir;
use crate::mir::interpret::ConstValue;
use crate::ty::layout::{Align, LayoutError, Size};
use crate::ty::query::TyCtxtAt;
use crate::ty::tls;
use crate::ty::{self, layout, Ty};

use backtrace::Backtrace;
use rustc_data_structures::sync::Lock;
use rustc_errors::{struct_span_err, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace;
use rustc_span::{Pos, Span};
use rustc_target::spec::abi::Abi;
use std::{any::Any, env, fmt};
use std::{any::Any, fmt};

#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]
pub enum ErrorHandled {
Expand Down Expand Up @@ -257,21 +260,25 @@ impl From<ErrorHandled> for InterpErrorInfo<'_> {

impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
fn from(kind: InterpError<'tcx>) -> Self {
let backtrace = match env::var("RUSTC_CTFE_BACKTRACE") {
// Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
Ok(ref val) if val != "0" => {
let mut backtrace = Backtrace::new_unresolved();
let capture_backtrace = tls::with_context_opt(|ctxt| {
if let Some(ctxt) = ctxt {
*Lock::borrow(&ctxt.tcx.sess.ctfe_backtrace)
} else {
CtfeBacktrace::Disabled
}
});

if val == "immediate" {
// Print it now.
print_backtrace(&mut backtrace);
None
} else {
Some(Box::new(backtrace))
}
let backtrace = match capture_backtrace {
CtfeBacktrace::Disabled => None,
CtfeBacktrace::Capture => Some(Box::new(Backtrace::new_unresolved())),
CtfeBacktrace::Immediate => {
// Print it now.
let mut backtrace = Backtrace::new_unresolved();
print_backtrace(&mut backtrace);
None
}
_ => None,
};

InterpErrorInfo { kind, backtrace }
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/librustc_session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ pub struct OptimizationFuel {
out_of_fuel: bool,
}

/// The behavior of the CTFE engine when an error occurs with regards to backtraces.
#[derive(Clone, Copy)]
pub enum CtfeBacktrace {
/// Do nothing special, return the error as usual without a backtrace.
Disabled,
/// Capture a backtrace at the point the error is created and return it in the error
/// (to be printed later if/when the error ever actually gets shown to the user).
Capture,
/// Capture a backtrace at the point the error is created and immediately print it out.
Immediate,
}

/// Represents the data associated with a compilation
/// session for a single crate.
pub struct Session {
Expand Down Expand Up @@ -139,6 +151,11 @@ pub struct Session {
/// Path for libraries that will take preference over libraries shipped by Rust.
/// Used by windows-gnu targets to priortize system mingw-w64 libraries.
pub system_library_path: OneThread<RefCell<Option<Option<PathBuf>>>>,

/// Tracks the current behavior of the CTFE engine when an error occurs.
/// Options range from returning the error without a backtrace to returning an error
/// and immediately printing the backtrace to stderr.
pub ctfe_backtrace: Lock<CtfeBacktrace>,
}

pub struct PerfStats {
Expand Down Expand Up @@ -1040,6 +1057,12 @@ fn build_session_(
sopts.debugging_opts.time_passes,
);

let ctfe_backtrace = Lock::new(match env::var("RUSTC_CTFE_BACKTRACE") {
Ok(ref val) if val == "immediate" => CtfeBacktrace::Immediate,
Ok(ref val) if val != "0" => CtfeBacktrace::Capture,
_ => CtfeBacktrace::Disabled,
});

let sess = Session {
target: target_cfg,
host,
Expand Down Expand Up @@ -1078,6 +1101,7 @@ fn build_session_(
trait_methods_not_found: Lock::new(Default::default()),
confused_type_with_std_module: Lock::new(Default::default()),
system_library_path: OneThread::new(RefCell::new(Default::default())),
ctfe_backtrace,
};

validate_commandline_args_with_session_available(&sess);
Expand Down