1
Fork 0

Rollup merge of #97351 - b-naber:adt-const-params-structural-match-violation, r=michaelwoerister

Output correct type responsible for structural match violation

Previously we included the outermost type that caused a structural match violation in the error message and stated that that type must be annotated with `#[derive(Eq, PartialEq)]` even if it already had that annotation. This PR outputs the correct type in the error message.

Fixes https://github.com/rust-lang/rust/issues/97278
This commit is contained in:
Dylan DPC 2022-05-25 17:37:21 +02:00 committed by GitHub
commit 8a3ad4942c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 30 deletions

View file

@ -62,7 +62,7 @@ pub use self::specialize::specialization_graph::FutureCompatOverlapError;
pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
pub use self::specialize::{specialization_graph, translate_substs, OverlapError};
pub use self::structural_match::search_for_structural_match_violation;
pub use self::structural_match::NonStructuralMatchTy;
pub use self::structural_match::{NonStructuralMatchTy, NonStructuralMatchTyKind};
pub use self::util::{
elaborate_obligations, elaborate_predicates, elaborate_predicates_with_span,
elaborate_trait_ref, elaborate_trait_refs,

View file

@ -11,7 +11,13 @@ use rustc_span::Span;
use std::ops::ControlFlow;
#[derive(Debug)]
pub enum NonStructuralMatchTy<'tcx> {
pub struct NonStructuralMatchTy<'tcx> {
pub ty: Ty<'tcx>,
pub kind: NonStructuralMatchTyKind<'tcx>,
}
#[derive(Debug)]
pub enum NonStructuralMatchTyKind<'tcx> {
Adt(AdtDef<'tcx>),
Param,
Dynamic,
@ -137,25 +143,32 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
let (adt_def, substs) = match *ty.kind() {
ty::Adt(adt_def, substs) => (adt_def, substs),
ty::Param(_) => {
return ControlFlow::Break(NonStructuralMatchTy::Param);
let kind = NonStructuralMatchTyKind::Param;
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
ty::Dynamic(..) => {
return ControlFlow::Break(NonStructuralMatchTy::Dynamic);
let kind = NonStructuralMatchTyKind::Dynamic;
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
ty::Foreign(_) => {
return ControlFlow::Break(NonStructuralMatchTy::Foreign);
let kind = NonStructuralMatchTyKind::Foreign;
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
ty::Opaque(..) => {
return ControlFlow::Break(NonStructuralMatchTy::Opaque);
let kind = NonStructuralMatchTyKind::Opaque;
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
ty::Projection(..) => {
return ControlFlow::Break(NonStructuralMatchTy::Projection);
let kind = NonStructuralMatchTyKind::Projection;
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
ty::Closure(..) => {
return ControlFlow::Break(NonStructuralMatchTy::Closure);
let kind = NonStructuralMatchTyKind::Closure;
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
ty::Generator(..) | ty::GeneratorWitness(..) => {
return ControlFlow::Break(NonStructuralMatchTy::Generator);
let kind = NonStructuralMatchTyKind::Generator;
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
ty::RawPtr(..) => {
// structural-match ignores substructure of
@ -215,7 +228,8 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
if !self.type_marked_structural(ty) {
debug!("Search found ty: {:?}", ty);
return ControlFlow::Break(NonStructuralMatchTy::Adt(adt_def));
let kind = NonStructuralMatchTyKind::Adt(adt_def);
return ControlFlow::Break(NonStructuralMatchTy { ty, kind });
}
// structural-match does not care about the