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

Add Option<Span> to require_lang_item #63961

Merged
merged 3 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// rightly refuses to work with inference variables, but
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,13 @@ language_item_table! {
impl<'tcx> TyCtxt<'tcx> {
/// Returns the `DefId` for a given `LangItem`.
/// 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.sess.fatal(&msg)
if let Some(span) = span {
self.sess.span_fatal(span, &msg)
} else {
self.sess.fatal(&msg)
}
})
}
}
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3513,7 +3513,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

// We can only make objects from sized types.
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, &[]),
};
nested.push(predicate_to_obligation(tr.to_predicate()));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,13 +2385,13 @@ impl<'tcx> TyCtxt<'tcx> {

#[inline]
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)
}

#[inline]
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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<'tcx> 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()]);
Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap()
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2588,12 +2588,12 @@ impl<'tcx> ClosureKind {

pub fn trait_did(&self, tcx: TyCtxt<'tcx>) -> DefId {
match *self {
ClosureKind::Fn => tcx.require_lang_item(FnTraitLangItem),
ClosureKind::Fn => tcx.require_lang_item(FnTraitLangItem, None),
ClosureKind::FnMut => {
tcx.require_lang_item(FnMutTraitLangItem)
tcx.require_lang_item(FnMutTraitLangItem, None)
}
ClosureKind::FnOnce => {
tcx.require_lang_item(FnOnceTraitLangItem)
tcx.require_lang_item(FnOnceTraitLangItem, None)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ impl<'tcx> ty::TyS<'tcx> {

fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
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()
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
&infcx,
Expand All @@ -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 {
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()
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
&infcx,
Expand All @@ -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 {
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()
.enter(|infcx| traits::type_known_to_meet_bound_modulo_regions(
&infcx,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
if !subty.has_escaping_bound_vars() {
let cause = self.cause(cause);
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, &[]),
};
self.out.push(traits::Obligation::new(cause, self.param_env, trait_ref.to_predicate()));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
let arg_argv = param_argv;

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(
cx,
start_def_id,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
_ => 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 bool_ty = self.hir.bool_ty();
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,10 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
fulfillment_cx.register_bound(&infcx,
param_env,
ty,
tcx.require_lang_item(lang_items::SyncTraitLangItem),
tcx.require_lang_item(
lang_items::SyncTraitLangItem,
Some(body.span)
),
cause);
if let Err(err) = fulfillment_cx.select_all_or_error(&infcx) {
infcx.report_fulfillment_errors(&err, None, false);
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/util/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,10 @@ where
) -> BasicBlock {
let tcx = self.tcx();
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,
Some(self.source_info.span)
);
let args = adt.variants[VariantIdx::new(0)].fields.iter().enumerate().map(|(i, f)| {
let field = Field::new(i);
let field_ty = f.ty(self.tcx(), substs);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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, Some(span));
traits::type_known_to_meet_bound_modulo_regions(self, self.param_env, ty, lang_item, span)
}
}
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, '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 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();
if !is_fn && !is_gen {
debug!("deduce_sig_from_projection: not fn or generator");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
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, Some(span));
self.require_type_meets(ty, span, code, lang_item);
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn check_type_defn<'tcx, F>(
let last = idx == variant.fields.len() - 1;
fcx.register_bound(
field.ty,
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem, None),
traits::ObligationCause::new(
field.span,
fcx.body_id,
Expand Down Expand Up @@ -375,7 +375,7 @@ fn check_item_type(
if forbid_unsized {
fcx.register_bound(
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),
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
// it is *not* required (i.e., '?Sized')
let sized_trait = self.cx
.tcx
.require_lang_item(lang_items::SizedTraitLangItem);
.require_lang_item(lang_items::SizedTraitLangItem, None);

let mut replacer = RegionReplacer {
vid_to_region: &vid_to_region,
Expand Down Expand Up @@ -777,9 +777,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
fn is_fn_ty(&self, tcx: TyCtxt<'_>, ty: &Type) -> bool {
match &ty {
&&Type::ResolvedPath { ref did, .. } => {
*did == tcx.require_lang_item(lang_items::FnTraitLangItem)
|| *did == tcx.require_lang_item(lang_items::FnMutTraitLangItem)
|| *did == tcx.require_lang_item(lang_items::FnOnceTraitLangItem)
*did == tcx.require_lang_item(lang_items::FnTraitLangItem, None)
|| *did == tcx.require_lang_item(lang_items::FnMutTraitLangItem, None)
|| *did == tcx.require_lang_item(lang_items::FnOnceTraitLangItem, None)
}
_ => false,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ pub enum GenericBound {

impl 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 path = external_path(cx, &cx.tcx.item_name(did).as_str(),
Some(did), false, vec![], empty);
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/lang-item-missing-generator.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
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

4 changes: 4 additions & 0 deletions src/test/ui/lang-item-missing.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
error: requires `sized` lang_item
--> $DIR/lang-item-missing.rs:10:50
|
LL | fn start(argc: isize, argv: *const *const u8) -> isize {
| ^^^^^

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/privacy/privacy2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod bar {
}
}

pub fn foo() {}
pub fn foo() {} //~ ERROR: requires `sized` lang_item

fn test1() {
use bar::foo;
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/privacy/privacy2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ LL | use bar::glob::foo;
| ^^^

error: requires `sized` lang_item
--> $DIR/privacy2.rs:14:14
|
LL | pub fn foo() {}
| ^
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonas-schievink This and privacy3 are expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but yeah it's not a very good error span. Feel free to remove the spans for the Sized lang item, the compiler needs that lang item for all sorts of checks that don't really correspond to any language features.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, okay, it may cause confusing so I'd like to remove their spans.


error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/privacy/privacy3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod bar {
pub use self::glob::*;

mod glob {
fn gpriv() {}
fn gpriv() {} //~ ERROR: requires `sized` lang_item
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/privacy/privacy3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ LL | use bar::gpriv;
| ^^^^^^^^^^ no `gpriv` in `bar`

error: requires `sized` lang_item
--> $DIR/privacy3.rs:11:20
|
LL | fn gpriv() {}
| ^

error: aborting due to 2 previous errors

Expand Down