1use derive_where::derive_where;
2use rustc_abi::ExternAbi;
3use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic};
4
5use crate::solve::NoSolution;
6use crate::{self as ty, Interner};
7
8#[derive(#[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for ExpectedFound<T> {
#[inline]
fn clone(&self) -> ExpectedFound<T> {
ExpectedFound {
expected: ::core::clone::Clone::clone(&self.expected),
found: ::core::clone::Clone::clone(&self.found),
}
}
}Clone, #[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for ExpectedFound<T> { }Copy, #[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for ExpectedFound<T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "ExpectedFound",
"expected", &self.expected, "found", &&self.found)
}
}Debug, #[automatically_derived]
impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for ExpectedFound<T> {
#[inline]
fn eq(&self, other: &ExpectedFound<T>) -> bool {
self.expected == other.expected && self.found == other.found
}
}PartialEq, #[automatically_derived]
impl<T: ::core::cmp::Eq> ::core::cmp::Eq for ExpectedFound<T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) { let _: ::core::cmp::AssertParamIsEq<T>; }
}Eq)]
9#[derive(const _: () =
{
impl<T, I> ::rustc_type_ir::TypeFoldable<I> for ExpectedFound<T> where
I: Interner, T: ::rustc_type_ir::TypeFoldable<I> {
fn try_fold_with<__F: ::rustc_type_ir::FallibleTypeFolder<I>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
ExpectedFound { expected: __binding_0, found: __binding_1 }
=> {
ExpectedFound {
expected: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
found: ::rustc_type_ir::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
}
}
})
}
fn fold_with<__F: ::rustc_type_ir::TypeFolder<I>>(self,
__folder: &mut __F) -> Self {
match self {
ExpectedFound { expected: __binding_0, found: __binding_1 }
=> {
ExpectedFound {
expected: ::rustc_type_ir::TypeFoldable::fold_with(__binding_0,
__folder),
found: ::rustc_type_ir::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable_Generic, const _: () =
{
impl<T, I> ::rustc_type_ir::TypeVisitable<I> for ExpectedFound<T>
where I: Interner, T: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
ExpectedFound {
expected: ref __binding_0, found: ref __binding_1 } => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_type_ir::VisitorResult>::output()
}
}
};TypeVisitable_Generic, GenericTypeVisitable)]
10pub struct ExpectedFound<T> {
11 pub expected: T,
12 pub found: T,
13}
14
15impl<T> ExpectedFound<T> {
16 pub fn new(expected: T, found: T) -> Self {
17 ExpectedFound { expected, found }
18 }
19}
20
21#[automatically_derived]
impl<I: Interner> ::core::fmt::Debug for TypeError<I> where I: Interner {
fn fmt(&self, __f: &mut ::core::fmt::Formatter<'_>)
-> ::core::fmt::Result {
match self {
TypeError::Mismatch =>
::core::fmt::Formatter::write_str(__f, "Mismatch"),
TypeError::PolarityMismatch(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"PolarityMismatch");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::SafetyMismatch(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "SafetyMismatch");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::AbiMismatch(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "AbiMismatch");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::Mutability =>
::core::fmt::Formatter::write_str(__f, "Mutability"),
TypeError::ArgumentMutability(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"ArgumentMutability");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::TupleSize(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "TupleSize");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::ArraySize(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "ArraySize");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::ArgCount =>
::core::fmt::Formatter::write_str(__f, "ArgCount"),
TypeError::RegionsDoesNotOutlive(ref __field_0, ref __field_1) =>
{
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"RegionsDoesNotOutlive");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::field(&mut __builder, __field_1);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::RegionsInsufficientlyPolymorphic(ref __field_0,
ref __field_1) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"RegionsInsufficientlyPolymorphic");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::field(&mut __builder, __field_1);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::RegionsPlaceholderMismatch =>
::core::fmt::Formatter::write_str(__f,
"RegionsPlaceholderMismatch"),
TypeError::Sorts(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Sorts");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::ArgumentSorts(ref __field_0, ref __field_1) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "ArgumentSorts");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::field(&mut __builder, __field_1);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::Traits(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "Traits");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::VariadicMismatch(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"VariadicMismatch");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::CyclicTy(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "CyclicTy");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::CyclicConst(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "CyclicConst");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::ProjectionMismatched(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"ProjectionMismatched");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::ExistentialMismatch(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"ExistentialMismatch");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::ConstMismatch(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f, "ConstMismatch");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
TypeError::IntrinsicCast =>
::core::fmt::Formatter::write_str(__f, "IntrinsicCast"),
TypeError::ForceInlineCast =>
::core::fmt::Formatter::write_str(__f, "ForceInlineCast"),
TypeError::TargetFeatureCast(ref __field_0) => {
let mut __builder =
::core::fmt::Formatter::debug_tuple(__f,
"TargetFeatureCast");
::core::fmt::DebugTuple::field(&mut __builder, __field_0);
::core::fmt::DebugTuple::finish(&mut __builder)
}
}
}
}#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)]
23#[derive(const _: () =
{
impl<I: Interner> ::rustc_type_ir::TypeVisitable<I> for TypeError<I>
where I: Interner,
ExpectedFound<I::Const>: ::rustc_type_ir::TypeVisitable<I>,
I::Region: ::rustc_type_ir::TypeVisitable<I>,
ty::BoundRegion<I>: ::rustc_type_ir::TypeVisitable<I>,
ExpectedFound<I::Ty>: ::rustc_type_ir::TypeVisitable<I>,
ExpectedFound<I::TraitId>: ::rustc_type_ir::TypeVisitable<I>,
I::Ty: ::rustc_type_ir::TypeVisitable<I>,
I::Const: ::rustc_type_ir::TypeVisitable<I>,
ExpectedFound<I::DefId>: ::rustc_type_ir::TypeVisitable<I>,
ExpectedFound<I::BoundExistentialPredicates>: ::rustc_type_ir::TypeVisitable<I>,
I::DefId: ::rustc_type_ir::TypeVisitable<I> {
fn visit_with<__V: ::rustc_type_ir::TypeVisitor<I>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
TypeError::Mismatch => {}
TypeError::PolarityMismatch(..) => {}
TypeError::SafetyMismatch(..) => {}
TypeError::AbiMismatch(..) => {}
TypeError::Mutability => {}
TypeError::ArgumentMutability(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::TupleSize(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::ArraySize(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::ArgCount => {}
TypeError::RegionsDoesNotOutlive(ref __binding_0,
ref __binding_1) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::RegionsInsufficientlyPolymorphic(ref __binding_0,
ref __binding_1) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::RegionsPlaceholderMismatch => {}
TypeError::Sorts(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::ArgumentSorts(ref __binding_0, ref __binding_1)
=> {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::Traits(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::VariadicMismatch(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::CyclicTy(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::CyclicConst(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::ProjectionMismatched(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::ExistentialMismatch(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::ConstMismatch(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
TypeError::IntrinsicCast => {}
TypeError::ForceInlineCast => {}
TypeError::TargetFeatureCast(ref __binding_0) => {
{
match ::rustc_type_ir::VisitorResult::branch(::rustc_type_ir::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_type_ir::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_type_ir::VisitorResult>::output()
}
}
};TypeVisitable_Generic, GenericTypeVisitable)]
24#[cfg_attr(feature = "nightly", rustc_pass_by_value)]
25pub enum TypeError<I: Interner> {
26 Mismatch,
27 PolarityMismatch(#[type_visitable(ignore)] ExpectedFound<ty::PredicatePolarity>),
28 SafetyMismatch(#[type_visitable(ignore)] ExpectedFound<I::Safety>),
29 AbiMismatch(#[type_visitable(ignore)] ExpectedFound<ExternAbi>),
30 Mutability,
31 ArgumentMutability(usize),
32 TupleSize(ExpectedFound<usize>),
33 ArraySize(ExpectedFound<I::Const>),
34 ArgCount,
35
36 RegionsDoesNotOutlive(I::Region, I::Region),
37 RegionsInsufficientlyPolymorphic(ty::BoundRegion<I>, I::Region),
38 RegionsPlaceholderMismatch,
39
40 Sorts(ExpectedFound<I::Ty>),
41 ArgumentSorts(ExpectedFound<I::Ty>, usize),
42 Traits(ExpectedFound<I::TraitId>),
43 VariadicMismatch(ExpectedFound<bool>),
44
45 CyclicTy(I::Ty),
49 CyclicConst(I::Const),
50 ProjectionMismatched(ExpectedFound<I::DefId>),
51 ExistentialMismatch(ExpectedFound<I::BoundExistentialPredicates>),
52 ConstMismatch(ExpectedFound<I::Const>),
53
54 IntrinsicCast,
55 ForceInlineCast,
58 TargetFeatureCast(I::DefId),
60}
61
62impl<I: Interner> Eq for TypeError<I> {}
63
64impl<I: Interner> TypeError<I> {
65 pub fn involves_regions(self) -> bool {
66 match self {
67 TypeError::RegionsDoesNotOutlive(_, _)
68 | TypeError::RegionsInsufficientlyPolymorphic(_, _)
69 | TypeError::RegionsPlaceholderMismatch => true,
70 _ => false,
71 }
72 }
73
74 pub fn must_include_note(self) -> bool {
75 use self::TypeError::*;
76 match self {
77 CyclicTy(_) | CyclicConst(_) | SafetyMismatch(_) | PolarityMismatch(_) | Mismatch
78 | AbiMismatch(_) | ArraySize(_) | ArgumentSorts(..) | Sorts(_)
79 | VariadicMismatch(_) | TargetFeatureCast(_) => false,
80
81 Mutability
82 | ArgumentMutability(_)
83 | TupleSize(_)
84 | ArgCount
85 | RegionsDoesNotOutlive(..)
86 | RegionsInsufficientlyPolymorphic(..)
87 | RegionsPlaceholderMismatch
88 | Traits(_)
89 | ProjectionMismatched(_)
90 | ExistentialMismatch(_)
91 | ConstMismatch(_)
92 | ForceInlineCast
93 | IntrinsicCast => true,
94 }
95 }
96}
97
98impl<I: Interner> From<TypeError<I>> for NoSolution {
99 fn from(_: TypeError<I>) -> NoSolution {
100 NoSolution
101 }
102}