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]
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::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]
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::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) {
match *self {
AssocItem {
def_id: ref __binding_0,
kind: ref __binding_1,
container: ref __binding_2 } => {
::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 is_type_const(&self) -> bool {
142 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Const { is_type_const: true, .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Const { is_type_const: true, .. })
143 }
144
145 pub fn is_fn(&self) -> bool {
146 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Fn { .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Fn { .. })
147 }
148
149 pub fn is_method(&self) -> bool {
150 #[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, .. })
151 }
152
153 pub fn is_type(&self) -> bool {
154 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Type { .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Type { .. })
155 }
156
157 pub fn tag(&self) -> AssocTag {
158 self.kind.tag()
159 }
160
161 pub fn is_impl_trait_in_trait(&self) -> bool {
162 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
AssocKind::Type { data: AssocTypeData::Rpitit(_) } => true,
_ => false,
}matches!(self.kind, AssocKind::Type { data: AssocTypeData::Rpitit(_) })
163 }
164}
165
166#[derive(#[automatically_derived]
impl ::core::marker::Copy for AssocTypeData { }Copy, #[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::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)]
167pub enum AssocTypeData {
168 Normal(Symbol),
169 Rpitit(ty::ImplTraitInTraitData),
173}
174
175#[derive(#[automatically_derived]
impl ::core::marker::Copy for AssocKind { }Copy, #[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::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)]
176pub enum AssocKind {
177 Const { name: Symbol, is_type_const: bool },
178 Fn { name: Symbol, has_self: bool },
179 Type { data: AssocTypeData },
180}
181
182impl AssocKind {
183 pub fn namespace(&self) -> Namespace {
184 match self {
185 Self::Type { .. } => Namespace::TypeNS,
186 Self::Const { .. } | Self::Fn { .. } => Namespace::ValueNS,
187 }
188 }
189
190 pub fn tag(&self) -> AssocTag {
191 match self {
192 Self::Const { .. } => AssocTag::Const,
193 Self::Fn { .. } => AssocTag::Fn,
194 Self::Type { .. } => AssocTag::Type,
195 }
196 }
197
198 pub fn as_def_kind(&self) -> DefKind {
199 match self {
200 Self::Const { is_type_const, .. } => {
201 DefKind::AssocConst { is_type_const: *is_type_const }
202 }
203 Self::Fn { .. } => DefKind::AssocFn,
204 Self::Type { .. } => DefKind::AssocTy,
205 }
206 }
207
208 pub fn descr(&self) -> &'static str {
209 match self {
210 Self::Fn { has_self: true, .. } => "method",
211 _ => self.tag().descr(),
212 }
213 }
214}
215
216impl std::fmt::Display for AssocKind {
217 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
218 f.write_str(self.descr())
219 }
220}
221
222#[derive(#[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::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)]
224pub enum AssocTag {
225 Const,
226 Fn,
227 Type,
228}
229
230impl AssocTag {
231 pub fn descr(self) -> &'static str {
232 match self {
234 Self::Const => "associated constant",
235 Self::Fn => "associated function",
236 Self::Type => "associated type",
237 }
238 }
239}
240
241#[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::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)]
247pub struct AssocItems {
248 items: SortedIndexMultiMap<u32, Option<Symbol>, ty::AssocItem>,
249}
250
251impl AssocItems {
252 pub fn new(items_in_def_order: impl IntoIterator<Item = ty::AssocItem>) -> Self {
254 let items = items_in_def_order.into_iter().map(|item| (item.opt_name(), item)).collect();
255 AssocItems { items }
256 }
257
258 pub fn in_definition_order(&self) -> impl '_ + Iterator<Item = &ty::AssocItem> {
263 self.items.iter().map(|(_, v)| v)
264 }
265
266 pub fn len(&self) -> usize {
267 self.items.len()
268 }
269
270 pub fn filter_by_name_unhygienic(
274 &self,
275 name: Symbol,
276 ) -> impl '_ + Iterator<Item = &ty::AssocItem> {
277 if !!name.is_empty() {
::core::panicking::panic("assertion failed: !name.is_empty()")
};assert!(!name.is_empty());
278 self.items.get_by_key(Some(name))
279 }
280
281 pub fn filter_by_name_unhygienic_and_kind(
284 &self,
285 name: Symbol,
286 assoc_tag: AssocTag,
287 ) -> impl '_ + Iterator<Item = &ty::AssocItem> {
288 self.filter_by_name_unhygienic(name).filter(move |item| item.tag() == assoc_tag)
289 }
290
291 pub fn find_by_ident_and_kind(
294 &self,
295 tcx: TyCtxt<'_>,
296 ident: Ident,
297 assoc_tag: AssocTag,
298 parent_def_id: DefId,
299 ) -> Option<&ty::AssocItem> {
300 self.filter_by_name_unhygienic(ident.name)
301 .filter(|item| item.tag() == assoc_tag)
302 .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
303 }
304
305 pub fn find_by_ident_and_namespace(
308 &self,
309 tcx: TyCtxt<'_>,
310 ident: Ident,
311 ns: Namespace,
312 parent_def_id: DefId,
313 ) -> Option<&ty::AssocItem> {
314 self.filter_by_name_unhygienic(ident.name)
315 .filter(|item| item.namespace() == ns)
316 .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
317 }
318}
319
320impl<'tcx> TyCtxt<'tcx> {
321 pub fn associated_types_for_impl_traits_in_associated_fn(
331 self,
332 fn_def_id: DefId,
333 ) -> &'tcx [DefId] {
334 let parent_def_id = self.parent(fn_def_id);
335 &self.associated_types_for_impl_traits_in_trait_or_impl(parent_def_id)[&fn_def_id]
336 }
337}