about summary refs log tree commit diff
path: root/compiler/rustc_error_codes/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-02-11 05:27:49 +0000
committerbors <bors@rust-lang.org>2025-02-11 05:27:49 +0000
commitc182ce9cbc8c29ebc1b4559d027df545e6cdd287 (patch)
treea17345e81cf8c0c3db94f827c36b395ebb6ff245 /compiler/rustc_error_codes/src
parentffa9afef183a3496a277c8da2e61403582a99508 (diff)
parent5a44f78269717a926cfab6549ce0b4f323e27d63 (diff)
downloadrust-c182ce9cbc8c29ebc1b4559d027df545e6cdd287.tar.gz
rust-c182ce9cbc8c29ebc1b4559d027df545e6cdd287.zip
Auto merge of #136845 - matthiaskrgr:rollup-ol4np4z, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #136107 (Introduce CoercePointeeWellformed for coherence checks at typeck stage)
 - #136155 (Enable sanitizers on MSVC CI jobs)
 - #136524 (Delay bug when method confirmation cannot upcast object pick of self)
 - #136584 (Prevent generic pattern types from being used in libstd)
 - #136603 (compiler: gate `extern "{abi}"` in ast_lowering)
 - #136821 (assign marcoieni and jdno to infra-ci PRs)
 - #136825 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_error_codes/src')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0802.md94
-rw-r--r--compiler/rustc_error_codes/src/lib.rs1
2 files changed, 95 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0802.md b/compiler/rustc_error_codes/src/error_codes/E0802.md
new file mode 100644
index 00000000000..59061ff0435
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0802.md
@@ -0,0 +1,94 @@
+The target of `derive(CoercePointee)` macro has inadmissible specification for
+a meaningful use.
+
+Erroneous code examples:
+
+The target data is not a `struct`.
+
+```compile_fail,E0802
+#![feature(coerce_pointee)]
+use std::marker::CoercePointee;
+#[derive(CoercePointee)]
+enum NotStruct<'a, T: ?Sized> {
+    Variant(&'a T),
+}
+```
+
+The target data has a layout that is not transparent, or `repr(transparent)`
+in other words.
+
+```compile_fail,E0802
+#![feature(coerce_pointee)]
+use std::marker::CoercePointee;
+#[derive(CoercePointee)]
+struct NotTransparent<'a, #[pointee] T: ?Sized> {
+    ptr: &'a T,
+}
+```
+
+The target data has no data field.
+
+```compile_fail,E0802
+#![feature(coerce_pointee)]
+use std::marker::CoercePointee;
+#[derive(CoercePointee)]
+#[repr(transparent)]
+struct NoField<'a, #[pointee] T: ?Sized> {}
+```
+
+The target data is not generic over any data, or has no generic type parameter.
+
+```compile_fail,E0802
+#![feature(coerce_pointee)]
+use std::marker::CoercePointee;
+#[derive(CoercePointee)]
+#[repr(transparent)]
+struct NoGeneric<'a>(&'a u8);
+```
+
+The target data has multiple generic type parameters, but none is designated as
+a pointee for coercion.
+
+```compile_fail,E0802
+#![feature(coerce_pointee)]
+use std::marker::CoercePointee;
+#[derive(CoercePointee)]
+#[repr(transparent)]
+struct AmbiguousPointee<'a, T1: ?Sized, T2: ?Sized> {
+    a: (&'a T1, &'a T2),
+}
+```
+
+The target data has multiple generic type parameters that are designated as
+pointees for coercion.
+
+```compile_fail,E0802
+#![feature(coerce_pointee)]
+use std::marker::CoercePointee;
+#[derive(CoercePointee)]
+#[repr(transparent)]
+struct TooManyPointees<
+    'a,
+    #[pointee] A: ?Sized,
+    #[pointee] B: ?Sized>
+((&'a A, &'a B));
+```
+
+The type parameter that is designated as a pointee is not marked `?Sized`.
+
+```compile_fail,E0802
+#![feature(coerce_pointee)]
+use std::marker::CoercePointee;
+#[derive(CoercePointee)]
+#[repr(transparent)]
+struct NoMaybeSized<'a, #[pointee] T> {
+    ptr: &'a T,
+}
+```
+
+In summary, the `CoercePointee` macro demands the type to be a `struct` that is
+generic over at least one type or over more types, one of which is marked with
+`#[pointee]`, and has at least one data field and adopts a `repr(transparent)`
+layout.
+The only generic type or the type marked with `#[pointee]` has to be also
+marked as `?Sized`.
diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs
index 0a30bdb48a0..e970b16f610 100644
--- a/compiler/rustc_error_codes/src/lib.rs
+++ b/compiler/rustc_error_codes/src/lib.rs
@@ -545,6 +545,7 @@ E0798: 0798,
 E0799: 0799,
 E0800: 0800,
 E0801: 0801,
+E0802: 0802,
         );
     )
 }