Auto merge of #135031 - RalfJung:intrinsics-without-body, r=oli-obk
rustc_intrinsic: support functions without body
We synthesize a HIR body `loop {}` but such bodyless intrinsics.
Most of the diff is due to turning `ItemKind::Fn` into a brace (named-field) enum variant, because it carries a `bool`-typed field now. This is to remember whether the function has a body. MIR building panics to avoid ever translating the fake `loop {}` body, and the intrinsic logic uses the lack of a body to implicitly mark that intrinsic as must-be-overridden.
I first tried actually having no body rather than generating the fake body, but there's a *lot* of code that assumes that all function items have HIR and MIR, so this didn't work very well. Then I noticed that even `rustc_intrinsic_must_be_overridden` intrinsics have MIR generated (they are filled with an `Unreachable` terminator) so I guess I am not the first to discover this. ;)
r? `@oli-obk`
This commit is contained in:
@@ -795,7 +795,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||
}
|
||||
}
|
||||
|
||||
hir::ItemKind::Fn(..) => {
|
||||
hir::ItemKind::Fn { .. } => {
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
@@ -1325,7 +1325,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
|
||||
generics,
|
||||
..
|
||||
})
|
||||
| Item(hir::Item { kind: ItemKind::Fn(sig, generics, _), .. }) => {
|
||||
| Item(hir::Item { kind: ItemKind::Fn { sig, generics, .. }, .. }) => {
|
||||
lower_fn_sig_recovering_infer_ret_ty(&icx, sig, generics, def_id)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user