Skip to content

Commit 3cfac9d

Browse files
authored
Unrolled build for #143308
Rollup merge of #143308 - compiler-errors:no-pointer-like, r=oli-obk Remove `PointerLike` trait r? oli-obk
2 parents 556d20a + e2e3f58 commit 3cfac9d

File tree

14 files changed

+14
-288
lines changed

14 files changed

+14
-288
lines changed

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_macros::HashStable_Generic;
66

77
use crate::{
88
AbiAlign, Align, BackendRepr, FieldsShape, Float, HasDataLayout, LayoutData, Niche,
9-
PointeeInfo, Primitive, Scalar, Size, TargetDataLayout, Variants,
9+
PointeeInfo, Primitive, Size, Variants,
1010
};
1111

1212
// Explicitly import `Float` to avoid ambiguity with `Primitive::Float`.
@@ -115,16 +115,6 @@ impl<'a> Layout<'a> {
115115
pub fn unadjusted_abi_align(self) -> Align {
116116
self.0.0.unadjusted_abi_align
117117
}
118-
119-
/// Whether the layout is from a type that implements [`std::marker::PointerLike`].
120-
///
121-
/// Currently, that means that the type is pointer-sized, pointer-aligned,
122-
/// and has a initialized (non-union), scalar ABI.
123-
pub fn is_pointer_like(self, data_layout: &TargetDataLayout) -> bool {
124-
self.size() == data_layout.pointer_size
125-
&& self.align().abi == data_layout.pointer_align.abi
126-
&& matches!(self.backend_repr(), BackendRepr::Scalar(Scalar::Initialized { .. }))
127-
}
128118
}
129119

130120
/// The layout of a type, alongside the type itself.

compiler/rustc_hir/src/lang_items.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,6 @@ language_item_table! {
367367
TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
368368
TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None;
369369

370-
PointerLike, sym::pointer_like, pointer_like, Target::Trait, GenericRequirement::Exact(0);
371-
372370
CoercePointeeValidated, sym::coerce_pointee_validated, coerce_pointee_validated_trait, Target::Trait, GenericRequirement::Exact(0);
373371

374372
ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub(super) fn check_trait<'tcx>(
4747
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized)?;
4848
checker
4949
.check(lang_items.dispatch_from_dyn_trait(), visit_implementation_of_dispatch_from_dyn)?;
50-
checker.check(lang_items.pointer_like(), visit_implementation_of_pointer_like)?;
5150
checker.check(
5251
lang_items.coerce_pointee_validated_trait(),
5352
visit_implementation_of_coerce_pointee_validity,
@@ -707,104 +706,6 @@ fn infringing_fields_error<'tcx>(
707706
err.emit()
708707
}
709708

710-
fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
711-
let tcx = checker.tcx;
712-
let typing_env = ty::TypingEnv::non_body_analysis(tcx, checker.impl_def_id);
713-
let impl_span = tcx.def_span(checker.impl_def_id);
714-
let self_ty = tcx.impl_trait_ref(checker.impl_def_id).unwrap().instantiate_identity().self_ty();
715-
716-
let is_permitted_primitive = match *self_ty.kind() {
717-
ty::Adt(def, _) => def.is_box(),
718-
ty::Uint(..) | ty::Int(..) | ty::RawPtr(..) | ty::Ref(..) | ty::FnPtr(..) => true,
719-
_ => false,
720-
};
721-
722-
if is_permitted_primitive
723-
&& let Ok(layout) = tcx.layout_of(typing_env.as_query_input(self_ty))
724-
&& layout.layout.is_pointer_like(&tcx.data_layout)
725-
{
726-
return Ok(());
727-
}
728-
729-
let why_disqualified = match *self_ty.kind() {
730-
// If an ADT is repr(transparent)
731-
ty::Adt(self_ty_def, args) => {
732-
if self_ty_def.repr().transparent() {
733-
// FIXME(compiler-errors): This should and could be deduplicated into a query.
734-
// Find the nontrivial field.
735-
let adt_typing_env = ty::TypingEnv::non_body_analysis(tcx, self_ty_def.did());
736-
let nontrivial_field = self_ty_def.all_fields().find(|field_def| {
737-
let field_ty = tcx.type_of(field_def.did).instantiate_identity();
738-
!tcx.layout_of(adt_typing_env.as_query_input(field_ty))
739-
.is_ok_and(|layout| layout.layout.is_1zst())
740-
});
741-
742-
if let Some(nontrivial_field) = nontrivial_field {
743-
// Check that the nontrivial field implements `PointerLike`.
744-
let nontrivial_field_ty = nontrivial_field.ty(tcx, args);
745-
let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
746-
let ocx = ObligationCtxt::new(&infcx);
747-
ocx.register_bound(
748-
ObligationCause::misc(impl_span, checker.impl_def_id),
749-
param_env,
750-
nontrivial_field_ty,
751-
tcx.require_lang_item(LangItem::PointerLike, impl_span),
752-
);
753-
// FIXME(dyn-star): We should regionck this implementation.
754-
if ocx.select_all_or_error().is_empty() {
755-
return Ok(());
756-
} else {
757-
format!(
758-
"the field `{field_name}` of {descr} `{self_ty}` \
759-
does not implement `PointerLike`",
760-
field_name = nontrivial_field.name,
761-
descr = self_ty_def.descr()
762-
)
763-
}
764-
} else {
765-
format!(
766-
"the {descr} `{self_ty}` is `repr(transparent)`, \
767-
but does not have a non-trivial field (it is zero-sized)",
768-
descr = self_ty_def.descr()
769-
)
770-
}
771-
} else if self_ty_def.is_box() {
772-
// If we got here, then the `layout.is_pointer_like()` check failed
773-
// and this box is not a thin pointer.
774-
775-
String::from("boxes of dynamically-sized types are too large to be `PointerLike`")
776-
} else {
777-
format!(
778-
"the {descr} `{self_ty}` is not `repr(transparent)`",
779-
descr = self_ty_def.descr()
780-
)
781-
}
782-
}
783-
ty::Ref(..) => {
784-
// If we got here, then the `layout.is_pointer_like()` check failed
785-
// and this reference is not a thin pointer.
786-
String::from("references to dynamically-sized types are too large to be `PointerLike`")
787-
}
788-
ty::Dynamic(..) | ty::Foreign(..) => {
789-
String::from("types of dynamic or unknown size may not implement `PointerLike`")
790-
}
791-
_ => {
792-
// This is a white lie; it is true everywhere outside the standard library.
793-
format!("only user-defined sized types are eligible for `impl PointerLike`")
794-
}
795-
};
796-
797-
Err(tcx
798-
.dcx()
799-
.struct_span_err(
800-
impl_span,
801-
"implementation must be applied to type that has the same ABI as a pointer, \
802-
or is `repr(transparent)` and whose field is `PointerLike`",
803-
)
804-
.with_note(why_disqualified)
805-
.emit())
806-
}
807-
808709
fn visit_implementation_of_coerce_pointee_validity(
809710
checker: &Checker<'_>,
810711
) -> Result<(), ErrorGuaranteed> {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,12 +1149,16 @@ impl<'tcx> TypingEnv<'tcx> {
11491149
{
11501150
// FIXME(#132279): We should assert that the value does not contain any placeholders
11511151
// as these placeholders are also local to the current inference context. However, we
1152-
// currently use pseudo-canonical queries in the trait solver which replaces params with
1153-
// placeholders. We should also simply not use pseudo-canonical queries in the trait
1154-
// solver, at which point we can readd this assert. As of writing this comment, this is
1155-
// only used by `fn layout_is_pointer_like` when calling `layout_of`.
1152+
// currently use pseudo-canonical queries in the trait solver, which replaces params
1153+
// with placeholders during canonicalization. We should also simply not use pseudo-
1154+
// canonical queries in the trait solver, at which point we can readd this assert.
11561155
//
1157-
// debug_assert!(!value.has_placeholders());
1156+
// As of writing this comment, this is only used when normalizing consts that mention
1157+
// params.
1158+
/* debug_assert!(
1159+
!value.has_placeholders(),
1160+
"{value:?} which has placeholder shouldn't be pseudo-canonicalized"
1161+
); */
11581162
PseudoCanonicalInput { typing_env: self, value }
11591163
}
11601164
}

compiler/rustc_span/src/symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,6 @@ symbols! {
16231623
pointee_sized,
16241624
pointee_trait,
16251625
pointer,
1626-
pointer_like,
16271626
poll,
16281627
poll_next,
16291628
position,

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

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ use rustc_hir::lang_items::LangItem;
1414
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk};
1515
use rustc_infer::traits::ObligationCauseCode;
1616
use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
17-
use rustc_middle::ty::{
18-
self, GenericArgsRef, Region, SizedTraitKind, Ty, TyCtxt, Upcast, elaborate,
19-
};
17+
use rustc_middle::ty::{self, GenericArgsRef, Region, SizedTraitKind, Ty, TyCtxt, Upcast};
2018
use rustc_middle::{bug, span_bug};
2119
use rustc_span::def_id::DefId;
2220
use thin_vec::thin_vec;
@@ -1147,38 +1145,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11471145
ty::ClauseKind::TypeOutlives(outlives).upcast(tcx),
11481146
));
11491147

1150-
// Require that all AFIT will return something that can be coerced into `dyn*`
1151-
// -- a shim will be responsible for doing the actual coercion to `dyn*`.
1152-
if let Some(principal) = data.principal() {
1153-
for supertrait in
1154-
elaborate::supertraits(tcx, principal.with_self_ty(tcx, source))
1155-
{
1156-
if tcx.is_trait_alias(supertrait.def_id()) {
1157-
continue;
1158-
}
1159-
1160-
for &assoc_item in tcx.associated_item_def_ids(supertrait.def_id()) {
1161-
if !tcx.is_impl_trait_in_trait(assoc_item) {
1162-
continue;
1163-
}
1164-
1165-
// RPITITs with `Self: Sized` don't need to be checked.
1166-
if tcx.generics_require_sized_self(assoc_item) {
1167-
continue;
1168-
}
1169-
1170-
let pointer_like_goal = pointer_like_goal_for_rpitit(
1171-
tcx,
1172-
supertrait,
1173-
assoc_item,
1174-
&obligation.cause,
1175-
);
1176-
1177-
nested.push(predicate_to_obligation(pointer_like_goal.upcast(tcx)));
1178-
}
1179-
}
1180-
}
1181-
11821148
ImplSource::Builtin(BuiltinImplSource::Misc, nested)
11831149
}
11841150

@@ -1344,46 +1310,3 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13441310
ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
13451311
}
13461312
}
1347-
1348-
/// Compute a goal that some RPITIT (right now, only RPITITs corresponding to Futures)
1349-
/// implements the `PointerLike` trait, which is a requirement for the RPITIT to be
1350-
/// coercible to `dyn* Future`, which is itself a requirement for the RPITIT's parent
1351-
/// trait to be coercible to `dyn Trait`.
1352-
///
1353-
/// We do this given a supertrait's substitutions, and then augment the substitutions
1354-
/// with bound variables to compute the goal universally. Given that `PointerLike` has
1355-
/// no region requirements (at least for the built-in pointer types), this shouldn't
1356-
/// *really* matter, but it is the best choice for soundness.
1357-
fn pointer_like_goal_for_rpitit<'tcx>(
1358-
tcx: TyCtxt<'tcx>,
1359-
supertrait: ty::PolyTraitRef<'tcx>,
1360-
rpitit_item: DefId,
1361-
cause: &ObligationCause<'tcx>,
1362-
) -> ty::PolyTraitRef<'tcx> {
1363-
let mut bound_vars = supertrait.bound_vars().to_vec();
1364-
1365-
let args = supertrait.skip_binder().args.extend_to(tcx, rpitit_item, |arg, _| match arg.kind {
1366-
ty::GenericParamDefKind::Lifetime => {
1367-
let kind = ty::BoundRegionKind::Named(arg.def_id, tcx.item_name(arg.def_id));
1368-
bound_vars.push(ty::BoundVariableKind::Region(kind));
1369-
ty::Region::new_bound(
1370-
tcx,
1371-
ty::INNERMOST,
1372-
ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
1373-
)
1374-
.into()
1375-
}
1376-
ty::GenericParamDefKind::Type { .. } | ty::GenericParamDefKind::Const { .. } => {
1377-
unreachable!()
1378-
}
1379-
});
1380-
1381-
ty::Binder::bind_with_vars(
1382-
ty::TraitRef::new(
1383-
tcx,
1384-
tcx.require_lang_item(LangItem::PointerLike, cause.span),
1385-
[Ty::new_projection_from_args(tcx, rpitit_item, args)],
1386-
),
1387-
tcx.mk_bound_variable_kinds(&bound_vars),
1388-
)
1389-
}

library/alloc/src/boxed.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ use core::error::{self, Error};
191191
use core::fmt;
192192
use core::future::Future;
193193
use core::hash::{Hash, Hasher};
194-
use core::marker::{PointerLike, Tuple, Unsize};
194+
use core::marker::{Tuple, Unsize};
195195
use core::mem::{self, SizedTypeProperties};
196196
use core::ops::{
197197
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
@@ -2132,6 +2132,3 @@ impl<E: Error> Error for Box<E> {
21322132
Error::provide(&**self, request);
21332133
}
21342134
}
2135-
2136-
#[unstable(feature = "pointer_like_trait", issue = "none")]
2137-
impl<T> PointerLike for Box<T> {}

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
#![feature(panic_internals)]
135135
#![feature(pattern)]
136136
#![feature(pin_coerce_unsized_trait)]
137-
#![feature(pointer_like_trait)]
138137
#![feature(ptr_alignment_type)]
139138
#![feature(ptr_internals)]
140139
#![feature(ptr_metadata)]

library/core/src/cell.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252

253253
use crate::cmp::Ordering;
254254
use crate::fmt::{self, Debug, Display};
255-
use crate::marker::{PhantomData, PointerLike, Unsize};
255+
use crate::marker::{PhantomData, Unsize};
256256
use crate::mem;
257257
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn};
258258
use crate::panic::const_panic;
@@ -669,9 +669,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
669669
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
670670
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {}
671671

672-
#[unstable(feature = "pointer_like_trait", issue = "none")]
673-
impl<T: PointerLike> PointerLike for Cell<T> {}
674-
675672
impl<T> Cell<[T]> {
676673
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
677674
///
@@ -2361,9 +2358,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
23612358
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
23622359
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
23632360

2364-
#[unstable(feature = "pointer_like_trait", issue = "none")]
2365-
impl<T: PointerLike> PointerLike for UnsafeCell<T> {}
2366-
23672361
/// [`UnsafeCell`], but [`Sync`].
23682362
///
23692363
/// This is just an `UnsafeCell`, except it implements `Sync`
@@ -2470,9 +2464,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell
24702464
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
24712465
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
24722466

2473-
#[unstable(feature = "pointer_like_trait", issue = "none")]
2474-
impl<T: PointerLike> PointerLike for SyncUnsafeCell<T> {}
2475-
24762467
#[allow(unused)]
24772468
fn assert_coerce_unsized(
24782469
a: UnsafeCell<&i32>,

library/core/src/marker.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,37 +1066,6 @@ pub trait Destruct {}
10661066
#[rustc_do_not_implement_via_object]
10671067
pub trait Tuple {}
10681068

1069-
/// A marker for pointer-like types.
1070-
///
1071-
/// This trait can only be implemented for types that are certain to have
1072-
/// the same size and alignment as a [`usize`] or [`*const ()`](pointer).
1073-
/// To ensure this, there are special requirements on implementations
1074-
/// of `PointerLike` (other than the already-provided implementations
1075-
/// for built-in types):
1076-
///
1077-
/// * The type must have `#[repr(transparent)]`.
1078-
/// * The type’s sole non-zero-sized field must itself implement `PointerLike`.
1079-
#[unstable(feature = "pointer_like_trait", issue = "none")]
1080-
#[lang = "pointer_like"]
1081-
#[diagnostic::on_unimplemented(
1082-
message = "`{Self}` needs to have the same ABI as a pointer",
1083-
label = "`{Self}` needs to be a pointer-like type"
1084-
)]
1085-
#[rustc_do_not_implement_via_object]
1086-
pub trait PointerLike {}
1087-
1088-
marker_impls! {
1089-
#[unstable(feature = "pointer_like_trait", issue = "none")]
1090-
PointerLike for
1091-
isize,
1092-
usize,
1093-
{T} &T,
1094-
{T} &mut T,
1095-
{T} *const T,
1096-
{T} *mut T,
1097-
{T: PointerLike} crate::pin::Pin<T>,
1098-
}
1099-
11001069
/// A marker for types which can be used as types of `const` generic parameters.
11011070
///
11021071
/// These types must have a proper equivalence relation (`Eq`) and it must be automatically

library/core/src/pin/unsafe_pinned.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::cell::UnsafeCell;
2-
use crate::marker::{PointerLike, Unpin};
2+
use crate::marker::Unpin;
33
use crate::ops::{CoerceUnsized, DispatchFromDyn};
44
use crate::pin::Pin;
55
use crate::{fmt, ptr};
@@ -178,8 +178,4 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafePinned<U>> for UnsafePinned<T>
178178
// #[unstable(feature = "unsafe_pinned", issue = "125735")]
179179
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafePinned<U>> for UnsafePinned<T> {}
180180

181-
#[unstable(feature = "pointer_like_trait", issue = "none")]
182-
// #[unstable(feature = "unsafe_pinned", issue = "125735")]
183-
impl<T: PointerLike> PointerLike for UnsafePinned<T> {}
184-
185181
// FIXME(unsafe_pinned): impl PinCoerceUnsized for UnsafePinned<T>?

0 commit comments

Comments
 (0)