diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-05-23 20:09:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-23 20:09:10 +0200 |
| commit | 55a16a480303c064a3e52e76a33e1594a3093861 (patch) | |
| tree | d8f1808988e6095e09a4199142dfdebfb382d4f6 /compiler/rustc_codegen_llvm/src | |
| parent | 72cc4de6607bde50ff4e51fb51278ff69fb1a454 (diff) | |
| parent | b1fa845d426bb9866851c8ea610c34b68a4111b4 (diff) | |
| download | rust-55a16a480303c064a3e52e76a33e1594a3093861.tar.gz rust-55a16a480303c064a3e52e76a33e1594a3093861.zip | |
Rollup merge of #125454 - mu001999-contrib:master, r=oli-obk
Improve the doc of query associated_item
<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.
This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using
r? <reviewer name>
-->
This query also maps from a impl item to the impl item "descriptor". So it's a bit confused, I skipped it cause it doesn't say it contains impl items.
```rust
fn associated_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AssocItem {
let id = tcx.local_def_id_to_hir_id(def_id);
let parent_def_id = tcx.hir().get_parent_item(id);
let parent_item = tcx.hir().expect_item(parent_def_id.def_id);
match parent_item.kind {
hir::ItemKind::Impl(impl_) => {
if let Some(impl_item_ref) = impl_.items.iter().find(|i| i.id.owner_id.def_id == def_id)
{
let assoc_item = associated_item_from_impl_item_ref(impl_item_ref);
debug_assert_eq!(assoc_item.def_id.expect_local(), def_id);
return assoc_item;
}
}
hir::ItemKind::Trait(.., trait_item_refs) => {
if let Some(trait_item_ref) =
trait_item_refs.iter().find(|i| i.id.owner_id.def_id == def_id)
{
let assoc_item = associated_item_from_trait_item_ref(trait_item_ref);
debug_assert_eq!(assoc_item.def_id.expect_local(), def_id);
return assoc_item;
}
}
_ => {}
}
span_bug!(
parent_item.span,
"unexpected parent of trait or impl item or item not found: {:?}",
parent_item.kind
)
}
```
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
