Generate &core::panic::Location type in a single place.
This commit is contained in:
parent
f1d942b371
commit
4773ded15b
3 changed files with 12 additions and 16 deletions
|
@ -8,6 +8,7 @@ use crate::session::Session;
|
||||||
use crate::session::config::{BorrowckMode, OutputFilenames};
|
use crate::session::config::{BorrowckMode, OutputFilenames};
|
||||||
use crate::session::config::CrateType;
|
use crate::session::config::CrateType;
|
||||||
use crate::middle;
|
use crate::middle;
|
||||||
|
use crate::middle::lang_items::PanicLocationLangItem;
|
||||||
use crate::hir::{self, TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
|
use crate::hir::{self, TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
|
||||||
use crate::hir::def::{Res, DefKind, Export};
|
use crate::hir::def::{Res, DefKind, Export};
|
||||||
use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
|
use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
|
||||||
|
@ -1588,6 +1589,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn has_strict_asm_symbol_naming(&self) -> bool {
|
pub fn has_strict_asm_symbol_naming(&self) -> bool {
|
||||||
self.sess.target.target.arch.contains("nvptx")
|
self.sess.target.target.arch.contains("nvptx")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `&'static core::panic::Location<'static>`.
|
||||||
|
pub fn caller_location_ty(&self) -> Ty<'tcx> {
|
||||||
|
self.mk_imm_ref(
|
||||||
|
self.lifetimes.re_static,
|
||||||
|
self.type_of(self.require_lang_item(PanicLocationLangItem, None))
|
||||||
|
.subst(*self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> GlobalCtxt<'tcx> {
|
impl<'tcx> GlobalCtxt<'tcx> {
|
||||||
|
|
|
@ -9,7 +9,6 @@ use std::convert::TryInto;
|
||||||
|
|
||||||
use rustc::hir::def::DefKind;
|
use rustc::hir::def::DefKind;
|
||||||
use rustc::hir::def_id::DefId;
|
use rustc::hir::def_id::DefId;
|
||||||
use rustc::middle::lang_items::PanicLocationLangItem;
|
|
||||||
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
|
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
|
||||||
use rustc::mir;
|
use rustc::mir;
|
||||||
use rustc::ty::{self, Ty, TyCtxt, subst::Subst};
|
use rustc::ty::{self, Ty, TyCtxt, subst::Subst};
|
||||||
|
@ -559,11 +558,7 @@ pub fn const_caller_location<'tcx>(
|
||||||
trace!("const_caller_location: {}:{}:{}", file, line, col);
|
trace!("const_caller_location: {}:{}:{}", file, line, col);
|
||||||
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all());
|
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all());
|
||||||
|
|
||||||
let loc_ty = tcx.mk_imm_ref(
|
let loc_ty = tcx.caller_location_ty();
|
||||||
tcx.lifetimes.re_static,
|
|
||||||
tcx.type_of(tcx.require_lang_item(PanicLocationLangItem, None))
|
|
||||||
.subst(tcx, tcx.mk_substs([tcx.lifetimes.re_static.into()].iter())),
|
|
||||||
);
|
|
||||||
let loc_place = ecx.alloc_caller_location(file, line, col);
|
let loc_place = ecx.alloc_caller_location(file, line, col);
|
||||||
intern_const_alloc_recursive(&mut ecx, None, loc_place).unwrap();
|
intern_const_alloc_recursive(&mut ecx, None, loc_place).unwrap();
|
||||||
let loc_const = ty::Const {
|
let loc_const = ty::Const {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! Type-checking for the rust-intrinsic and platform-intrinsic
|
//! Type-checking for the rust-intrinsic and platform-intrinsic
|
||||||
//! intrinsics that the compiler exposes.
|
//! intrinsics that the compiler exposes.
|
||||||
|
|
||||||
use rustc::middle::lang_items::PanicLocationLangItem;
|
|
||||||
use rustc::traits::{ObligationCause, ObligationCauseCode};
|
use rustc::traits::{ObligationCause, ObligationCauseCode};
|
||||||
use rustc::ty::{self, TyCtxt, Ty};
|
use rustc::ty::{self, TyCtxt, Ty};
|
||||||
use rustc::ty::subst::Subst;
|
use rustc::ty::subst::Subst;
|
||||||
|
@ -148,15 +147,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
|
||||||
], tcx.types.usize)
|
], tcx.types.usize)
|
||||||
}
|
}
|
||||||
"rustc_peek" => (1, vec![param(0)], param(0)),
|
"rustc_peek" => (1, vec![param(0)], param(0)),
|
||||||
"caller_location" => (
|
"caller_location" => (0, vec![], tcx.caller_location_ty()),
|
||||||
0,
|
|
||||||
vec![],
|
|
||||||
tcx.mk_imm_ref(
|
|
||||||
tcx.lifetimes.re_static,
|
|
||||||
tcx.type_of(tcx.require_lang_item(PanicLocationLangItem, None))
|
|
||||||
.subst(tcx, tcx.mk_substs([tcx.lifetimes.re_static.into()].iter())),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
"panic_if_uninhabited" => (1, Vec::new(), tcx.mk_unit()),
|
"panic_if_uninhabited" => (1, Vec::new(), tcx.mk_unit()),
|
||||||
"init" => (1, Vec::new(), param(0)),
|
"init" => (1, Vec::new(), param(0)),
|
||||||
"uninit" => (1, Vec::new(), param(0)),
|
"uninit" => (1, Vec::new(), param(0)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue