Rollup merge of #110461 - WaffleLapkin:expect_, r=Nilstrieb
Use `Item::expect_*` and `ImplItem::expect_*` more r? ``@Nilstrieb``
This commit is contained in:
commit
d97b39d3a0
6 changed files with 11 additions and 24 deletions
|
@ -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)),
|
||||
|
|
|
@ -3146,7 +3146,6 @@ impl<'hir> Item<'hir> {
|
|||
(ty, gen)
|
||||
}
|
||||
|
||||
/// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`.
|
||||
/// Expect an [`ItemKind::OpaqueTy`] or panic.
|
||||
#[track_caller]
|
||||
pub fn expect_opaque_ty(&self) -> &OpaqueTy<'hir> {
|
||||
|
@ -3168,7 +3167,6 @@ impl<'hir> Item<'hir> {
|
|||
(data, gen)
|
||||
}
|
||||
|
||||
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
|
||||
/// Expect an [`ItemKind::Union`] or panic.
|
||||
#[track_caller]
|
||||
pub fn expect_union(&self) -> (&VariantData<'hir>, &'hir Generics<'hir>) {
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue