1use derive_where::derive_where;
2use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic};
3
4use crate::solve::NoSolution;
5use crate::{self as ty, Interner};
6
7#[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_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<T>;
}
}Eq)]
8#[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)]
9pub struct ExpectedFound<T> {
10 pub expected: T,
11 pub found: T,
12}
13
14impl<T> ExpectedFound<T> {
15 pub fn new(expected: T, found: T) -> Self {
16 ExpectedFound { expected, found }
17 }
18}
19
20#[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)]
22#[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>,
I::BoundRegion: ::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)]
23#[cfg_attr(feature = "nightly", rustc_pass_by_value)]
24pub enum TypeError<I: Interner> {
25 Mismatch,
26 PolarityMismatch(#[type_visitable(ignore)] ExpectedFound<ty::PredicatePolarity>),
27 SafetyMismatch(#[type_visitable(ignore)] ExpectedFound<I::Safety>),
28 AbiMismatch(#[type_visitable(ignore)] ExpectedFound<I::Abi>),
29 Mutability,
30 ArgumentMutability(usize),
31 TupleSize(ExpectedFound<usize>),
32 ArraySize(ExpectedFound<I::Const>),
33 ArgCount,
34
35 RegionsDoesNotOutlive(I::Region, I::Region),
36 RegionsInsufficientlyPolymorphic(I::BoundRegion, I::Region),
37 RegionsPlaceholderMismatch,
38
39 Sorts(ExpectedFound<I::Ty>),
40 ArgumentSorts(ExpectedFound<I::Ty>, usize),
41 Traits(ExpectedFound<I::TraitId>),
42 VariadicMismatch(ExpectedFound<bool>),
43
44 CyclicTy(I::Ty),
48 CyclicConst(I::Const),
49 ProjectionMismatched(ExpectedFound<I::DefId>),
50 ExistentialMismatch(ExpectedFound<I::BoundExistentialPredicates>),
51 ConstMismatch(ExpectedFound<I::Const>),
52
53 IntrinsicCast,
54 ForceInlineCast,
57 TargetFeatureCast(I::DefId),
59}
60
61impl<I: Interner> Eq for TypeError<I> {}
62
63impl<I: Interner> TypeError<I> {
64 pub fn involves_regions(self) -> bool {
65 match self {
66 TypeError::RegionsDoesNotOutlive(_, _)
67 | TypeError::RegionsInsufficientlyPolymorphic(_, _)
68 | TypeError::RegionsPlaceholderMismatch => true,
69 _ => false,
70 }
71 }
72
73 pub fn must_include_note(self) -> bool {
74 use self::TypeError::*;
75 match self {
76 CyclicTy(_) | CyclicConst(_) | SafetyMismatch(_) | PolarityMismatch(_) | Mismatch
77 | AbiMismatch(_) | ArraySize(_) | ArgumentSorts(..) | Sorts(_)
78 | VariadicMismatch(_) | TargetFeatureCast(_) => false,
79
80 Mutability
81 | ArgumentMutability(_)
82 | TupleSize(_)
83 | ArgCount
84 | RegionsDoesNotOutlive(..)
85 | RegionsInsufficientlyPolymorphic(..)
86 | RegionsPlaceholderMismatch
87 | Traits(_)
88 | ProjectionMismatched(_)
89 | ExistentialMismatch(_)
90 | ConstMismatch(_)
91 | ForceInlineCast
92 | IntrinsicCast => true,
93 }
94 }
95}
96
97impl<I: Interner> From<TypeError<I>> for NoSolution {
98 fn from(_: TypeError<I>) -> NoSolution {
99 NoSolution
100 }
101}