Add Option<Span> to require_lang_item
This commit is contained in:
parent
7e0afdad28
commit
82f2b37635
19 changed files with 39 additions and 28 deletions
|
@ -1460,7 +1460,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem);
|
let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem, None);
|
||||||
|
|
||||||
// this can get called from typeck (by euv), and moves_by_default
|
// this can get called from typeck (by euv), and moves_by_default
|
||||||
// rightly refuses to work with inference variables, but
|
// rightly refuses to work with inference variables, but
|
||||||
|
|
|
@ -381,9 +381,13 @@ language_item_table! {
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Returns the `DefId` for a given `LangItem`.
|
/// Returns the `DefId` for a given `LangItem`.
|
||||||
/// If not found, fatally abort compilation.
|
/// If not found, fatally abort compilation.
|
||||||
pub fn require_lang_item(&self, lang_item: LangItem) -> DefId {
|
pub fn require_lang_item(&self, lang_item: LangItem, span: Option<Span>) -> DefId {
|
||||||
self.lang_items().require(lang_item).unwrap_or_else(|msg| {
|
self.lang_items().require(lang_item).unwrap_or_else(|msg| {
|
||||||
|
if let Some(span) = span {
|
||||||
|
self.sess.span_fatal(span, &msg)
|
||||||
|
} else {
|
||||||
self.sess.fatal(&msg)
|
self.sess.fatal(&msg)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3513,7 +3513,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
// We can only make objects from sized types.
|
// We can only make objects from sized types.
|
||||||
let tr = ty::TraitRef {
|
let tr = ty::TraitRef {
|
||||||
def_id: tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
def_id: tcx.require_lang_item(lang_items::SizedTraitLangItem, None),
|
||||||
substs: tcx.mk_substs_trait(source, &[]),
|
substs: tcx.mk_substs_trait(source, &[]),
|
||||||
};
|
};
|
||||||
nested.push(predicate_to_obligation(tr.to_predicate()));
|
nested.push(predicate_to_obligation(tr.to_predicate()));
|
||||||
|
|
|
@ -2385,13 +2385,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem);
|
let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem, None);
|
||||||
self.mk_generic_adt(def_id, ty)
|
self.mk_generic_adt(def_id, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem);
|
let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem, None);
|
||||||
self.mk_generic_adt(def_id, ty)
|
self.mk_generic_adt(def_id, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,7 @@ impl<'tcx> Instance<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
|
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
|
||||||
let def_id = tcx.require_lang_item(DropInPlaceFnLangItem);
|
let def_id = tcx.require_lang_item(DropInPlaceFnLangItem, None);
|
||||||
let substs = tcx.intern_substs(&[ty.into()]);
|
let substs = tcx.intern_substs(&[ty.into()]);
|
||||||
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap()
|
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2588,12 +2588,12 @@ impl<'tcx> ClosureKind {
|
||||||
|
|
||||||
pub fn trait_did(&self, tcx: TyCtxt<'tcx>) -> DefId {
|
pub fn trait_did(&self, tcx: TyCtxt<'tcx>) -> DefId {
|
||||||
match *self {
|
match *self {
|
||||||
ClosureKind::Fn => tcx.require_lang_item(FnTraitLangItem),
|
ClosureKind::Fn => tcx.require_lang_item(FnTraitLangItem, None),
|
||||||
ClosureKind::FnMut => {
|
ClosureKind::FnMut => {
|
||||||
tcx.require_lang_item(FnMutTraitLangItem)
|
tcx.require_lang_item(FnMutTraitLangItem, None)
|
||||||
}
|
}
|
||||||
ClosureKind::FnOnce => {
|
ClosureKind::FnOnce => {
|
||||||
tcx.require_lang_item(FnOnceTraitLangItem)
|
tcx.require_lang_item(FnOnceTraitLangItem, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -998,7 +998,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||||
|
|
||||||
fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
|
fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
|
||||||
let (param_env, ty) = query.into_parts();
|
let (param_env, ty) = query.into_parts();
|
||||||
let trait_def_id = tcx.require_lang_item(lang_items::CopyTraitLangItem);
|
let trait_def_id = tcx.require_lang_item(lang_items::CopyTraitLangItem, None);
|
||||||
tcx.infer_ctxt()
|
tcx.infer_ctxt()
|
||||||
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
|
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
|
||||||
&infcx,
|
&infcx,
|
||||||
|
@ -1011,7 +1011,7 @@ fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
|
||||||
|
|
||||||
fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
|
fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
|
||||||
let (param_env, ty) = query.into_parts();
|
let (param_env, ty) = query.into_parts();
|
||||||
let trait_def_id = tcx.require_lang_item(lang_items::SizedTraitLangItem);
|
let trait_def_id = tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
|
||||||
tcx.infer_ctxt()
|
tcx.infer_ctxt()
|
||||||
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
|
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
|
||||||
&infcx,
|
&infcx,
|
||||||
|
@ -1024,7 +1024,7 @@ fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
|
||||||
|
|
||||||
fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
|
fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
|
||||||
let (param_env, ty) = query.into_parts();
|
let (param_env, ty) = query.into_parts();
|
||||||
let trait_def_id = tcx.require_lang_item(lang_items::FreezeTraitLangItem);
|
let trait_def_id = tcx.require_lang_item(lang_items::FreezeTraitLangItem, None);
|
||||||
tcx.infer_ctxt()
|
tcx.infer_ctxt()
|
||||||
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
|
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
|
||||||
&infcx,
|
&infcx,
|
||||||
|
|
|
@ -221,7 +221,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
if !subty.has_escaping_bound_vars() {
|
if !subty.has_escaping_bound_vars() {
|
||||||
let cause = self.cause(cause);
|
let cause = self.cause(cause);
|
||||||
let trait_ref = ty::TraitRef {
|
let trait_ref = ty::TraitRef {
|
||||||
def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None),
|
||||||
substs: self.infcx.tcx.mk_substs_trait(subty, &[]),
|
substs: self.infcx.tcx.mk_substs_trait(subty, &[]),
|
||||||
};
|
};
|
||||||
self.out.push(traits::Obligation::new(cause, self.param_env, trait_ref.to_predicate()));
|
self.out.push(traits::Obligation::new(cause, self.param_env, trait_ref.to_predicate()));
|
||||||
|
|
|
@ -456,7 +456,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
|
||||||
let arg_argv = param_argv;
|
let arg_argv = param_argv;
|
||||||
|
|
||||||
let (start_fn, args) = if use_start_lang_item {
|
let (start_fn, args) = if use_start_lang_item {
|
||||||
let start_def_id = cx.tcx().require_lang_item(StartFnLangItem);
|
let start_def_id = cx.tcx().require_lang_item(StartFnLangItem, None);
|
||||||
let start_fn = callee::resolve_and_get_fn(
|
let start_fn = callee::resolve_and_get_fn(
|
||||||
cx,
|
cx,
|
||||||
start_def_id,
|
start_def_id,
|
||||||
|
|
|
@ -443,7 +443,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
_ => bug!("non_scalar_compare called on non-reference type: {}", ty),
|
_ => bug!("non_scalar_compare called on non-reference type: {}", ty),
|
||||||
};
|
};
|
||||||
|
|
||||||
let eq_def_id = self.hir.tcx().require_lang_item(EqTraitLangItem);
|
let eq_def_id = self.hir.tcx().require_lang_item(EqTraitLangItem, None);
|
||||||
let method = self.hir.trait_method(eq_def_id, sym::eq, deref_ty, &[deref_ty.into()]);
|
let method = self.hir.trait_method(eq_def_id, sym::eq, deref_ty, &[deref_ty.into()]);
|
||||||
|
|
||||||
let bool_ty = self.hir.bool_ty();
|
let bool_ty = self.hir.bool_ty();
|
||||||
|
|
|
@ -1752,7 +1752,10 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
|
||||||
fulfillment_cx.register_bound(&infcx,
|
fulfillment_cx.register_bound(&infcx,
|
||||||
param_env,
|
param_env,
|
||||||
ty,
|
ty,
|
||||||
tcx.require_lang_item(lang_items::SyncTraitLangItem),
|
tcx.require_lang_item(
|
||||||
|
lang_items::SyncTraitLangItem,
|
||||||
|
None
|
||||||
|
),
|
||||||
cause);
|
cause);
|
||||||
if let Err(err) = fulfillment_cx.select_all_or_error(&infcx) {
|
if let Err(err) = fulfillment_cx.select_all_or_error(&infcx) {
|
||||||
infcx.report_fulfillment_errors(&err, None, false);
|
infcx.report_fulfillment_errors(&err, None, false);
|
||||||
|
|
|
@ -897,7 +897,7 @@ where
|
||||||
) -> BasicBlock {
|
) -> BasicBlock {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let unit_temp = Place::from(self.new_temp(tcx.mk_unit()));
|
let unit_temp = Place::from(self.new_temp(tcx.mk_unit()));
|
||||||
let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem);
|
let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem, None);
|
||||||
let args = adt.variants[VariantIdx::new(0)].fields.iter().enumerate().map(|(i, f)| {
|
let args = adt.variants[VariantIdx::new(0)].fields.iter().enumerate().map(|(i, f)| {
|
||||||
let field = Field::new(i);
|
let field = Field::new(i);
|
||||||
let field_ty = f.ty(self.tcx(), substs);
|
let field_ty = f.ty(self.tcx(), substs);
|
||||||
|
|
|
@ -649,7 +649,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fn type_is_known_to_be_sized_modulo_regions(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
fn type_is_known_to_be_sized_modulo_regions(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
||||||
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem);
|
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
|
||||||
traits::type_known_to_meet_bound_modulo_regions(self, self.param_env, ty, lang_item, span)
|
traits::type_known_to_meet_bound_modulo_regions(self, self.param_env, ty, lang_item, span)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let trait_ref = projection.to_poly_trait_ref(tcx);
|
let trait_ref = projection.to_poly_trait_ref(tcx);
|
||||||
|
|
||||||
let is_fn = tcx.lang_items().fn_trait_kind(trait_ref.def_id()).is_some();
|
let is_fn = tcx.lang_items().fn_trait_kind(trait_ref.def_id()).is_some();
|
||||||
let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem);
|
let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem, cause_span);
|
||||||
let is_gen = gen_trait == trait_ref.def_id();
|
let is_gen = gen_trait == trait_ref.def_id();
|
||||||
if !is_fn && !is_gen {
|
if !is_fn && !is_gen {
|
||||||
debug!("deduce_sig_from_projection: not fn or generator");
|
debug!("deduce_sig_from_projection: not fn or generator");
|
||||||
|
|
|
@ -2622,7 +2622,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
code: traits::ObligationCauseCode<'tcx>)
|
code: traits::ObligationCauseCode<'tcx>)
|
||||||
{
|
{
|
||||||
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem);
|
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
|
||||||
self.require_type_meets(ty, span, code, lang_item);
|
self.require_type_meets(ty, span, code, lang_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -287,7 +287,7 @@ fn check_type_defn<'tcx, F>(
|
||||||
let last = idx == variant.fields.len() - 1;
|
let last = idx == variant.fields.len() - 1;
|
||||||
fcx.register_bound(
|
fcx.register_bound(
|
||||||
field.ty,
|
field.ty,
|
||||||
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None),
|
||||||
traits::ObligationCause::new(
|
traits::ObligationCause::new(
|
||||||
field.span,
|
field.span,
|
||||||
fcx.body_id,
|
fcx.body_id,
|
||||||
|
@ -375,7 +375,7 @@ fn check_item_type(
|
||||||
if forbid_unsized {
|
if forbid_unsized {
|
||||||
fcx.register_bound(
|
fcx.register_bound(
|
||||||
item_ty,
|
item_ty,
|
||||||
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None),
|
||||||
traits::ObligationCause::new(ty_span, fcx.body_id, traits::MiscObligation),
|
traits::ObligationCause::new(ty_span, fcx.body_id, traits::MiscObligation),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -464,7 +464,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
// it is *not* required (i.e., '?Sized')
|
// it is *not* required (i.e., '?Sized')
|
||||||
let sized_trait = self.cx
|
let sized_trait = self.cx
|
||||||
.tcx
|
.tcx
|
||||||
.require_lang_item(lang_items::SizedTraitLangItem);
|
.require_lang_item(lang_items::SizedTraitLangItem, None);
|
||||||
|
|
||||||
let mut replacer = RegionReplacer {
|
let mut replacer = RegionReplacer {
|
||||||
vid_to_region: &vid_to_region,
|
vid_to_region: &vid_to_region,
|
||||||
|
@ -777,9 +777,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
fn is_fn_ty(&self, tcx: TyCtxt<'_>, ty: &Type) -> bool {
|
fn is_fn_ty(&self, tcx: TyCtxt<'_>, ty: &Type) -> bool {
|
||||||
match &ty {
|
match &ty {
|
||||||
&&Type::ResolvedPath { ref did, .. } => {
|
&&Type::ResolvedPath { ref did, .. } => {
|
||||||
*did == tcx.require_lang_item(lang_items::FnTraitLangItem)
|
*did == tcx.require_lang_item(lang_items::FnTraitLangItem, None)
|
||||||
|| *did == tcx.require_lang_item(lang_items::FnMutTraitLangItem)
|
|| *did == tcx.require_lang_item(lang_items::FnMutTraitLangItem, None)
|
||||||
|| *did == tcx.require_lang_item(lang_items::FnOnceTraitLangItem)
|
|| *did == tcx.require_lang_item(lang_items::FnOnceTraitLangItem, None)
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1060,7 +1060,7 @@ pub enum GenericBound {
|
||||||
|
|
||||||
impl GenericBound {
|
impl GenericBound {
|
||||||
fn maybe_sized(cx: &DocContext<'_>) -> GenericBound {
|
fn maybe_sized(cx: &DocContext<'_>) -> GenericBound {
|
||||||
let did = cx.tcx.require_lang_item(lang_items::SizedTraitLangItem);
|
let did = cx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None);
|
||||||
let empty = cx.tcx.intern_substs(&[]);
|
let empty = cx.tcx.intern_substs(&[]);
|
||||||
let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
|
let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
|
||||||
Some(did), false, vec![], empty);
|
Some(did), false, vec![], empty);
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
error: requires `generator` lang_item
|
error: requires `generator` lang_item
|
||||||
|
--> $DIR/lang-item-missing-generator.rs:15:17
|
||||||
|
|
|
||||||
|
LL | pub fn abc() -> impl FnOnce(f32) {
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue