mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
Use Item::expect_*
and ImplItem::expect_*
more
This commit is contained in:
parent
e49122fb1c
commit
9534541dd4
@ -138,12 +138,10 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
||||
// Evaluate with the lifetimes in `params` in-scope.
|
||||
// This is used to track which lifetimes have already been defined,
|
||||
// and which need to be replicated when lowering an async fn.
|
||||
match parent_hir.node().expect_item().kind {
|
||||
hir::ItemKind::Impl(hir::Impl { of_trait, .. }) => {
|
||||
lctx.is_in_trait_impl = of_trait.is_some();
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
if let hir::ItemKind::Impl(impl_) = parent_hir.node().expect_item().kind {
|
||||
lctx.is_in_trait_impl = impl_.of_trait.is_some();
|
||||
}
|
||||
|
||||
match ctxt {
|
||||
AssocCtxt::Trait => hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)),
|
||||
|
@ -74,10 +74,9 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
|
||||
|
||||
debug!("visit_implementation_of_copy: self_type={:?} (free)", self_type);
|
||||
|
||||
let span = match tcx.hir().expect_item(impl_did).kind {
|
||||
ItemKind::Impl(hir::Impl { polarity: hir::ImplPolarity::Negative(_), .. }) => return,
|
||||
ItemKind::Impl(impl_) => impl_.self_ty.span,
|
||||
_ => bug!("expected Copy impl item"),
|
||||
let span = match tcx.hir().expect_item(impl_did).expect_impl() {
|
||||
hir::Impl { polarity: hir::ImplPolarity::Negative(_), .. } => return,
|
||||
hir::Impl { self_ty, .. } => self_ty.span,
|
||||
};
|
||||
|
||||
let cause = traits::ObligationCause::misc(span, impl_did);
|
||||
|
@ -462,10 +462,7 @@ fn foo(&self) -> Self::T { String::new() }
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *proj_ty.self_ty().kind() {
|
||||
let opaque_local_def_id = def_id.as_local();
|
||||
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
|
||||
match &tcx.hir().expect_item(opaque_local_def_id).kind {
|
||||
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
|
||||
_ => bug!("The HirId comes from a `ty::Opaque`"),
|
||||
}
|
||||
tcx.hir().expect_item(opaque_local_def_id).expect_opaque_ty()
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
|
@ -392,12 +392,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
/// defining scope.
|
||||
#[instrument(skip(self), level = "trace", ret)]
|
||||
fn opaque_type_origin_unchecked(&self, def_id: LocalDefId) -> OpaqueTyOrigin {
|
||||
match self.tcx.hir().expect_item(def_id).kind {
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => origin,
|
||||
ref itemkind => {
|
||||
bug!("weird opaque type: {:?}, {:#?}", def_id, itemkind)
|
||||
}
|
||||
}
|
||||
self.tcx.hir().expect_item(def_id).expect_opaque_ty().origin
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1469,8 +1469,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
|
||||
match impl_item.kind {
|
||||
ty::AssocKind::Fn => {
|
||||
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
|
||||
let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
|
||||
let (sig, body) =
|
||||
self.tcx.hir().expect_impl_item(def_id.expect_local()).expect_fn();
|
||||
self.tables.asyncness.set_some(def_id.index, sig.header.asyncness);
|
||||
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
|
||||
// Can be inside `impl const Trait`, so using sig.header.constness is not reliable
|
||||
|
Loading…
Reference in New Issue
Block a user