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, bug};
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::TraitImpl(__self_0), Self::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]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Trait => ::core::fmt::Formatter::write_str(f, "Trait"),
Self::InherentImpl =>
::core::fmt::Formatter::write_str(f, "InherentImpl"),
Self::TraitImpl(__self_0) =>
::core::fmt::Formatter::debug_struct_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) {
match *self {
AssocContainer::Trait => 0u8.stable_hash(__hcx, __hasher),
AssocContainer::InherentImpl =>
1u8.stable_hash(__hcx, __hasher),
AssocContainer::TraitImpl(ref __binding_0) =>
2u8.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) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"AssocItem def_id kind container", &self.def_id, &self.kind,
&&self.container)
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for AssocItem
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for AssocItem {
#[inline]
fn eq(&self, other: &Self) -> 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 { data: AssocConstData::Named(name), .. } => Some(name),
35 ty::AssocKind::Const { data: AssocConstData::Anonymous, .. } => None,
36 ty::AssocKind::Fn { name, .. } => Some(name),
37 }
38 }
39
40 pub fn name(&self) -> Symbol {
43 self.opt_name().expect("name of anonymous associated item")
44 }
45
46 pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
47 Ident::new(self.name(), tcx.def_ident_span(self.def_id).unwrap())
48 }
49
50 pub fn defaultness(&self, tcx: TyCtxt<'_>) -> hir::Defaultness {
56 match self.container {
57 AssocContainer::InherentImpl => hir::Defaultness::Final,
58 AssocContainer::Trait | AssocContainer::TraitImpl(_) => tcx.defaultness(self.def_id),
59 }
60 }
61
62 pub fn expect_trait_impl(&self) -> Result<DefId, ErrorGuaranteed> {
63 let AssocContainer::TraitImpl(trait_item_id) = self.container else {
64 ::rustc_span::macros::bug_impl(None,
format_args!("expected item to be in a trait impl: {0:?}", self.def_id),
Location::caller());bug!("expected item to be in a trait impl: {:?}", self.def_id);
65 };
66 trait_item_id
67 }
68
69 pub fn trait_item_or_self(&self) -> Result<DefId, ErrorGuaranteed> {
73 match self.container {
74 AssocContainer::TraitImpl(id) => id,
75 AssocContainer::Trait | AssocContainer::InherentImpl => Ok(self.def_id),
76 }
77 }
78
79 pub fn trait_item_def_id(&self) -> Option<DefId> {
80 match self.container {
81 AssocContainer::TraitImpl(Ok(id)) => Some(id),
82 _ => None,
83 }
84 }
85
86 #[inline]
87 pub fn visibility(&self, tcx: TyCtxt<'_>) -> Visibility<ModId> {
88 tcx.visibility(self.def_id)
89 }
90
91 #[inline]
92 pub fn container_id(&self, tcx: TyCtxt<'_>) -> DefId {
93 tcx.parent(self.def_id)
94 }
95
96 #[inline]
97 pub fn trait_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
98 match self.container {
99 AssocContainer::InherentImpl | AssocContainer::TraitImpl(_) => None,
100 AssocContainer::Trait => Some(tcx.parent(self.def_id)),
101 }
102 }
103
104 #[inline]
105 pub fn impl_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
106 match self.container {
107 AssocContainer::InherentImpl | AssocContainer::TraitImpl(_) => {
108 Some(tcx.parent(self.def_id))
109 }
110 AssocContainer::Trait => None,
111 }
112 }
113
114 pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
115 match self.kind {
116 ty::AssocKind::Fn { .. } => {
117 tcx.fn_sig(self.def_id).instantiate_identity().skip_binder().to_string()
122 }
123 ty::AssocKind::Type { .. } => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("type {0};", self.name()))
})format!("type {};", self.name()),
124 ty::AssocKind::Const { data, .. } => {
125 let name = match data {
126 AssocConstData::Named(name) => name,
127 AssocConstData::Anonymous => rustc_span::symbol::kw::Underscore,
128 };
129 ::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())
130 }
131 }
132 }
133
134 pub fn descr(&self) -> &'static str {
135 self.kind.descr()
136 }
137
138 pub fn namespace(&self) -> Namespace {
139 self.kind.namespace()
140 }
141
142 pub fn as_def_kind(&self) -> DefKind {
143 self.kind.as_def_kind()
144 }
145
146 pub fn can_have_equality_constraint(&self, tcx: TyCtxt<'_>) -> bool {
148 match self.kind {
149 ty::AssocKind::Type { .. } => true,
150 ty::AssocKind::Const { .. } => {
151 tcx.features().gca_const_items() || tcx.is_direct_const(self.def_id)
152 }
153 ty::AssocKind::Fn { .. } => false,
154 }
155 }
156
157 pub fn is_anon_const(&self) -> bool {
158 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Const { data: AssocConstData::Anonymous, .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Const { data: AssocConstData::Anonymous, .. })
159 }
160
161 pub fn is_fn(&self) -> bool {
162 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Fn { .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Fn { .. })
163 }
164
165 pub fn is_method(&self) -> bool {
166 #[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, .. })
167 }
168
169 pub fn is_type(&self) -> bool {
170 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
ty::AssocKind::Type { .. } => true,
_ => false,
}matches!(self.kind, ty::AssocKind::Type { .. })
171 }
172
173 pub fn tag(&self) -> AssocTag {
174 self.kind.tag()
175 }
176
177 pub fn is_impl_trait_in_trait(&self) -> bool {
178 #[allow(non_exhaustive_omitted_patterns)] match self.kind {
AssocKind::Type { data: AssocTypeData::Rpitit(_) } => true,
_ => false,
}matches!(self.kind, AssocKind::Type { data: AssocTypeData::Rpitit(_) })
179 }
180}
181
182#[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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Normal(__self_0), Self::Normal(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Rpitit(__self_0), Self::Rpitit(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::fmt::Debug for AssocTypeData {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Normal(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Normal", &__self_0),
Self::Rpitit(__self_0) =>
::core::fmt::Formatter::debug_struct_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) {
match *self {
AssocTypeData::Normal(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
AssocTypeData::Rpitit(ref __binding_0) =>
1u8.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) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Normal(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::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)]
183pub enum AssocTypeData {
184 Normal(Symbol),
185 Rpitit(ty::ImplTraitInTraitData),
189}
190
191#[derive(#[automatically_derived]impl ::core::marker::Copy for AssocConstData { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AssocConstData {
}
#[automatically_derived]impl ::core::clone::Clone for AssocConstData {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
AssocConstData {
}
#[automatically_derived]impl ::core::cmp::PartialEq for AssocConstData {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Named(__self_0), Self::Named(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::fmt::Debug for AssocConstData {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Named(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Named",
&__self_0),
Self::Anonymous =>
::core::fmt::Formatter::write_str(f, "Anonymous"),
}
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
AssocConstData {
#[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 {
AssocConstData::Named(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
AssocConstData::Anonymous =>
1u8.stable_hash(__hcx, __hasher),
}
match *self {
AssocConstData::Named(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
AssocConstData::Anonymous => {}
}
}
}
};StableHash, #[automatically_derived]impl ::core::cmp::Eq for AssocConstData {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq, #[automatically_derived]impl ::core::hash::Hash for AssocConstData {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Named(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for AssocConstData {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AssocConstData::Named(ref __binding_0) => { 0usize }
AssocConstData::Anonymous => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AssocConstData::Named(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
AssocConstData::Anonymous => {}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for AssocConstData {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
AssocConstData::Named(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => { AssocConstData::Anonymous }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AssocConstData`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable)]
192pub enum AssocConstData {
193 Named(Symbol),
194 Anonymous,
196}
197
198#[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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<AssocConstData>;
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: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Const { data: __self_0 }, Self::Const { data: __arg1_0
}) => __self_0 == __arg1_0,
(Self::Fn { name: __self_0, has_self: __self_1 }, Self::Fn {
name: __arg1_0, has_self: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Type { data: __self_0 }, Self::Type { data: __arg1_0 })
=> __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::fmt::Debug for AssocKind {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Const { data: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Const data", &__self_0),
Self::Fn { name: __self_0, has_self: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Fn name has_self", __self_0, &__self_1),
Self::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) {
match *self {
AssocKind::Const { data: ref __binding_0 } =>
0u8.stable_hash(__hcx, __hasher),
AssocKind::Fn {
name: ref __binding_0, has_self: ref __binding_1 } =>
1u8.stable_hash(__hcx, __hasher),
AssocKind::Type { data: ref __binding_0 } =>
2u8.stable_hash(__hcx, __hasher),
}
match *self {
AssocKind::Const { data: ref __binding_0 } => {
{ __binding_0.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<AssocConstData>;
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) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Const { data: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
Self::Fn { name: __self_0, has_self: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::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 { data: ref __binding_0 } => { 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 { data: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__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 {
data: ::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)]
199pub enum AssocKind {
200 Const { data: AssocConstData },
201 Fn { name: Symbol, has_self: bool },
202 Type { data: AssocTypeData },
203}
204
205impl AssocKind {
206 pub fn namespace(&self) -> Namespace {
207 match self {
208 Self::Type { .. } => Namespace::TypeNS,
209 Self::Const { .. } | Self::Fn { .. } => Namespace::ValueNS,
210 }
211 }
212
213 pub fn tag(&self) -> AssocTag {
214 match self {
215 Self::Const { .. } => AssocTag::Const,
216 Self::Fn { .. } => AssocTag::Fn,
217 Self::Type { .. } => AssocTag::Type,
218 }
219 }
220
221 pub fn as_def_kind(&self) -> DefKind {
222 match self {
223 Self::Const { .. } => DefKind::AssocConst,
224 Self::Fn { .. } => DefKind::AssocFn,
225 Self::Type { .. } => DefKind::AssocTy,
226 }
227 }
228
229 pub fn descr(&self) -> &'static str {
230 match self {
231 Self::Fn { has_self: true, .. } => "method",
232 _ => self.tag().descr(),
233 }
234 }
235}
236
237impl std::fmt::Display for AssocKind {
238 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
239 f.write_str(self.descr())
240 }
241}
242
243#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AssocTag {
}
#[automatically_derived]impl ::core::clone::Clone for AssocTag {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for AssocTag { }Copy, #[automatically_derived]impl ::core::fmt::Debug for AssocTag {
#[inline]
#[rustc_trivial_field_reads]
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: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for AssocTag { }Eq, #[automatically_derived]impl ::core::hash::Hash for AssocTag {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash)]
245pub enum AssocTag {
246 Const,
247 Fn,
248 Type,
249}
250
251impl AssocTag {
252 pub fn descr(self) -> &'static str {
253 match self {
255 Self::Const => "associated constant",
256 Self::Fn => "associated function",
257 Self::Type => "associated type",
258 }
259 }
260}
261
262#[derive(#[automatically_derived]impl ::core::fmt::Debug for AssocItems {
#[inline]
#[rustc_trivial_field_reads]
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]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
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: &Self) -> 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)]
268pub struct AssocItems {
269 items: SortedIndexMultiMap<u32, Option<Symbol>, ty::AssocItem>,
270}
271
272impl AssocItems {
273 pub fn new(items_in_def_order: impl IntoIterator<Item = ty::AssocItem>) -> Self {
275 let items = items_in_def_order.into_iter().map(|item| (item.opt_name(), item)).collect();
276 AssocItems { items }
277 }
278
279 pub fn in_definition_order(&self) -> impl '_ + Iterator<Item = &ty::AssocItem> {
284 self.items.iter().map(|(_, v)| v)
285 }
286
287 pub fn named_items_in_definition_order(&self) -> impl '_ + Iterator<Item = &ty::AssocItem> {
292 self.items.iter().filter_map(|(name, v)| name.is_some().then(|| v))
293 }
294
295 pub fn len(&self) -> usize {
296 self.items.len()
297 }
298
299 pub fn filter_by_name_unhygienic(
303 &self,
304 name: Symbol,
305 ) -> impl '_ + Iterator<Item = &ty::AssocItem> {
306 if !!name.is_empty() {
::core::panicking::panic("assertion failed: !name.is_empty()")
};assert!(!name.is_empty());
307 self.items.get_by_key(Some(name))
308 }
309
310 pub fn filter_by_name_unhygienic_and_kind(
313 &self,
314 name: Symbol,
315 assoc_tag: AssocTag,
316 ) -> impl '_ + Iterator<Item = &ty::AssocItem> {
317 self.filter_by_name_unhygienic(name).filter(move |item| item.tag() == assoc_tag)
318 }
319
320 pub fn find_by_ident_and_kind(
323 &self,
324 tcx: TyCtxt<'_>,
325 ident: Ident,
326 assoc_tag: AssocTag,
327 parent_def_id: DefId,
328 ) -> Option<&ty::AssocItem> {
329 self.filter_by_name_unhygienic(ident.name)
330 .filter(|item| item.tag() == assoc_tag)
331 .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
332 }
333
334 pub fn find_by_ident_and_namespace(
337 &self,
338 tcx: TyCtxt<'_>,
339 ident: Ident,
340 ns: Namespace,
341 parent_def_id: DefId,
342 ) -> Option<&ty::AssocItem> {
343 self.filter_by_name_unhygienic(ident.name)
344 .filter(|item| item.namespace() == ns)
345 .find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
346 }
347}
348
349impl<'tcx> TyCtxt<'tcx> {
350 pub fn associated_types_for_impl_traits_in_associated_fn(
360 self,
361 fn_def_id: DefId,
362 ) -> &'tcx [DefId] {
363 let parent_def_id = self.parent(fn_def_id);
364 &self.associated_types_for_impl_traits_in_trait_or_impl(parent_def_id)[&fn_def_id]
365 }
366}