fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) {
debug_assert!(crate_num == LOCAL_CRATE);
tcx.par_body_owners(|body_owner_def_id| {
- tcx.ensure().typeck_tables_of(body_owner_def_id.to_def_id());
+ tcx.ensure().typeck_tables_of(body_owner_def_id);
});
}
fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) {
- wfcheck::check_item_well_formed(tcx, def_id);
+ wfcheck::check_item_well_formed(tcx, def_id.expect_local());
}
fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) {
- wfcheck::check_trait_item(tcx, def_id);
+ wfcheck::check_trait_item(tcx, def_id.expect_local());
}
fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) {
- wfcheck::check_impl_item(tcx, def_id);
+ wfcheck::check_impl_item(tcx, def_id.expect_local());
}
pub fn provide(providers: &mut Providers<'_>) {
}
fn has_typeck_tables(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
+ // FIXME(#71104) some `LocalDefId` do not seem to have a corresponding `HirId`.
+ if let Some(def_id) = def_id.as_local() {
+ if tcx.hir().opt_local_def_id_to_hir_id(def_id).is_none() {
+ return false;
+ }
+ }
+
// Closures' tables come from their outermost function,
// as they are part of the same "inference environment".
let outer_def_id = tcx.closure_base_def_id(def_id);
return tcx.has_typeck_tables(outer_def_id);
}
- // FIXME(#71104) Should really be using just `as_local_hir_id` but
- // some `LocalDefId` do not seem to have a corresponding HirId.
- if let Some(id) =
- def_id.as_local().and_then(|def_id| tcx.hir().opt_local_def_id_to_hir_id(def_id))
- {
+ if let Some(def_id) = def_id.as_local() {
+ let id = tcx.hir().local_def_id_to_hir_id(def_id);
primary_body_of(tcx, id).is_some()
} else {
false
) -> &ty::TypeckTables<'tcx> {
assert!(def_id.is_local());
let fallback = move || {
- let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id).unwrap());
+ let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id.expect_local()));
tcx.sess.delay_span_bug(span, "diagnostic only typeck table used");
tcx.types.err
};
return tcx.typeck_tables_of(outer_def_id);
}
- let id = tcx.hir().as_local_hir_id(def_id).unwrap();
+ let id = tcx.hir().as_local_hir_id(def_id.expect_local());
let span = tcx.hir().span(id);
// Figure out what primary body this item has.
}
let outer_def_id = tcx.closure_base_def_id(hir.local_def_id(fn_id).to_def_id());
- let outer_hir_id = hir.as_local_hir_id(outer_def_id).unwrap();
+ let outer_hir_id = hir.as_local_hir_id(outer_def_id.expect_local());
GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id }.visit_body(body);
// C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
// Check that the main return type implements the termination trait.
if let Some(term_id) = tcx.lang_items().termination() {
if let Some((def_id, EntryFnType::Main)) = tcx.entry_fn(LOCAL_CRATE) {
- let main_id = hir.as_local_hir_id(def_id).unwrap();
+ let main_id = hir.as_local_hir_id(def_id.expect_local());
if main_id == fn_id {
let substs = tcx.mk_substs_trait(declared_ret_ty, &[]);
let trait_ref = ty::TraitRef::new(term_id, substs);
/// Checks that an opaque type does not use `Self` or `T::Foo` projections that would result
/// in "inheriting lifetimes".
fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) {
- let item = tcx.hir().expect_item(
- tcx.hir().as_local_hir_id(def_id.to_def_id()).expect("opaque type is not local"),
- );
+ let item = tcx.hir().expect_item(tcx.hir().as_local_hir_id(def_id));
debug!(
"check_opaque_for_inheriting_lifetimes: def_id={:?} span={:?} item={:?}",
def_id, span, item
);
let hir = tcx.hir();
- if let Some(hir_id) = hir.as_local_hir_id(def_spans[0].0) {
- if let Node::Item(Item { ident, .. }) = hir.get(hir_id) {
- err.span_note(
- tcx.def_span(def_spans[0].0),
- &format!("`{}` has a `#[repr(align)]` attribute", ident),
- );
- }
+ let hir_id = hir.as_local_hir_id(def_spans[0].0.expect_local());
+ if let Node::Item(Item { ident, .. }) = hir.get(hir_id) {
+ err.span_note(
+ tcx.def_span(def_spans[0].0),
+ &format!("`{}` has a `#[repr(align)]` attribute", ident),
+ );
}
if def_spans.len() > 2 {
let mut first = true;
for (adt_def, span) in def_spans.iter().skip(1).rev() {
- if let Some(hir_id) = hir.as_local_hir_id(*adt_def) {
- if let Node::Item(Item { ident, .. }) = hir.get(hir_id) {
- err.span_note(
- *span,
- &if first {
- format!(
- "`{}` contains a field of type `{}`",
- tcx.type_of(def.did),
- ident
- )
- } else {
- format!("...which contains a field of type `{}`", ident)
- },
- );
- first = false;
- }
+ let hir_id = hir.as_local_hir_id(adt_def.expect_local());
+ if let Node::Item(Item { ident, .. }) = hir.get(hir_id) {
+ err.span_note(
+ *span,
+ &if first {
+ format!(
+ "`{}` contains a field of type `{}`",
+ tcx.type_of(def.did),
+ ident
+ )
+ } else {
+ format!("...which contains a field of type `{}`", ident)
+ },
+ );
+ first = false;
}
}
}
// Check for duplicate discriminant values
if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) {
let variant_did = def.variants[VariantIdx::new(i)].def_id;
- let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap();
+ let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did.expect_local());
let variant_i = tcx.hir().expect_variant(variant_i_hir_id);
let i_span = match variant_i.disr_expr {
Some(ref expr) => tcx.hir().span(expr.hir_id),
fn get_type_parameter_bounds(&self, _: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> {
let tcx = self.tcx;
- let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
+ let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let item_id = tcx.hir().ty_param_owner(hir_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id);
}
Some(Node::Ctor(hir::VariantData::Tuple(fields, _))) => {
sugg_call = fields.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
- match hir.as_local_hir_id(def_id).and_then(|hir_id| hir.def_kind(hir_id)) {
- Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, _)) => {
+ match def_id.as_local().map(|def_id| hir.def_kind(def_id)) {
+ Some(DefKind::Ctor(hir::def::CtorOf::Variant, _)) => {
msg = "instantiate this tuple variant";
}
- Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Struct, _)) => {
+ Some(DefKind::Ctor(CtorOf::Struct, _)) => {
msg = "instantiate this tuple struct";
}
_ => {}