Skip to content

Commit a26a420

Browse files
redact coerced type away
1 parent aea5595 commit a26a420

File tree

10 files changed

+423
-70
lines changed

10 files changed

+423
-70
lines changed

compiler/rustc_codegen_cranelift/example/mini_core.rs

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ pub trait Unsize<T: ?Sized> {}
2929
#[lang = "coerce_unsized"]
3030
pub trait CoerceUnsized<T> {}
3131

32+
#[lang = "coerce_pointee_validated"]
33+
pub trait CoercePointeeValidated {
34+
/* compiler built-in */
35+
#[lang = "coerce_pointee_validated_pointee"]
36+
type Pointee: ?Sized;
37+
}
38+
3239
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
3340
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
3441
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}

compiler/rustc_codegen_gcc/example/mini_core.rs

+39-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#![feature(
2-
no_core, lang_items, intrinsics, unboxed_closures, extern_types,
3-
decl_macro, rustc_attrs, transparent_unions, auto_traits, freeze_impls,
2+
no_core,
3+
lang_items,
4+
intrinsics,
5+
unboxed_closures,
6+
extern_types,
7+
decl_macro,
8+
rustc_attrs,
9+
transparent_unions,
10+
auto_traits,
11+
freeze_impls,
412
thread_local
513
)]
614
#![no_core]
@@ -26,6 +34,13 @@ pub trait Unsize<T: ?Sized> {}
2634
#[lang = "coerce_unsized"]
2735
pub trait CoerceUnsized<T> {}
2836

37+
#[lang = "coerce_pointee_validated"]
38+
pub trait CoercePointeeValidated {
39+
/* compiler built-in */
40+
#[lang = "coerce_pointee_validated_pointee"]
41+
type Pointee: ?Sized;
42+
}
43+
2944
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
3045
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
3146
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
@@ -35,13 +50,13 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
3550
pub trait DispatchFromDyn<T> {}
3651

3752
// &T -> &U
38-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
53+
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
3954
// &mut T -> &mut U
40-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
55+
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4156
// *const T -> *const U
42-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
57+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
4358
// *mut T -> *mut U
44-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
59+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
4560
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
4661

4762
#[lang = "legacy_receiver"]
@@ -289,7 +304,6 @@ impl PartialEq for u32 {
289304
}
290305
}
291306

292-
293307
impl PartialEq for u64 {
294308
fn eq(&self, other: &u64) -> bool {
295309
(*self) == (*other)
@@ -476,7 +490,11 @@ fn panic_in_cleanup() -> ! {
476490
#[track_caller]
477491
fn panic_bounds_check(index: usize, len: usize) -> ! {
478492
unsafe {
479-
libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
493+
libc::printf(
494+
"index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8,
495+
len,
496+
index,
497+
);
480498
intrinsics::abort();
481499
}
482500
}
@@ -504,8 +522,7 @@ pub trait Deref {
504522
fn deref(&self) -> &Self::Target;
505523
}
506524

507-
pub trait Allocator {
508-
}
525+
pub trait Allocator {}
509526

510527
impl Allocator for () {}
511528

@@ -699,19 +716,27 @@ pub struct VaList<'a>(&'a mut VaListImpl);
699716

700717
#[rustc_builtin_macro]
701718
#[rustc_macro_transparency = "semitransparent"]
702-
pub macro stringify($($t:tt)*) { /* compiler built-in */ }
719+
pub macro stringify($($t:tt)*) {
720+
/* compiler built-in */
721+
}
703722

704723
#[rustc_builtin_macro]
705724
#[rustc_macro_transparency = "semitransparent"]
706-
pub macro file() { /* compiler built-in */ }
725+
pub macro file() {
726+
/* compiler built-in */
727+
}
707728

708729
#[rustc_builtin_macro]
709730
#[rustc_macro_transparency = "semitransparent"]
710-
pub macro line() { /* compiler built-in */ }
731+
pub macro line() {
732+
/* compiler built-in */
733+
}
711734

712735
#[rustc_builtin_macro]
713736
#[rustc_macro_transparency = "semitransparent"]
714-
pub macro cfg() { /* compiler built-in */ }
737+
pub macro cfg() {
738+
/* compiler built-in */
739+
}
715740

716741
pub static A_STATIC: u8 = 42;
717742

compiler/rustc_hir_analysis/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ hir_analysis_cmse_output_stack_spill =
8585
.note1 = functions with the `"{$abi_name}"` ABI must pass their result via the available return registers
8686
.note2 = the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
8787
88+
hir_analysis_coerce_pointee_multiple_targets = `derive(CoercePointee)` only admits exactly one data field, {$diag_trait ->
89+
[DispatchFromDyn] to which `dyn` methods shall be dispatched
90+
*[CoerceUnsized] on which unsize coercion shall be performed
91+
}
92+
8893
hir_analysis_coerce_pointee_no_field = `CoercePointee` can only be derived on `struct`s with at least one field
8994
9095
hir_analysis_coerce_pointee_no_user_validity_assertion = asserting applicability of `derive(CoercePointee)` on a target data is forbidden

0 commit comments

Comments
 (0)