Rollup merge of #133774 - dingxiangfei2009:translatable-coerce-pointee-errors, r=jieyouxu

Make CoercePointee errors translatable

Tracked by #123430

Just in case that a translatable error message would become a blocker to stabilization, this PR switches over to fluent error messages, which also slightly improve the wordings and use more accurate span information.

cc `@Darksonn` `@traviscross`
This commit is contained in:
Matthias Krüger 2024-12-04 18:23:37 +01:00 committed by GitHub
commit 4b2d68dc3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 78 additions and 48 deletions

View file

@ -29,7 +29,7 @@ struct NoFieldUnit<'a, #[pointee] T: ?Sized>();
struct NoGeneric<'a>(&'a u8);
#[derive(CoercePointee)]
//~^ ERROR: exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits
//~^ ERROR: exactly one generic type parameter must be marked as `#[pointee]` to derive `CoercePointee` traits
#[repr(transparent)]
struct AmbiguousPointee<'a, T1: ?Sized, T2: ?Sized> {
a: (&'a T1, &'a T2),
@ -38,7 +38,7 @@ struct AmbiguousPointee<'a, T1: ?Sized, T2: ?Sized> {
#[derive(CoercePointee)]
#[repr(transparent)]
struct TooManyPointees<'a, #[pointee] A: ?Sized, #[pointee] B: ?Sized>((&'a A, &'a B));
//~^ ERROR: only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits
//~^ ERROR: only one type parameter can be marked as `#[pointee]` when deriving `CoercePointee` traits
#[derive(CoercePointee)]
//~^ ERROR: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`
@ -49,7 +49,7 @@ struct NotTransparent<'a, #[pointee] T: ?Sized> {
#[derive(CoercePointee)]
#[repr(transparent)]
struct NoMaybeSized<'a, #[pointee] T> {
//~^ ERROR: `derive(CoercePointee)` requires T to be marked `?Sized`
//~^ ERROR: `derive(CoercePointee)` requires `T` to be marked `?Sized`
ptr: &'a T,
}

View file

@ -30,7 +30,7 @@ LL | #[derive(CoercePointee)]
|
= note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info)
error: exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits
error: exactly one generic type parameter must be marked as `#[pointee]` to derive `CoercePointee` traits
--> $DIR/deriving-coerce-pointee-neg.rs:31:10
|
LL | #[derive(CoercePointee)]
@ -38,11 +38,11 @@ LL | #[derive(CoercePointee)]
|
= note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info)
error: only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits
error: only one type parameter can be marked as `#[pointee]` when deriving `CoercePointee` traits
--> $DIR/deriving-coerce-pointee-neg.rs:40:39
|
LL | struct TooManyPointees<'a, #[pointee] A: ?Sized, #[pointee] B: ?Sized>((&'a A, &'a B));
| ^ ^
| ^ - here another type parameter is marked as `#[pointee]`
error: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`
--> $DIR/deriving-coerce-pointee-neg.rs:43:10
@ -52,7 +52,7 @@ LL | #[derive(CoercePointee)]
|
= note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `derive(CoercePointee)` requires T to be marked `?Sized`
error: `derive(CoercePointee)` requires `T` to be marked `?Sized`
--> $DIR/deriving-coerce-pointee-neg.rs:51:36
|
LL | struct NoMaybeSized<'a, #[pointee] T> {