Rollup merge of #94249 - compiler-errors:better-copy-errors, r=davidtwco
Better errors when a Copy impl on a Struct is not self-consistent As discovered in a Zulip thread with `@nnethercote` and `@Mark-Simulacrum,` it's not immediately obvious why a field on an ADT doesn't implement `Copy`. This PR attempts to give slightly more detailed information by spinning up a fulfillment context to try to dig down and discover transitive fulfillment errors that cause `is_copy_modulo_regions` to fail on a ADT field. The error message still kinda sucks, but should only show up in the case that an existing error message was totally missing... so I think it's a good compromise for now?
This commit is contained in:
commit
af19a50a26
5 changed files with 100 additions and 4 deletions
|
@ -11,7 +11,7 @@ use crate::traits::error_reporting::InferCtxtExt;
|
|||
|
||||
#[derive(Clone)]
|
||||
pub enum CopyImplementationError<'tcx> {
|
||||
InfrigingFields(Vec<&'tcx ty::FieldDef>),
|
||||
InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>)>),
|
||||
NotAnAdt,
|
||||
HasDestructor,
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ pub fn can_type_implement_copy<'tcx>(
|
|||
match traits::fully_normalize(&infcx, ctx, cause, param_env, ty) {
|
||||
Ok(ty) => {
|
||||
if !infcx.type_is_copy_modulo_regions(param_env, ty, span) {
|
||||
infringing.push(field);
|
||||
infringing.push((field, ty));
|
||||
}
|
||||
}
|
||||
Err(errors) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue