Redact CoercePointee target type by dingxiangfei2009 · Pull Request #136796 · rust-lang/rust (original) (raw)

OK -- so I think I understand my problem with this PR in its current state. Specifically, it's trying to do two things:

  1. Change the error messages when fields violate the implementation validity *structurally, like:
#![feature(derive_coerce_pointee)]
use std:📑:CoercePointee;

#[derive(CoercePointee)]
#[repr(transparent)]
struct P<T: 'static + ?Sized> {
    x: &'static T,
    y: &'static T,
}
  1. Improve the error messages when trait solving fails to satisfy the CoercePointee or DispatchFromDyn goal needed for validity:
#![feature(derive_coerce_pointee)]
use std:📑:CoercePointee;

#[derive(CoercePointee)]
#[repr(transparent)]
struct P<T: 'static + ?Sized> {
    x: (T,),
}

I'm somewhat hesitant that they need to be fixed at the same time, and I dislike the fact that the improvements relies on extract_coerce_pointee_data doing so much work.

For example, for (1.) we could simply just detect if the impl is coming from an expansion (by looking at the span of the impl) and change the error message (like DispatchFromDynSingle, DispatchFromDynMulti) into more tailored versions that don't need to mention the "right-hand-side type", like &'static S__.

For the trait error reporting, we could simply emit a more tailored fulfillment error if there is only one fulfillment error and it ends up failing an Unsize or CoerceUnsized goal, rather than relying on a somewhat pervasive control flow invariant that extract_coerce_pointee_data will emit an error.

TL;DR is that I think this PR is trying to change a lot all at once, and I'm somewhat overwhelmed with the state of it right now.