Skip to content

Commit

Permalink
fix the error code document
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Feb 9, 2025
1 parent 9aabb55 commit 5324992
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0802.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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),
Expand All @@ -16,6 +18,8 @@ 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,
Expand All @@ -25,6 +29,8 @@ struct NotTransparent<'a, #[pointee] T: ?Sized> {
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> {}
Expand All @@ -33,6 +39,8 @@ 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);
Expand All @@ -42,6 +50,8 @@ 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> {
Expand All @@ -53,6 +63,8 @@ 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<
Expand All @@ -65,6 +77,8 @@ struct TooManyPointees<
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> {
Expand Down

0 comments on commit 5324992

Please sign in to comment.