1use rustc_data_structures::sorted_map::SortedIndexMultiMap;
2use rustc_hir as hir;
3use rustc_hir::def::{DefKind, Namespace};
4use rustc_hir::def_id::DefId;
5use rustc_macros::{Decodable, Encodable, StableHash};
6use rustc_span::def_id::ModId;
7use rustc_span::{ErrorGuaranteed, Ident, Symbol};
8
9use super::{TyCtxt, Visibility};
10use crate::ty;
11
12#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AssocContainer { }
#[automatically_derived]
impl ::core::clone::Clone for AssocContainer {
#[inline]
fn clone(&self) -> AssocContainer {
let _:
::core::clone::AssertParamIsClone<Result<DefId,
ErrorGuaranteed>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for AssocContainer { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AssocContainer { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AssocContainer {
#[inline]
fn eq(&self, other: &AssocContainer) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(AssocContainer::TraitImpl(__self_0),
AssocContainer::TraitImpl(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AssocContainer {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Result<DefId, ErrorGuaranteed>>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for AssocContainer {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AssocContainer::Trait =>
::core::fmt::Formatter::write_str(f, "Trait"),
AssocContainer::InherentImpl =>
::core::fmt::Formatter::write_str(f, "InherentImpl"),
AssocContainer::TraitImpl(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TraitImpl", &__self_0),
}
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
AssocContainer {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
AssocContainer::Trait => {}
AssocContainer::InherentImpl => {}
AssocContainer::TraitImpl(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, #[automatically_derived]
impl ::core::hash::Hash for AssocContainer {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
AssocContainer::TraitImpl(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for AssocContainer {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AssocContainer::Trait => { 0usize }
AssocContainer::InherentImpl => { 1usize }
AssocContainer::TraitImpl(ref __binding_0) => { 2usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AssocContainer::Trait => {}
AssocContainer::InherentImpl => {}
AssocContainer::TraitImpl(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for AssocContainer {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { AssocContainer::Trait }
1usize => { AssocContainer::InherentImpl }
2usize => {
AssocContainer::TraitImpl(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AssocContainer`, expected 0..3, actual {0}",
n));
}
}
}
}
};Decodable)]
13pub enum AssocContainer {
14 Trait,
15 InherentImpl,
16 TraitImpl(Result<DefId, ErrorGuaranteed>),
18}
19
20#[derive(#[automatically_derived]
impl ::core::marker::Copy for AssocItem { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AssocItem { }
#[automatically_derived]
impl ::core::clone::Clone for AssocItem {
#[inline]
fn clone(&self) -> AssocItem {
let _: ::core::clone::AssertParamIsClone<DefId>;
let _: ::core::clone::AssertParamIsClone<AssocKind>;
let _: ::core::clone::AssertParamIsClone<AssocContainer>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for AssocItem {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "AssocItem",
"def_id", &self.def_id, "kind", &self.kind, "container",
&&self.container)
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AssocItem { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AssocItem {
#[inline]
fn eq(&self, other: &AssocItem) -> bool {
self.def_id == other.def_id && self.kind == other.kind &&
self.container == other.container
}
}PartialEq, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for AssocItem {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
AssocItem {
def_id: ref __binding_0,
kind: ref __binding_1,
container: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, #[automatically_derived]
impl ::core::cmp::Eq for AssocItem {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<AssocKind>;
let _: ::core::cmp::AssertParamIsEq<AssocContainer>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for AssocItem {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.def_id, state);
::core::hash::Hash::hash(&self.kind, state);
::core::hash::Hash::hash(&self.container, state)
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for AssocItem {
fn encode(&self, __encoder: &mut __E) {
let AssocItem {
def_id: ref __binding_0,
kind: ref __binding_1,
container: ref __binding_2 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for AssocItem {
fn decode(__decoder: &mut __D) -> Self {
AssocItem {
def_id: ::rustc_serialize::Decodable::decode(__decoder),
kind: ::rustc_serialize::Decodable::decode(__decoder),
container: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
22pub struct AssocItem {
23 pub def_id: DefId,
24 pub kind: AssocKind,
25 pub container: AssocContainer,
26}
27
28impl AssocItem {
29 pub fn opt_name(&self) -> Option<Symbol> {
31 match self.kind {
32 ty::AssocKind::Type { data: AssocTypeData::Normal(name) } => Some(name),
33 ty::AssocKind::Type { data: AssocTypeData::Rpitit(_) } => None,
34 ty::AssocKind::Const { name, .. } => Some(name),
35 ty::AssocKind::Fn { name, .. } => Some(name),
36 }
37 }
38
39 pub fn name(&self) -> Symbol {
42 self.opt_name().expect("name of non-Rpitit assoc item")
43 }
44
45 pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
46 Ident::new(self.name(), tcx.def_ident_span(self.def_id).unwrap())
47 }
48
49 pub fn defaultness(&self, tcx: TyCtxt<'_>) -> hir::Defaultness {
55 match self.container {
56 AssocContainer::InherentImpl => hir::Defaultness::Final,
57 AssocContainer::Trait | AssocContainer::TraitImpl(_) => tcx.defaultness(self.def_id),
58 }
59 }
60
61 pub fn expect_trait_impl(&self) -> Result<DefId, ErrorGuaranteed> {
62 let AssocContainer::TraitImpl(trait_item_id) = self.container else {
63 crate::util::bug::bug_fmt(format_args!("expected item to be in a trait impl: {0:?}",
self.def_id));bug!("expected item to be in a trait impl: {:?}", self.def_id);
64 };
65 trait_item_id
66 }
67
68 pub fn trait_item_or_self(&self) -> Result<DefId, ErrorGuaranteed> {
72 match self.container {
73 AssocContainer::TraitImpl(id) => id,
74 AssocContainer::Trait | AssocContainer::InherentImpl => Ok(self.def_id),
75 }
76 }
77
78 pub fn trait_item_def_id(&self) -> Option<DefId> {
79 match self.container {
80 AssocContainer::TraitImpl(Ok(id)) => Some(id),
81 _ => None,
82 }
83 }
84
85 #[inline]
86 pub fn visibility(&self, tcx: TyCtxt<'_>) -> Visibility<ModId> {
87 tcx.visibility(self.def_id)
88 }
89
90 #[inline]
91 pub fn container_id(&self, tcx: TyCtxt<'_>) -> DefId {
92 tcx.parent(self.def_id)
93 }
94
95 #[inline]
96 pub fn trait_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
97 match self.container {
98 AssocContainer::InherentImpl | AssocContainer::TraitImpl(_) => None,
99 AssocContainer::Trait => Some(tcx.parent(self.def_id)),
100 }
101 }
102
103 #[inline]
104 pub fn impl_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
105 match self.container {
106 AssocContainer::InherentImpl | AssocContainer::TraitImpl(_) => {
107 Some(tcx.parent(self.def_id))
108 }
109 AssocContainer::Trait => None,
110 }
111 }
112
113 pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
114 match self.kind {
115 ty::AssocKind::Fn { .. } => {
116 tcx.fn_sig(self.def_id).instantiate_identity().skip_binder().to_string()
121 }
122 ty::AssocKind::Type { .. } => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("type {0};", self.name()))
})format!("type {};", self.name()),
123 ty::AssocKind::Const { name, .. } => {
124 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("const {0}: {1:?};", name,
tcx.type_of(self.def_id).instantiate_identity()))
})format!("const {}: {:?};", name, tcx.type_of(self.def_id).instantiate_identity())
125 }
126 }
127 }
128
129 pub fn descr(&self) -> &'static str {
130 self.kind.descr()
131 }
132
133 pub fn namespace(&self) -> Namespace {
134 self.kind.namespace()
135 }
136
137 pub fn as_def_kind(&self) -> DefKind {
138 self.kind.as_def_kind()
139 }
140
141 pub fn can_have_equality_constraint(&self, tcx: TyCtxt<'_>) -> bool {
143 match self.kind {
144 ty::AssocKind::Type { .. } => true,
145 ty::AssocKind::Const { .. } => {
146 tcx.features().generic_const_args() || tcx.is_direct_const(self.def_id)
147 }
148 ty::AssocKind::Fn { .. } => false,
149 }
150 }
151
152 pub fn is_fn(&self) -> bool {
153 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Fn { .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Fn { .. })
154 }
155
156 pub fn is_method(&self) -> bool {
157 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Fn { has_self: true, .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Fn { has_self: true, .. })
158 }
159
160 pub fn is_type(&self) -> bool {
161 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Type { .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Type { .. })
162 }
163
164 pub fn tag(&self) -> AssocTag {
165 self.kind.tag()
166 }
167
168 pub fn is_impl_trait_in_trait(&self) -> bool {
169 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
AssocKind::Type { data: AssocTypeData::Rpitit(_) } => true,
_ => false,
}matches!(self.kind, AssocKind::Type { data: AssocTypeData::Rpitit(_) })
170 }
171}
172
173#[derive(#[automatically_derived]
impl ::core::marker::Copy for AssocTypeData { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AssocTypeData { }
#[automatically_derived]
impl ::core::clone::Clone for AssocTypeData {
#[inline]
fn clone(&self) -> AssocTypeData {
let _: ::core::clone::AssertParamIsClone<Symbol>;
let _: ::core::clone::AssertParamIsClone<ty::ImplTraitInTraitData>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AssocTypeData { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AssocTypeData {
#[inline]
fn eq(&self, other: &AssocTypeData) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(AssocTypeData::Normal(__self_0),
AssocTypeData::Normal(__arg1_0)) => __self_0 == __arg1_0,
(AssocTypeData::Rpitit(__self_0),
AssocTypeData::Rpitit(__arg1_0)) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for AssocTypeData {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AssocTypeData::Normal(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Normal",
&__self_0),
AssocTypeData::Rpitit(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Rpitit",
&__self_0),
}
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
AssocTypeData {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
AssocTypeData::Normal(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AssocTypeData::Rpitit(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, #[automatically_derived]
impl ::core::cmp::Eq for AssocTypeData {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Symbol>;
let _: ::core::cmp::AssertParamIsEq<ty::ImplTraitInTraitData>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for AssocTypeData {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
AssocTypeData::Normal(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
AssocTypeData::Rpitit(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for AssocTypeData {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AssocTypeData::Normal(ref __binding_0) => { 0usize }
AssocTypeData::Rpitit(ref __binding_0) => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AssocTypeData::Normal(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AssocTypeData::Rpitit(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for AssocTypeData {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
AssocTypeData::Normal(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
AssocTypeData::Rpitit(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AssocTypeData`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable)]
174pub enum AssocTypeData {
175 Normal(Symbol),
176 Rpitit(ty::ImplTraitInTraitData),
180}
181
182#[derive(#[automatically_derived]
impl ::core::marker::Copy for AssocKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AssocKind { }
#[automatically_derived]
impl ::core::clone::Clone for AssocKind {
#[inline]
fn clone(&self) -> AssocKind {
let _: ::core::clone::AssertParamIsClone<Symbol>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<AssocTypeData>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AssocKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AssocKind {
#[inline]
fn eq(&self, other: &AssocKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(AssocKind::Const { name: __self_0, is_type_const: __self_1 },
AssocKind::Const { name: __arg1_0, is_type_const: __arg1_1
}) => __self_1 == __arg1_1 && __self_0 == __arg1_0,
(AssocKind::Fn { name: __self_0, has_self: __self_1 },
AssocKind::Fn { name: __arg1_0, has_self: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(AssocKind::Type { data: __self_0 }, AssocKind::Type {
data: __arg1_0 }) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for AssocKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AssocKind::Const { name: __self_0, is_type_const: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "Const",
"name", __self_0, "is_type_const", &__self_1),
AssocKind::Fn { name: __self_0, has_self: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "Fn",
"name", __self_0, "has_self", &__self_1),
AssocKind::Type { data: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Type",
"data", &__self_0),
}
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for AssocKind {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
AssocKind::Const {
name: ref __binding_0, is_type_const: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
AssocKind::Fn {
name: ref __binding_0, has_self: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
AssocKind::Type { data: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, #[automatically_derived]
impl ::core::cmp::Eq for AssocKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Symbol>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<AssocTypeData>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for AssocKind {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
AssocKind::Const { name: __self_0, is_type_const: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
AssocKind::Fn { name: __self_0, has_self: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
AssocKind::Type { data: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for AssocKind {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AssocKind::Const {
name: ref __binding_0, is_type_const: ref __binding_1 } => {
0usize
}
AssocKind::Fn {
name: ref __binding_0, has_self: ref __binding_1 } => {
1usize
}
AssocKind::Type { data: ref __binding_0 } => { 2usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AssocKind::Const {
name: ref __binding_0, is_type_const: ref __binding_1 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
AssocKind::Fn {
name: ref __binding_0, has_self: ref __binding_1 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
AssocKind::Type { data: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for AssocKind {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
AssocKind::Const {
name: ::rustc_serialize::Decodable::decode(__decoder),
is_type_const: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
AssocKind::Fn {
name: ::rustc_serialize::Decodable::decode(__decoder),
has_self: ::rustc_serialize::Decodable::decode(__decoder),
}
}
2usize => {
AssocKind::Type {
data: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AssocKind`, expected 0..3, actual {0}",
n));
}
}
}
}
};Decodable)]
183pub enum AssocKind {
184 Const { name: Symbol, is_type_const: bool },
185 Fn { name: Symbol, has_self: bool },
186 Type { data: AssocTypeData },
187}
188
189impl AssocKind {
190 pub fn namespace(&self) -> Namespace {
191 match self {
192 Self::Type { .. } => Namespace::TypeNS,
193 Self::Const { .. } | Self::Fn { .. } => Namespace::ValueNS,
194 }
195 }
196
197 pub fn tag(&self) -> AssocTag {
198 match self {
199 Self::Const { .. } => AssocTag::Const,
200 Self::Fn { .. } => AssocTag::Fn,
201 Self::Type { .. } => AssocTag::Type,
202 }
203 }
204
205 pub fn as_def_kind(&self) -> DefKind {
206 match self {
207 &Self::Const { is_type_const, .. } => DefKind::AssocConst { is_type_const },
208 Self::Fn { .. } => DefKind::AssocFn,
209 Self::Type { .. } => DefKind::AssocTy,
210 }
211 }
212
213 pub fn descr(&self) -> &'static str {
214 match self {
215 Self::Fn { has_self: true, .. } => "method",
216 _ => self.tag().descr(),
217 }
218 }
219}
220
221impl std::fmt::Display for AssocKind {
222 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
223 f.write_str(self.descr())
224 }
225}
226
227#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AssocTag { }
#[automatically_derived]
impl ::core::clone::Clone for AssocTag {
#[inline]
fn clone(&self) -> AssocTag { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for AssocTag { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for AssocTag {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AssocTag::Const => "Const",
AssocTag::Fn => "Fn",
AssocTag::Type => "Type",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AssocTag { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AssocTag {
#[inline]
fn eq(&self, other: &AssocTag) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AssocTag {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for AssocTag {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash)]
229pub enum AssocTag {
230 Const,
231 Fn,
232 Type,
233}
234
235impl AssocTag {
236 pub fn descr(self) -> &'static str {
237 match self {
239 Self::Const => "associated constant",
240 Self::Fn => "associated function",
241 Self::Type => "associated type",
242 }
243 }
244}
245
246#[derive(#[automatically_derived]
impl ::core::fmt::Debug for AssocItems {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "AssocItems",
"items", &&self.items)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for AssocItems {
#[inline]
fn clone(&self) -> AssocItems {
AssocItems { items: ::core::clone::Clone::clone(&self.items) }
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AssocItems { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AssocItems {
#[inline]
fn eq(&self, other: &AssocItems) -> bool { self.items == other.items }
}PartialEq, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for AssocItems {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
AssocItems { items: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
252pub struct AssocItems {
253 items: SortedIndexMultiMap<u32, Option<Symbol>, ty::AssocItem>,
254}
255
256impl AssocItems {
257 pub fn new(items_in_def_order: impl IntoIterator<Item = ty::AssocItem>) -> Self {
259 let items = items_in_def_order.into_iter().map(|item| (item.opt_name(), item)).collect();
260 AssocItems { items }
261 }
262
263 pub fn in_definition_order(&self) -> impl '_ + Iterator<Item = &ty::AssocItem> {
268 self.items.iter().map(|(_, v)| v)
269 }
270
271 pub fn len(&self) -> usize {
272 self.items.len()
273 }
274
275 pub fn filter_by_name_unhygienic(
279 &self,
280 name: Symbol,
281 ) -> impl '_ + Iterator<Item = &ty::AssocItem> {
282 if !!name.is_empty() {
::core::panicking::panic("assertion failed: !name.is_empty()")
};assert!(!name.is_empty());
283 self.items.get_by_key(Some(name))
284 }
285
286 pub fn filter_by_name_unhygienic_and_kind(
289 &self,
290 name: Symbol,
291 assoc_tag: AssocTag,
292 ) -> impl '_ + Iterator<Item = &ty::AssocItem> {
293 self.filter_by_name_unhygienic(name).filter(move |item| item.tag() == assoc_tag)
294 }
295
296 pub fn find_by_ident_and_kind(
299 &self,
300 tcx: TyCtxt<'_>,
301 ident: Ident,
302 assoc_tag: AssocTag,
303 parent_def_id: DefId,
304 ) -> Option<&ty::AssocItem> {
305 self.filter_by_name_unhygienic(ident.name)
306 .filter(|item| item.tag() == assoc_tag)
307 .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
308 }
309
310 pub fn find_by_ident_and_namespace(
313 &self,
314 tcx: TyCtxt<'_>,
315 ident: Ident,
316 ns: Namespace,
317 parent_def_id: DefId,
318 ) -> Option<&ty::AssocItem> {
319 self.filter_by_name_unhygienic(ident.name)
320 .filter(|item| item.namespace() == ns)
321 .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
322 }
323}
324
325impl<'tcx> TyCtxt<'tcx> {
326 pub fn associated_types_for_impl_traits_in_associated_fn(
336 self,
337 fn_def_id: DefId,
338 ) -> &'tcx [DefId] {
339 let parent_def_id = self.parent(fn_def_id);
340 &self.associated_types_for_impl_traits_in_trait_or_impl(parent_def_id)[&fn_def_id]
341 }
342}