Skip to content

Commit ba3b6ed

Browse files
committed
Add implicit argument to MIR of #[track_caller] functions.
1 parent 3a4f45d commit ba3b6ed

File tree

5 files changed

+55
-18
lines changed

5 files changed

+55
-18
lines changed

src/librustc_mir/build/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
8989
_ => None,
9090
};
9191

92+
// if this fn has #[track_caller], it will receive an implicit argument with a location
93+
let has_track_caller = tcx.codegen_fn_attrs(def_id).flags
94+
.contains(hir::CodegenFnAttrFlags::TRACK_CALLER);
95+
let location_argument = if has_track_caller {
96+
#[cfg(not(bootstrap))]
97+
{
98+
use rustc::middle::lang_items::PanicLocationLangItem;
99+
let panic_loc_item = tcx.require_lang_item(PanicLocationLangItem, None);
100+
let panic_loc_ty = tcx.type_of(panic_loc_item);
101+
Some(ArgInfo(panic_loc_ty, None, None, None))
102+
}
103+
#[cfg(bootstrap)]
104+
{
105+
bug!("#[track_caller] can't be used during a bootstrap build (yet).");
106+
}
107+
} else {
108+
None
109+
};
110+
92111
let safety = match fn_sig.unsafety {
93112
hir::Unsafety::Normal => Safety::Safe,
94113
hir::Unsafety::Unsafe => Safety::FnUnsafe,
@@ -141,7 +160,9 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
141160
ArgInfo(ty, opt_ty_info, Some(&arg), self_arg)
142161
});
143162

144-
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
163+
let arguments = implicit_argument.into_iter()
164+
.chain(location_argument)
165+
.chain(explicit_arguments);
145166

146167
let (yield_ty, return_ty) = if body.generator_kind.is_some() {
147168
let gen_sig = match ty.kind {

src/test/ui/rfc-2091-track-caller/pass.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/test/ui/rfc-2091-track-caller/pass.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// failure-status: 101
2+
// normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET"
3+
// normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS"
4+
5+
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete
6+
7+
#[track_caller]
8+
fn f() {}
9+
10+
fn main() {
11+
f();
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
warning: the feature `track_caller` is incomplete and may cause the compiler to crash
2+
--> $DIR/should-pass.rs:5:12
3+
|
4+
LL | #![feature(track_caller)]
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', $SRC_DIR/libcore/slice/mod.rs:LL:COL
10+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
11+
12+
error: internal compiler error: unexpected panic
13+
14+
note: the compiler unexpectedly panicked. this is a bug.
15+
16+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
17+
18+
note: rustc VERSION running on TARGET
19+
20+
note: compiler flags: FLAGS
21+

0 commit comments

Comments
 (0)