Skip to content

Commit 7ae3ccf

Browse files
authored
Rollup merge of rust-lang#107769 - compiler-errors:pointer-like, r=eholk
Rename `PointerSized` to `PointerLike` The old name was unnecessarily vague. This PR renames a nightly language feature that I added, so I don't think it needs any additional approval, though anyone can feel free to speak up if you dislike the rename. It's still unsatisfying that we don't the user which of {size, alignment} is wrong, but this trait really is just a stepping stone for a more generalized mechanism to create `dyn*`, just meant for nightly testing, so I don't think it really deserves additional diagnostic machinery for now. Fixes rust-lang#107696, cc `@RalfJung` r? `@eholk`
2 parents 6f660c9 + 2b70cbb commit 7ae3ccf

20 files changed

+73
-70
lines changed

compiler/rustc_const_eval/src/interpret/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
126126
let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
127127
let vtable = Scalar::from_maybe_pointer(vtable, self);
128128
let data = self.read_immediate(src)?.to_scalar();
129-
let _assert_pointer_sized = data.to_pointer(self)?;
129+
let _assert_pointer_like = data.to_pointer(self)?;
130130
let val = Immediate::ScalarPair(data, vtable);
131131
self.write_immediate(val, dest)?;
132132
} else {

compiler/rustc_hir/src/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ language_item_table! {
287287
TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
288288
TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None;
289289

290-
PointerSized, sym::pointer_sized, pointer_sized, Target::Trait, GenericRequirement::Exact(0);
290+
PointerLike, sym::pointer_like, pointer_like, Target::Trait, GenericRequirement::Exact(0);
291291

292292
Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;
293293
PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
765765
self.cause.clone(),
766766
self.param_env,
767767
ty::Binder::dummy(
768-
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerSized, [a]),
768+
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerLike, [a]),
769769
),
770770
));
771771

compiler/rustc_span/src/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ symbols! {
10841084
plugins,
10851085
pointee_trait,
10861086
pointer,
1087-
pointer_sized,
1087+
pointer_like,
10881088
poll,
10891089
position,
10901090
post_dash_lto: "post-lto",

compiler/rustc_trait_selection/src/solve/assembly.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
128128
goal: Goal<'tcx, Self>,
129129
) -> QueryResult<'tcx>;
130130

131-
// A type is `PointerSized` if we can compute its layout, and that layout
131+
// A type is `PointerLike` if we can compute its layout, and that layout
132132
// matches the layout of `usize`.
133-
fn consider_builtin_pointer_sized_candidate(
133+
fn consider_builtin_pointer_like_candidate(
134134
ecx: &mut EvalCtxt<'_, 'tcx>,
135135
goal: Goal<'tcx, Self>,
136136
) -> QueryResult<'tcx>;
@@ -312,8 +312,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
312312
|| lang_items.clone_trait() == Some(trait_def_id)
313313
{
314314
G::consider_builtin_copy_clone_candidate(self, goal)
315-
} else if lang_items.pointer_sized() == Some(trait_def_id) {
316-
G::consider_builtin_pointer_sized_candidate(self, goal)
315+
} else if lang_items.pointer_like() == Some(trait_def_id) {
316+
G::consider_builtin_pointer_like_candidate(self, goal)
317317
} else if let Some(kind) = self.tcx().fn_trait_kind_from_def_id(trait_def_id) {
318318
G::consider_builtin_fn_trait_candidates(self, goal, kind)
319319
} else if lang_items.tuple_trait() == Some(trait_def_id) {

compiler/rustc_trait_selection/src/solve/project_goals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
370370
bug!("`Copy`/`Clone` does not have an associated type: {:?}", goal);
371371
}
372372

373-
fn consider_builtin_pointer_sized_candidate(
373+
fn consider_builtin_pointer_like_candidate(
374374
_ecx: &mut EvalCtxt<'_, 'tcx>,
375375
goal: Goal<'tcx, Self>,
376376
) -> QueryResult<'tcx> {
377-
bug!("`PointerSized` does not have an associated type: {:?}", goal);
377+
bug!("`PointerLike` does not have an associated type: {:?}", goal);
378378
}
379379

380380
fn consider_builtin_fn_trait_candidates(

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
131131
)
132132
}
133133

134-
fn consider_builtin_pointer_sized_candidate(
134+
fn consider_builtin_pointer_like_candidate(
135135
ecx: &mut EvalCtxt<'_, 'tcx>,
136136
goal: Goal<'tcx, Self>,
137137
) -> QueryResult<'tcx> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
9494
self.assemble_candidates_for_transmutability(obligation, &mut candidates);
9595
} else if lang_items.tuple_trait() == Some(def_id) {
9696
self.assemble_candidate_for_tuple(obligation, &mut candidates);
97-
} else if lang_items.pointer_sized() == Some(def_id) {
97+
} else if lang_items.pointer_like() == Some(def_id) {
9898
self.assemble_candidate_for_ptr_sized(obligation, &mut candidates);
9999
} else {
100100
if lang_items.clone_trait() == Some(def_id) {

library/core/src/marker.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,14 @@ pub trait Destruct {}
872872
pub trait Tuple {}
873873

874874
/// A marker for things
875-
#[unstable(feature = "pointer_sized_trait", issue = "none")]
876-
#[lang = "pointer_sized"]
875+
#[unstable(feature = "pointer_like_trait", issue = "none")]
876+
#[cfg_attr(bootstrap, lang = "pointer_sized")]
877+
#[cfg_attr(not(bootstrap), lang = "pointer_like")]
877878
#[rustc_on_unimplemented(
878-
message = "`{Self}` needs to be a pointer-sized type",
879-
label = "`{Self}` needs to be a pointer-sized type"
879+
message = "`{Self}` needs to have the same alignment and size as a pointer",
880+
label = "`{Self}` needs to be a pointer-like type"
880881
)]
881-
pub trait PointerSized {}
882+
pub trait PointerLike {}
882883

883884
/// Implementations of `Copy` for primitive types.
884885
///

tests/ui/dyn-star/align.over_aligned.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ LL | #![feature(dyn_star)]
77
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error[E0277]: `AlignedUsize` needs to be a pointer-sized type
10+
error[E0277]: `AlignedUsize` needs to have the same alignment and size as a pointer
1111
--> $DIR/align.rs:15:13
1212
|
1313
LL | let x = AlignedUsize(12) as dyn* Debug;
14-
| ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-sized type
14+
| ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-like type
1515
|
16-
= help: the trait `PointerSized` is not implemented for `AlignedUsize`
16+
= help: the trait `PointerLike` is not implemented for `AlignedUsize`
1717

1818
error: aborting due to previous error; 1 warning emitted
1919

tests/ui/dyn-star/align.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ struct AlignedUsize(usize);
1313

1414
fn main() {
1515
let x = AlignedUsize(12) as dyn* Debug;
16-
//[over_aligned]~^ ERROR `AlignedUsize` needs to be a pointer-sized type
16+
//[over_aligned]~^ ERROR `AlignedUsize` needs to have the same alignment and size as a pointer
1717
}

tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn dyn_debug(_: (dyn* Debug + '_)) {
99

1010
fn polymorphic<T: Debug + ?Sized>(t: &T) {
1111
dyn_debug(t);
12-
//~^ ERROR `&T` needs to be a pointer-sized type
12+
//~^ ERROR `&T` needs to have the same alignment and size as a pointer
1313
}
1414

1515
fn main() {}

tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0277]: `&T` needs to be a pointer-sized type
1+
error[E0277]: `&T` needs to have the same alignment and size as a pointer
22
--> $DIR/check-size-at-cast-polymorphic-bad.rs:11:15
33
|
44
LL | dyn_debug(t);
5-
| ^ `&T` needs to be a pointer-sized type
5+
| ^ `&T` needs to be a pointer-like type
66
|
7-
= help: the trait `PointerSized` is not implemented for `&T`
7+
= help: the trait `PointerLike` is not implemented for `&T`
88
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
99
|
10-
LL | fn polymorphic<T: Debug + ?Sized>(t: &T) where &T: PointerSized {
11-
| ++++++++++++++++++++++
10+
LL | fn polymorphic<T: Debug + ?Sized>(t: &T) where &T: PointerLike {
11+
| +++++++++++++++++++++
1212

1313
error: aborting due to previous error
1414

tests/ui/dyn-star/check-size-at-cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ use std::fmt::Debug;
55

66
fn main() {
77
let i = [1, 2, 3, 4] as dyn* Debug;
8-
//~^ ERROR `[i32; 4]` needs to be a pointer-sized type
8+
//~^ ERROR `[i32; 4]` needs to have the same alignment and size as a pointer
99
dbg!(i);
1010
}

tests/ui/dyn-star/check-size-at-cast.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0277]: `[i32; 4]` needs to be a pointer-sized type
1+
error[E0277]: `[i32; 4]` needs to have the same alignment and size as a pointer
22
--> $DIR/check-size-at-cast.rs:7:13
33
|
44
LL | let i = [1, 2, 3, 4] as dyn* Debug;
5-
| ^^^^^^^^^^^^ `[i32; 4]` needs to be a pointer-sized type
5+
| ^^^^^^^^^^^^ `[i32; 4]` needs to be a pointer-like type
66
|
7-
= help: the trait `PointerSized` is not implemented for `[i32; 4]`
7+
= help: the trait `PointerLike` is not implemented for `[i32; 4]`
88

99
error: aborting due to previous error
1010

tests/ui/dyn-star/upcast.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ LL | #![feature(dyn_star, trait_upcasting)]
77
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error[E0277]: `dyn* Foo` needs to be a pointer-sized type
10+
error[E0277]: `dyn* Foo` needs to have the same alignment and size as a pointer
1111
--> $DIR/upcast.rs:30:23
1212
|
1313
LL | let w: dyn* Bar = w;
14-
| ^ `dyn* Foo` needs to be a pointer-sized type
14+
| ^ `dyn* Foo` needs to be a pointer-like type
1515
|
16-
= help: the trait `PointerSized` is not implemented for `dyn* Foo`
16+
= help: the trait `PointerLike` is not implemented for `dyn* Foo`
1717

1818
error: aborting due to previous error; 1 warning emitted
1919

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
#![feature(pointer_like_trait)]
4+
5+
use std::marker::PointerLike;
6+
7+
fn require_(_: impl PointerLike) {}
8+
9+
fn main() {
10+
require_(1usize);
11+
require_(1u16);
12+
//~^ ERROR `u16` needs to have the same alignment and size as a pointer
13+
require_(&1i16);
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0277]: `u16` needs to have the same alignment and size as a pointer
2+
--> $DIR/pointer-like.rs:11:14
3+
|
4+
LL | require_(1u16);
5+
| -------- ^^^^ the trait `PointerLike` is not implemented for `u16`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= note: the trait bound `u16: PointerLike` is not satisfied
10+
note: required by a bound in `require_`
11+
--> $DIR/pointer-like.rs:7:21
12+
|
13+
LL | fn require_(_: impl PointerLike) {}
14+
| ^^^^^^^^^^^ required by this bound in `require_`
15+
help: consider borrowing here
16+
|
17+
LL | require_(&1u16);
18+
| +
19+
LL | require_(&mut 1u16);
20+
| ++++
21+
22+
error: aborting due to previous error
23+
24+
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/new-solver/pointer-sized.rs

-12
This file was deleted.

tests/ui/traits/new-solver/pointer-sized.stderr

-24
This file was deleted.

0 commit comments

Comments
 (0)