Skip to content

Commit d05a184

Browse files
committed
remove unaligned & unsized field support from lib & their lang items
1 parent 06c599c commit d05a184

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
@@ -638,7 +638,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
638638
rustc_apfloat::Round::NearestTiesToEven,
639639
)?,
640640

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

643643
// Unsupported intrinsic: skip the return_to_block below.
644644
_ => return interp_ok(false),
@@ -649,7 +649,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
649649
interp_ok(true)
650650
}
651651

652-
fn unaligned_field_offset(
652+
fn field_offset(
653653
&mut self,
654654
instance: ty::Instance<'tcx>,
655655
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
@@ -442,11 +442,10 @@ language_item_table! {
442442
Reborrow, sym::reborrow, reborrow, Target::Trait, GenericRequirement::Exact(0);
443443

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

452451
/// 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
@@ -141,7 +141,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
141141
| sym::prefetch_read_instruction
142142
| sym::prefetch_write_instruction
143143
| sym::const_eval_select
144-
| sym::unaligned_field_offset => hir::Safety::Safe,
144+
| sym::field_offset => hir::Safety::Safe,
145145
_ => hir::Safety::Unsafe,
146146
};
147147

@@ -674,7 +674,7 @@ pub(crate) fn check_intrinsic_type(
674674
| sym::atomic_xor => (2, 1, vec![Ty::new_mut_ptr(tcx, param(0)), param(1)], param(0)),
675675
sym::atomic_fence | sym::atomic_singlethreadfence => (0, 1, Vec::new(), tcx.types.unit),
676676

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

679679
other => {
680680
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,
@@ -1041,6 +1040,7 @@ symbols! {
10411040
field,
10421041
field_init_shorthand,
10431042
field_of,
1043+
field_offset,
10441044
field_projections,
10451045
file,
10461046
file_options,
@@ -2289,7 +2289,6 @@ symbols! {
22892289
u128_legacy_fn_min_value,
22902290
u128_legacy_mod,
22912291
ub_checks,
2292-
unaligned_field_offset,
22932292
unaligned_volatile_load,
22942293
unaligned_volatile_store,
22952294
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.
@@ -1555,16 +1554,16 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
15551554
}
15561555
});
15571556
(metadata_ty.into(), obligations)
1558-
} else if tcx.is_lang_item(trait_def_id, LangItem::UnalignedField) {
1557+
} else if tcx.is_lang_item(trait_def_id, LangItem::Field) {
15591558
let &ty::Field(container, field_path) = self_ty.kind() else {
1560-
bug!("only `field_of!()` can implement `UnalignedField`")
1559+
bug!("only `field_of!()` can implement `Field`")
15611560
};
1562-
if tcx.is_lang_item(item_def_id, LangItem::UnalignedFieldBase) {
1561+
if tcx.is_lang_item(item_def_id, LangItem::FieldBase) {
15631562
(container.into(), PredicateObligations::new())
1564-
} else if tcx.is_lang_item(item_def_id, LangItem::UnalignedFieldType) {
1563+
} else if tcx.is_lang_item(item_def_id, LangItem::FieldType) {
15651564
(field_path.field_ty(tcx, container).into(), PredicateObligations::new())
15661565
} else {
1567-
bug!("unexpected associated type {:?} in `UnalignedField`", obligation.predicate);
1566+
bug!("unexpected associated type {:?} in `Field`", obligation.predicate);
15681567
}
15691568
} else {
15701569
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)