Skip to content

Commit 6be7991

Browse files
committed
add values for associated items of UnalignedField
1 parent b273c2b commit 6be7991

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,17 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
15551555
}
15561556
});
15571557
(metadata_ty.into(), obligations)
1558+
} else if tcx.is_lang_item(trait_def_id, LangItem::UnalignedField) {
1559+
let &ty::Field(container, field_path) = self_ty.kind() else {
1560+
bug!("only `field_of!()` can implement `UnalignedField`")
1561+
};
1562+
if tcx.is_lang_item(item_def_id, LangItem::UnalignedFieldBase) {
1563+
(container.into(), PredicateObligations::new())
1564+
} else if tcx.is_lang_item(item_def_id, LangItem::UnalignedFieldType) {
1565+
(field_path.field_ty(tcx, container).into(), PredicateObligations::new())
1566+
} else {
1567+
bug!("unexpected associated type {:?} in `UnalignedField`", obligation.predicate);
1568+
}
15581569
} else {
15591570
bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate);
15601571
};

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,23 @@ fn resolve_associated_item<'tcx>(
256256
}
257257
}
258258
traits::ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
259-
if tcx.is_lang_item(trait_ref.def_id, LangItem::Clone) {
259+
if tcx.is_lang_item(trait_ref.def_id, LangItem::UnalignedField) {
260+
if tcx.is_lang_item(trait_item_id, LangItem::UnalignedFieldOFFSET) {
261+
let self_ty = trait_ref.self_ty();
262+
match self_ty.kind() {
263+
ty::Field(_, _) => {}
264+
_ => bug!("expected field representing type, found {self_ty}"),
265+
}
266+
Some(Instance {
267+
def: ty::InstanceKind::Item(
268+
tcx.lang_items().get(LangItem::UnalignedFieldOFFSET).unwrap(),
269+
),
270+
args: rcvr_args,
271+
})
272+
} else {
273+
bug!("unexpected associated associated item")
274+
}
275+
} else if tcx.is_lang_item(trait_ref.def_id, LangItem::Clone) {
260276
// FIXME(eddyb) use lang items for methods instead of names.
261277
let name = tcx.item_name(trait_item_id);
262278
if name == sym::clone {

0 commit comments

Comments
 (0)