Skip to content

Commit 4773ded

Browse files
committed
Generate &core::panic::Location type in a single place.
1 parent f1d942b commit 4773ded

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/librustc/ty/context.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::session::Session;
88
use crate::session::config::{BorrowckMode, OutputFilenames};
99
use crate::session::config::CrateType;
1010
use crate::middle;
11+
use crate::middle::lang_items::PanicLocationLangItem;
1112
use crate::hir::{self, TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
1213
use crate::hir::def::{Res, DefKind, Export};
1314
use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
@@ -1588,6 +1589,15 @@ impl<'tcx> TyCtxt<'tcx> {
15881589
pub fn has_strict_asm_symbol_naming(&self) -> bool {
15891590
self.sess.target.target.arch.contains("nvptx")
15901591
}
1592+
1593+
/// Returns `&'static core::panic::Location<'static>`.
1594+
pub fn caller_location_ty(&self) -> Ty<'tcx> {
1595+
self.mk_imm_ref(
1596+
self.lifetimes.re_static,
1597+
self.type_of(self.require_lang_item(PanicLocationLangItem, None))
1598+
.subst(*self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
1599+
)
1600+
}
15911601
}
15921602

15931603
impl<'tcx> GlobalCtxt<'tcx> {

src/librustc_mir/const_eval.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::convert::TryInto;
99

1010
use rustc::hir::def::DefKind;
1111
use rustc::hir::def_id::DefId;
12-
use rustc::middle::lang_items::PanicLocationLangItem;
1312
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
1413
use rustc::mir;
1514
use rustc::ty::{self, Ty, TyCtxt, subst::Subst};
@@ -559,11 +558,7 @@ pub fn const_caller_location<'tcx>(
559558
trace!("const_caller_location: {}:{}:{}", file, line, col);
560559
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all());
561560

562-
let loc_ty = tcx.mk_imm_ref(
563-
tcx.lifetimes.re_static,
564-
tcx.type_of(tcx.require_lang_item(PanicLocationLangItem, None))
565-
.subst(tcx, tcx.mk_substs([tcx.lifetimes.re_static.into()].iter())),
566-
);
561+
let loc_ty = tcx.caller_location_ty();
567562
let loc_place = ecx.alloc_caller_location(file, line, col);
568563
intern_const_alloc_recursive(&mut ecx, None, loc_place).unwrap();
569564
let loc_const = ty::Const {

src/librustc_typeck/check/intrinsic.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Type-checking for the rust-intrinsic and platform-intrinsic
22
//! intrinsics that the compiler exposes.
33
4-
use rustc::middle::lang_items::PanicLocationLangItem;
54
use rustc::traits::{ObligationCause, ObligationCauseCode};
65
use rustc::ty::{self, TyCtxt, Ty};
76
use rustc::ty::subst::Subst;
@@ -148,15 +147,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
148147
], tcx.types.usize)
149148
}
150149
"rustc_peek" => (1, vec![param(0)], param(0)),
151-
"caller_location" => (
152-
0,
153-
vec![],
154-
tcx.mk_imm_ref(
155-
tcx.lifetimes.re_static,
156-
tcx.type_of(tcx.require_lang_item(PanicLocationLangItem, None))
157-
.subst(tcx, tcx.mk_substs([tcx.lifetimes.re_static.into()].iter())),
158-
),
159-
),
150+
"caller_location" => (0, vec![], tcx.caller_location_ty()),
160151
"panic_if_uninhabited" => (1, Vec::new(), tcx.mk_unit()),
161152
"init" => (1, Vec::new(), param(0)),
162153
"uninit" => (1, Vec::new(), param(0)),

0 commit comments

Comments
 (0)