MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / target_from_impl_item

Function target_from_impl_item

crates/rustc_codegen_spirv/src/attr.rs:245–263  ·  view source on GitHub ↗

FIXME(eddyb) make this reusable from somewhere in `rustc`.

(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>)

Source from the content-addressed store, hash-verified

243
244// FIXME(eddyb) make this reusable from somewhere in `rustc`.
245fn target_from_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) -> Target {
246 match impl_item.kind {
247 hir::ImplItemKind::Const(..) => Target::AssocConst,
248 hir::ImplItemKind::Fn(..) => {
249 let parent_owner_id = tcx.hir().get_parent_item(impl_item.hir_id());
250 let containing_item = tcx.hir().expect_item(parent_owner_id.def_id);
251 let containing_impl_is_for_trait = match &containing_item.kind {
252 hir::ItemKind::Impl(hir::Impl { of_trait, .. }) => of_trait.is_some(),
253 _ => unreachable!("parent of an ImplItem must be an Impl"),
254 };
255 if containing_impl_is_for_trait {
256 Target::Method(MethodKind::Trait { body: true })
257 } else {
258 Target::Method(MethodKind::Inherent)
259 }
260 }
261 hir::ImplItemKind::Type(..) => Target::AssocTy,
262 }
263}
264
265struct CheckSpirvAttrVisitor<'tcx> {
266 tcx: TyCtxt<'tcx>,

Callers 1

visit_impl_itemMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected