introduce CoercePointeeWellformed for coherence checks at typeck stage
This commit is contained in:
@@ -48,6 +48,10 @@ pub(super) fn check_trait<'tcx>(
|
||||
checker
|
||||
.check(lang_items.dispatch_from_dyn_trait(), visit_implementation_of_dispatch_from_dyn)?;
|
||||
checker.check(lang_items.pointer_like(), visit_implementation_of_pointer_like)?;
|
||||
checker.check(
|
||||
lang_items.coerce_pointee_wellformed_trait(),
|
||||
visit_implementation_of_coerce_pointee_wellformed,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -782,3 +786,27 @@ fn visit_implementation_of_pointer_like(checker: &Checker<'_>) -> Result<(), Err
|
||||
.with_note(why_disqualified)
|
||||
.emit())
|
||||
}
|
||||
|
||||
fn visit_implementation_of_coerce_pointee_wellformed(
|
||||
checker: &Checker<'_>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let tcx = checker.tcx;
|
||||
let self_ty = tcx.impl_trait_ref(checker.impl_def_id).unwrap().instantiate_identity().self_ty();
|
||||
let ty::Adt(def, _args) = self_ty.kind() else {
|
||||
return Err(tcx.dcx().emit_err(errors::CoercePointeeNotConcreteType {
|
||||
span: tcx.def_span(checker.impl_def_id),
|
||||
}));
|
||||
};
|
||||
let did = def.did();
|
||||
let span =
|
||||
if let Some(local) = did.as_local() { tcx.source_span(local) } else { tcx.def_span(did) };
|
||||
if !def.is_struct() {
|
||||
return Err(tcx
|
||||
.dcx()
|
||||
.emit_err(errors::CoercePointeeNotStruct { span, kind: def.descr().into() }));
|
||||
}
|
||||
if !def.repr().transparent() {
|
||||
return Err(tcx.dcx().emit_err(errors::CoercePointeeNotTransparent { span }));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user