Skip to content

Commit 4a8f5c9

Browse files
committed
remove unaligned & unsized field support from lib & their lang items
1 parent b568a77 commit 4a8f5c9

File tree

18 files changed

+40
-77
lines changed

18 files changed

+40
-77
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
646646
sym::fmuladdf64 => self.float_muladd_intrinsic::<Double>(args, dest)?,
647647
sym::fmuladdf128 => self.float_muladd_intrinsic::<Quad>(args, dest)?,
648648

649-
sym::unaligned_field_offset => self.unaligned_field_offset(instance, dest)?,
649+
sym::field_offset => self.field_offset(instance, dest)?,
650650

651651
// Unsupported intrinsic: skip the return_to_block below.
652652
_ => return interp_ok(false),
@@ -657,7 +657,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
657657
interp_ok(true)
658658
}
659659

660-
fn unaligned_field_offset(
660+
fn field_offset(
661661
&mut self,
662662
instance: ty::Instance<'tcx>,
663663
dest: &PlaceTy<'tcx, M::Provenance>,

compiler/rustc_hir/src/lang_items.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,10 @@ language_item_table! {
443443
CoerceShared, sym::coerce_shared, coerce_shared, Target::Trait, GenericRequirement::Exact(0);
444444

445445
// Experimental lang items for field projections.
446-
Field, sym::Field, field_trait, Target::Trait, GenericRequirement::None;
447-
UnalignedField, sym::UnalignedField, unaligned_field_trait, Target::Trait, GenericRequirement::None;
448-
UnalignedFieldBase, sym::UnalignedFieldBase, unaligned_field_base, Target::AssocTy, GenericRequirement::None;
449-
UnalignedFieldType, sym::UnalignedFieldType, unaligned_field_type, Target::AssocTy, GenericRequirement::None;
450-
UnalignedFieldOFFSET, sym::UnalignedFieldOFFSET, unaligned_field_offset, Target::AssocConst, GenericRequirement::None;
446+
Field, sym::Field, field_trait, Target::Trait, GenericRequirement::None;
447+
FieldBase, sym::FieldBase, field_base, Target::AssocTy, GenericRequirement::None;
448+
FieldType, sym::FieldType, field_type, Target::AssocTy, GenericRequirement::None;
449+
FieldOffset, sym::FieldOffset, field_offset, Target::AssocConst, GenericRequirement::None;
451450
}
452451

453452
/// The requirement imposed on the generics of a lang item

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
116116
| sym::fabsf128
117117
| sym::fadd_algebraic
118118
| sym::fdiv_algebraic
119+
| sym::field_offset
119120
| sym::floorf16
120121
| sym::floorf32
121122
| sym::floorf64
@@ -211,7 +212,6 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
211212
| sym::type_id_eq
212213
| sym::type_name
213214
| sym::ub_checks
214-
| sym::unaligned_field_offset
215215
| sym::variant_count
216216
| sym::wrapping_add
217217
| sym::wrapping_mul
@@ -750,7 +750,7 @@ pub(crate) fn check_intrinsic_type(
750750
| sym::atomic_xor => (2, 1, vec![Ty::new_mut_ptr(tcx, param(0)), param(1)], param(0)),
751751
sym::atomic_fence | sym::atomic_singlethreadfence => (0, 1, Vec::new(), tcx.types.unit),
752752

753-
sym::unaligned_field_offset => (1, 0, Vec::new(), tcx.types.usize),
753+
sym::field_offset => (1, 0, Vec::new(), tcx.types.usize),
754754

755755
other => {
756756
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other });

compiler/rustc_middle/src/ty/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ bidirectional_lang_item_map! {
852852
Sized,
853853
TransmuteTrait,
854854
Tuple,
855-
UnalignedField,
856855
Unpin,
857856
Unsize,
858857
// tidy-alphabetical-end

compiler/rustc_span/src/symbol.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ symbols! {
234234
Err,
235235
Error,
236236
Field,
237+
FieldBase,
238+
FieldOffset,
239+
FieldType,
237240
File,
238241
FileType,
239242
FmtArgumentsNew,
@@ -379,10 +382,6 @@ symbols! {
379382
Ty,
380383
TyCtxt,
381384
TyKind,
382-
UnalignedField,
383-
UnalignedFieldBase,
384-
UnalignedFieldOFFSET,
385-
UnalignedFieldType,
386385
Unknown,
387386
Unsize,
388387
UnsizedConstParamTy,
@@ -1044,6 +1043,7 @@ symbols! {
10441043
field,
10451044
field_init_shorthand,
10461045
field_of,
1046+
field_offset,
10471047
field_projections,
10481048
file,
10491049
file_options,
@@ -2297,7 +2297,6 @@ symbols! {
22972297
u128_legacy_fn_min_value,
22982298
u128_legacy_mod,
22992299
ub_checks,
2300-
unaligned_field_offset,
23012300
unaligned_volatile_load,
23022301
unaligned_volatile_store,
23032302
unboxed_closures,

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
997997
| LangItem::AsyncFn
998998
| LangItem::AsyncFnMut
999999
| LangItem::AsyncFnOnce
1000-
| LangItem::Field
1001-
| LangItem::UnalignedField,
1000+
| LangItem::Field,
10021001
) => true,
10031002
Some(LangItem::AsyncFnKindHelper) => {
10041003
// FIXME(async_closures): Validity constraints here could be cleaned up.
@@ -1556,16 +1555,16 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
15561555
}
15571556
});
15581557
(metadata_ty.into(), obligations)
1559-
} else if tcx.is_lang_item(trait_def_id, LangItem::UnalignedField) {
1558+
} else if tcx.is_lang_item(trait_def_id, LangItem::Field) {
15601559
let &ty::Field(container, field_path) = self_ty.kind() else {
1561-
bug!("only `field_of!()` can implement `UnalignedField`")
1560+
bug!("only `field_of!()` can implement `Field`")
15621561
};
1563-
if tcx.is_lang_item(item_def_id, LangItem::UnalignedFieldBase) {
1562+
if tcx.is_lang_item(item_def_id, LangItem::FieldBase) {
15641563
(container.into(), PredicateObligations::new())
1565-
} else if tcx.is_lang_item(item_def_id, LangItem::UnalignedFieldType) {
1564+
} else if tcx.is_lang_item(item_def_id, LangItem::FieldType) {
15661565
(field_path.field_ty(tcx, container).into(), PredicateObligations::new())
15671566
} else {
1568-
bug!("unexpected associated type {:?} in `UnalignedField`", obligation.predicate);
1567+
bug!("unexpected associated type {:?} in `Field`", obligation.predicate);
15691568
}
15701569
} else {
15711570
bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate);

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
131131
Some(LangItem::Field) => {
132132
self.assemble_builtin_candidates_for_field(obligation, &mut candidates);
133133
}
134-
Some(LangItem::UnalignedField) => {
135-
self.assemble_builtin_candidates_for_unaligned_field(
136-
obligation,
137-
&mut candidates,
138-
);
139-
}
140134
_ => {
141135
// We re-match here for traits that can have both builtin impls and user written impls.
142136
// After the builtin impls we need to also add user written impls, which we do not want to
@@ -1476,15 +1470,4 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14761470
_ => {}
14771471
}
14781472
}
1479-
1480-
fn assemble_builtin_candidates_for_unaligned_field(
1481-
&mut self,
1482-
obligation: &PolyTraitObligation<'tcx>,
1483-
candidates: &mut SelectionCandidateSet<'tcx>,
1484-
) {
1485-
match obligation.predicate.self_ty().skip_binder().kind() {
1486-
ty::Field(_, _) => candidates.vec.push(BuiltinCandidate),
1487-
_ => {}
1488-
}
1489-
}
14901473
}

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
283283
| LangItem::PointeeTrait
284284
| LangItem::Tuple
285285
| LangItem::Unpin
286-
| LangItem::Field
287-
| LangItem::UnalignedField,
286+
| LangItem::Field,
288287
) => ty::Binder::dummy(vec![]),
289288
other => bug!("unexpected builtin trait {trait_def:?} ({other:?})"),
290289
};

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,16 @@ 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::UnalignedField) {
260-
if tcx.is_lang_item(trait_item_id, LangItem::UnalignedFieldOFFSET) {
259+
if tcx.is_lang_item(trait_ref.def_id, LangItem::Field) {
260+
if tcx.is_lang_item(trait_item_id, LangItem::FieldOffset) {
261261
let self_ty = trait_ref.self_ty();
262262
match self_ty.kind() {
263263
ty::Field(_, _) => {}
264264
_ => bug!("expected field representing type, found {self_ty}"),
265265
}
266266
Some(Instance {
267267
def: ty::InstanceKind::Item(
268-
tcx.lang_items().get(LangItem::UnalignedFieldOFFSET).unwrap(),
268+
tcx.lang_items().get(LangItem::FieldOffset).unwrap(),
269269
),
270270
args: rcvr_args,
271271
})

compiler/rustc_type_ir/src/lang_items.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub enum SolverTraitLangItem {
5050
Sized,
5151
TransmuteTrait,
5252
Tuple,
53-
UnalignedField,
5453
Unpin,
5554
Unsize,
5655
// tidy-alphabetical-end

0 commit comments

Comments
 (0)