1use std::array::IntoIter;
2use std::borrow::Cow;
3use std::fmt::Debug;
4
5use rustc_ast as ast;
6use rustc_ast::NodeId;
7use rustc_error_messages::{DiagArgValue, IntoDiagArg};
8use rustc_hir_id::HirId;
9use rustc_macros::{Decodable, Encodable, StableHash};
10use rustc_span::Symbol;
11use rustc_span::def_id::DefId;
12use rustc_span::hygiene::MacroKind;
13
14use crate as hir;
15use crate::definitions::DefPathData;
16
17#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for CtorOf { }
#[automatically_derived]
impl ::core::clone::Clone for CtorOf {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CtorOf { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for CtorOf { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CtorOf {
#[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 CtorOf { }Eq, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for CtorOf {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
CtorOf::Struct => { 0usize }
CtorOf::Variant => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for CtorOf {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { CtorOf::Struct }
1usize => { CtorOf::Variant }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `CtorOf`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable, #[automatically_derived]
impl ::core::hash::Hash for CtorOf {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for CtorOf {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
CtorOf::Struct => "Struct",
CtorOf::Variant => "Variant",
})
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for CtorOf {
#[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 { CtorOf::Struct => {} CtorOf::Variant => {} }
}
}
};StableHash)]
19pub enum CtorOf {
20 Struct,
22 Variant,
24}
25
26#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for CtorKind { }
#[automatically_derived]
impl ::core::clone::Clone for CtorKind {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CtorKind { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for CtorKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CtorKind {
#[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 CtorKind { }Eq, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for CtorKind {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
CtorKind::Fn => { 0usize }
CtorKind::Const => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for CtorKind {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { CtorKind::Fn }
1usize => { CtorKind::Const }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `CtorKind`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable, #[automatically_derived]
impl ::core::hash::Hash for CtorKind {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for CtorKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self { CtorKind::Fn => "Fn", CtorKind::Const => "Const", })
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for CtorKind {
#[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 { CtorKind::Fn => {} CtorKind::Const => {} }
}
}
};StableHash)]
28pub enum CtorKind {
29 Fn,
31 Const,
33}
34
35#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for MacroKinds { }
#[automatically_derived]
impl ::core::clone::Clone for MacroKinds {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MacroKinds { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for MacroKinds { }
#[automatically_derived]
impl ::core::cmp::PartialEq for MacroKinds {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for MacroKinds {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for MacroKinds {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for MacroKinds {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for MacroKinds {
fn encode(&self, __encoder: &mut __E) {
let MacroKinds(ref __binding_0) = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for MacroKinds {
fn decode(__decoder: &mut __D) -> Self {
MacroKinds(::rustc_serialize::Decodable::decode(__decoder))
}
}
};Decodable, #[automatically_derived]
impl ::core::hash::Hash for MacroKinds {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for MacroKinds {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "MacroKinds",
&&self.0)
}
}Debug)]
37#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for MacroKinds {
#[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 {
MacroKinds(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
38pub struct MacroKinds(u8);
39impl MacroKinds {
#[allow(deprecated, non_upper_case_globals,)]
pub const BANG: Self = Self::from_bits_retain(1 << 0);
#[allow(deprecated, non_upper_case_globals,)]
pub const ATTR: Self = Self::from_bits_retain(1 << 1);
#[allow(deprecated, non_upper_case_globals,)]
pub const DERIVE: Self = Self::from_bits_retain(1 << 2);
}
impl ::bitflags::Flags for MacroKinds {
const FLAGS: &'static [::bitflags::Flag<MacroKinds>] =
&[{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("BANG", MacroKinds::BANG)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("ATTR", MacroKinds::ATTR)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("DERIVE", MacroKinds::DERIVE)
}];
type Bits = u8;
fn bits(&self) -> u8 { MacroKinds::bits(self) }
fn from_bits_retain(bits: u8) -> MacroKinds {
MacroKinds::from_bits_retain(bits)
}
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: iter_without_into_iter,)]
const _: () =
{
#[allow(dead_code, deprecated, unused_attributes)]
impl MacroKinds {
#[inline]
pub const fn empty() -> Self {
Self(<u8 as ::bitflags::Bits>::EMPTY)
}
#[inline]
pub const fn all() -> Self {
let mut truncated = <u8 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
<MacroKinds as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<MacroKinds as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<MacroKinds as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
let _ = i;
Self(truncated)
}
#[inline]
pub const fn bits(&self) -> u8 { self.0 }
#[inline]
pub const fn from_bits(bits: u8)
-> ::bitflags::__private::core::option::Option<Self> {
let truncated = Self::from_bits_truncate(bits).0;
if truncated == bits {
::bitflags::__private::core::option::Option::Some(Self(bits))
} else { ::bitflags::__private::core::option::Option::None }
}
#[inline]
pub const fn from_bits_truncate(bits: u8) -> Self {
Self(bits & Self::all().0)
}
#[inline]
pub const fn from_bits_retain(bits: u8) -> Self { Self(bits) }
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
{
if name == "BANG" {
return ::bitflags::__private::core::option::Option::Some(Self(MacroKinds::BANG.bits()));
}
};
;
{
if name == "ATTR" {
return ::bitflags::__private::core::option::Option::Some(Self(MacroKinds::ATTR.bits()));
}
};
;
{
if name == "DERIVE" {
return ::bitflags::__private::core::option::Option::Some(Self(MacroKinds::DERIVE.bits()));
}
};
;
let _ = name;
::bitflags::__private::core::option::Option::None
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.0 == <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn is_all(&self) -> bool {
Self::all().0 | self.0 == self.0
}
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0 & other.0 != <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0 & other.0 == other.0
}
#[inline]
pub fn insert(&mut self, other: Self) {
*self = Self(self.0).union(other);
}
#[inline]
pub fn remove(&mut self, other: Self) {
*self = Self(self.0).difference(other);
}
#[inline]
pub fn toggle(&mut self, other: Self) {
*self = Self(self.0).symmetric_difference(other);
}
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0 ^ other.0)
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self::from_bits_truncate(!self.0)
}
}
impl ::bitflags::__private::core::fmt::Binary for MacroKinds {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for MacroKinds {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for MacroKinds {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for MacroKinds {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for MacroKinds {
type Output = Self;
#[inline]
fn bitor(self, other: MacroKinds) -> Self { self.union(other) }
}
impl ::bitflags::__private::core::ops::BitOrAssign for MacroKinds {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for MacroKinds {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for MacroKinds {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for MacroKinds {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for MacroKinds {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for MacroKinds {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for MacroKinds {
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for MacroKinds {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<MacroKinds> for
MacroKinds {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<MacroKinds> for
MacroKinds {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl MacroKinds {
#[inline]
pub const fn iter(&self) -> ::bitflags::iter::Iter<MacroKinds> {
::bitflags::iter::Iter::__private_const_new(<MacroKinds as
::bitflags::Flags>::FLAGS,
MacroKinds::from_bits_retain(self.bits()),
MacroKinds::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<MacroKinds> {
::bitflags::iter::IterNames::__private_const_new(<MacroKinds
as ::bitflags::Flags>::FLAGS,
MacroKinds::from_bits_retain(self.bits()),
MacroKinds::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for MacroKinds {
type Item = MacroKinds;
type IntoIter = ::bitflags::iter::Iter<MacroKinds>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
};bitflags::bitflags! {
40 impl MacroKinds: u8 {
41 const BANG = 1 << 0;
42 const ATTR = 1 << 1;
43 const DERIVE = 1 << 2;
44 }
45}
46
47impl From<MacroKind> for MacroKinds {
48 fn from(kind: MacroKind) -> Self {
49 match kind {
50 MacroKind::Bang => Self::BANG,
51 MacroKind::Attr => Self::ATTR,
52 MacroKind::Derive => Self::DERIVE,
53 }
54 }
55}
56
57impl MacroKinds {
58 pub const ATTR_BANG: MacroKinds = MacroKinds::ATTR.union(MacroKinds::BANG);
61 pub const DERIVE_BANG: MacroKinds = MacroKinds::DERIVE.union(MacroKinds::BANG);
63 pub const DERIVE_ATTR: MacroKinds = MacroKinds::DERIVE.union(MacroKinds::ATTR);
65 pub const DERIVE_ATTR_BANG: MacroKinds =
67 MacroKinds::DERIVE.union(MacroKinds::ATTR).union(MacroKinds::BANG);
68
69 pub fn descr(self) -> &'static str {
73 match self {
74 Self::BANG => "macro",
76 Self::ATTR => "attribute macro",
77 Self::DERIVE => "derive macro",
78 Self::ATTR_BANG => "attribute/function macro",
79 Self::DERIVE_BANG => "derive/function macro",
80 Self::DERIVE_ATTR => "attribute/derive macro",
81 Self::DERIVE_ATTR_BANG => "attribute/derive/function macro",
82 _ if self.is_empty() => "useless macro",
83 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
84 }
85 }
86
87 pub fn article(self) -> &'static str {
89 if self.contains(Self::ATTR) { "an" } else { "a" }
90 }
91}
92
93#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for NonMacroAttrKind { }
#[automatically_derived]
impl ::core::clone::Clone for NonMacroAttrKind {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for NonMacroAttrKind { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for NonMacroAttrKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for NonMacroAttrKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Builtin(__self_0), Self::Builtin(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for NonMacroAttrKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for NonMacroAttrKind {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
NonMacroAttrKind::Builtin(ref __binding_0) => { 0usize }
NonMacroAttrKind::Tool => { 1usize }
NonMacroAttrKind::DeriveHelper => { 2usize }
NonMacroAttrKind::DeriveHelperCompat => { 3usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
NonMacroAttrKind::Builtin(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
NonMacroAttrKind::Tool => {}
NonMacroAttrKind::DeriveHelper => {}
NonMacroAttrKind::DeriveHelperCompat => {}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for NonMacroAttrKind {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
NonMacroAttrKind::Builtin(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => { NonMacroAttrKind::Tool }
2usize => { NonMacroAttrKind::DeriveHelper }
3usize => { NonMacroAttrKind::DeriveHelperCompat }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `NonMacroAttrKind`, expected 0..4, actual {0}",
n));
}
}
}
}
};Decodable, #[automatically_derived]
impl ::core::hash::Hash for NonMacroAttrKind {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Builtin(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for NonMacroAttrKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Builtin(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Builtin", &__self_0),
Self::Tool => ::core::fmt::Formatter::write_str(f, "Tool"),
Self::DeriveHelper =>
::core::fmt::Formatter::write_str(f, "DeriveHelper"),
Self::DeriveHelperCompat =>
::core::fmt::Formatter::write_str(f, "DeriveHelperCompat"),
}
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
NonMacroAttrKind {
#[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 {
NonMacroAttrKind::Builtin(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
NonMacroAttrKind::Tool => {}
NonMacroAttrKind::DeriveHelper => {}
NonMacroAttrKind::DeriveHelperCompat => {}
}
}
}
};StableHash)]
95pub enum NonMacroAttrKind {
96 Builtin(Symbol),
98 Tool,
100 DeriveHelper,
102 DeriveHelperCompat,
105}
106
107#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for DefKind { }
#[automatically_derived]
impl ::core::clone::Clone for DefKind {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<hir::Safety>;
let _: ::core::clone::AssertParamIsClone<ast::Mutability>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<CtorOf>;
let _: ::core::clone::AssertParamIsClone<CtorKind>;
let _: ::core::clone::AssertParamIsClone<MacroKinds>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DefKind { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for DefKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for DefKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Static {
safety: __self_0, mutability: __self_1, nested: __self_2 },
Self::Static {
safety: __arg1_0, mutability: __arg1_1, nested: __arg1_2 })
=>
__self_2 == __arg1_2 && __self_0 == __arg1_0 &&
__self_1 == __arg1_1,
(Self::Ctor(__self_0, __self_1),
Self::Ctor(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::Macro(__self_0), Self::Macro(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Impl { of_trait: __self_0 }, Self::Impl {
of_trait: __arg1_0 }) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DefKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<hir::Safety>;
let _: ::core::cmp::AssertParamIsEq<ast::Mutability>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<CtorOf>;
let _: ::core::cmp::AssertParamIsEq<CtorKind>;
let _: ::core::cmp::AssertParamIsEq<MacroKinds>;
}
}Eq, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for DefKind {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
DefKind::Mod => { 0usize }
DefKind::Struct => { 1usize }
DefKind::Union => { 2usize }
DefKind::Enum => { 3usize }
DefKind::Variant => { 4usize }
DefKind::Trait => { 5usize }
DefKind::TyAlias => { 6usize }
DefKind::ForeignTy => { 7usize }
DefKind::TraitAlias => { 8usize }
DefKind::AssocTy => { 9usize }
DefKind::TyParam => { 10usize }
DefKind::Fn => { 11usize }
DefKind::Const => { 12usize }
DefKind::ConstParam => { 13usize }
DefKind::Static {
safety: ref __binding_0,
mutability: ref __binding_1,
nested: ref __binding_2 } => {
14usize
}
DefKind::Ctor(ref __binding_0, ref __binding_1) => {
15usize
}
DefKind::AssocFn => { 16usize }
DefKind::AssocConst => { 17usize }
DefKind::Macro(ref __binding_0) => { 18usize }
DefKind::ExternCrate => { 19usize }
DefKind::Use => { 20usize }
DefKind::ForeignMod => { 21usize }
DefKind::AnonConst => { 22usize }
DefKind::OpaqueTy => { 23usize }
DefKind::Field => { 24usize }
DefKind::LifetimeParam => { 25usize }
DefKind::GlobalAsm => { 26usize }
DefKind::Impl { of_trait: ref __binding_0 } => { 27usize }
DefKind::Closure => { 28usize }
DefKind::SyntheticCoroutineBody => { 29usize }
DefKind::TestBinderConstraints => { 30usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
DefKind::Mod => {}
DefKind::Struct => {}
DefKind::Union => {}
DefKind::Enum => {}
DefKind::Variant => {}
DefKind::Trait => {}
DefKind::TyAlias => {}
DefKind::ForeignTy => {}
DefKind::TraitAlias => {}
DefKind::AssocTy => {}
DefKind::TyParam => {}
DefKind::Fn => {}
DefKind::Const => {}
DefKind::ConstParam => {}
DefKind::Static {
safety: ref __binding_0,
mutability: ref __binding_1,
nested: 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);
}
DefKind::Ctor(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
DefKind::AssocFn => {}
DefKind::AssocConst => {}
DefKind::Macro(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefKind::ExternCrate => {}
DefKind::Use => {}
DefKind::ForeignMod => {}
DefKind::AnonConst => {}
DefKind::OpaqueTy => {}
DefKind::Field => {}
DefKind::LifetimeParam => {}
DefKind::GlobalAsm => {}
DefKind::Impl { of_trait: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefKind::Closure => {}
DefKind::SyntheticCoroutineBody => {}
DefKind::TestBinderConstraints => {}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for DefKind {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { DefKind::Mod }
1usize => { DefKind::Struct }
2usize => { DefKind::Union }
3usize => { DefKind::Enum }
4usize => { DefKind::Variant }
5usize => { DefKind::Trait }
6usize => { DefKind::TyAlias }
7usize => { DefKind::ForeignTy }
8usize => { DefKind::TraitAlias }
9usize => { DefKind::AssocTy }
10usize => { DefKind::TyParam }
11usize => { DefKind::Fn }
12usize => { DefKind::Const }
13usize => { DefKind::ConstParam }
14usize => {
DefKind::Static {
safety: ::rustc_serialize::Decodable::decode(__decoder),
mutability: ::rustc_serialize::Decodable::decode(__decoder),
nested: ::rustc_serialize::Decodable::decode(__decoder),
}
}
15usize => {
DefKind::Ctor(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
16usize => { DefKind::AssocFn }
17usize => { DefKind::AssocConst }
18usize => {
DefKind::Macro(::rustc_serialize::Decodable::decode(__decoder))
}
19usize => { DefKind::ExternCrate }
20usize => { DefKind::Use }
21usize => { DefKind::ForeignMod }
22usize => { DefKind::AnonConst }
23usize => { DefKind::OpaqueTy }
24usize => { DefKind::Field }
25usize => { DefKind::LifetimeParam }
26usize => { DefKind::GlobalAsm }
27usize => {
DefKind::Impl {
of_trait: ::rustc_serialize::Decodable::decode(__decoder),
}
}
28usize => { DefKind::Closure }
29usize => { DefKind::SyntheticCoroutineBody }
30usize => { DefKind::TestBinderConstraints }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `DefKind`, expected 0..31, actual {0}",
n));
}
}
}
}
};Decodable, #[automatically_derived]
impl ::core::hash::Hash for DefKind {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Static {
safety: __self_0, mutability: __self_1, nested: __self_2 } =>
{
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state)
}
Self::Ctor(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::Macro(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Impl { of_trait: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for DefKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Mod => ::core::fmt::Formatter::write_str(f, "Mod"),
Self::Struct => ::core::fmt::Formatter::write_str(f, "Struct"),
Self::Union => ::core::fmt::Formatter::write_str(f, "Union"),
Self::Enum => ::core::fmt::Formatter::write_str(f, "Enum"),
Self::Variant => ::core::fmt::Formatter::write_str(f, "Variant"),
Self::Trait => ::core::fmt::Formatter::write_str(f, "Trait"),
Self::TyAlias => ::core::fmt::Formatter::write_str(f, "TyAlias"),
Self::ForeignTy =>
::core::fmt::Formatter::write_str(f, "ForeignTy"),
Self::TraitAlias =>
::core::fmt::Formatter::write_str(f, "TraitAlias"),
Self::AssocTy => ::core::fmt::Formatter::write_str(f, "AssocTy"),
Self::TyParam => ::core::fmt::Formatter::write_str(f, "TyParam"),
Self::Fn => ::core::fmt::Formatter::write_str(f, "Fn"),
Self::Const => ::core::fmt::Formatter::write_str(f, "Const"),
Self::ConstParam =>
::core::fmt::Formatter::write_str(f, "ConstParam"),
Self::Static {
safety: __self_0, mutability: __self_1, nested: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Static", "safety", __self_0, "mutability", __self_1,
"nested", &__self_2),
Self::Ctor(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Ctor",
__self_0, &__self_1),
Self::AssocFn => ::core::fmt::Formatter::write_str(f, "AssocFn"),
Self::AssocConst =>
::core::fmt::Formatter::write_str(f, "AssocConst"),
Self::Macro(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Macro",
&__self_0),
Self::ExternCrate =>
::core::fmt::Formatter::write_str(f, "ExternCrate"),
Self::Use => ::core::fmt::Formatter::write_str(f, "Use"),
Self::ForeignMod =>
::core::fmt::Formatter::write_str(f, "ForeignMod"),
Self::AnonConst =>
::core::fmt::Formatter::write_str(f, "AnonConst"),
Self::OpaqueTy =>
::core::fmt::Formatter::write_str(f, "OpaqueTy"),
Self::Field => ::core::fmt::Formatter::write_str(f, "Field"),
Self::LifetimeParam =>
::core::fmt::Formatter::write_str(f, "LifetimeParam"),
Self::GlobalAsm =>
::core::fmt::Formatter::write_str(f, "GlobalAsm"),
Self::Impl { of_trait: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Impl",
"of_trait", &__self_0),
Self::Closure => ::core::fmt::Formatter::write_str(f, "Closure"),
Self::SyntheticCoroutineBody =>
::core::fmt::Formatter::write_str(f,
"SyntheticCoroutineBody"),
Self::TestBinderConstraints =>
::core::fmt::Formatter::write_str(f, "TestBinderConstraints"),
}
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for DefKind {
#[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 {
DefKind::Mod => {}
DefKind::Struct => {}
DefKind::Union => {}
DefKind::Enum => {}
DefKind::Variant => {}
DefKind::Trait => {}
DefKind::TyAlias => {}
DefKind::ForeignTy => {}
DefKind::TraitAlias => {}
DefKind::AssocTy => {}
DefKind::TyParam => {}
DefKind::Fn => {}
DefKind::Const => {}
DefKind::ConstParam => {}
DefKind::Static {
safety: ref __binding_0,
mutability: ref __binding_1,
nested: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
DefKind::Ctor(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
DefKind::AssocFn => {}
DefKind::AssocConst => {}
DefKind::Macro(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
DefKind::ExternCrate => {}
DefKind::Use => {}
DefKind::ForeignMod => {}
DefKind::AnonConst => {}
DefKind::OpaqueTy => {}
DefKind::Field => {}
DefKind::LifetimeParam => {}
DefKind::GlobalAsm => {}
DefKind::Impl { of_trait: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
DefKind::Closure => {}
DefKind::SyntheticCoroutineBody => {}
DefKind::TestBinderConstraints => {}
}
}
}
};StableHash)]
110pub enum DefKind {
111 Mod,
113 Struct,
115 Union,
116 Enum,
117 Variant,
119 Trait,
120 TyAlias,
122 ForeignTy,
124 TraitAlias,
126 AssocTy,
128 TyParam,
130
131 Fn,
133 Const,
134 ConstParam,
136 Static {
137 safety: hir::Safety,
139 mutability: ast::Mutability,
141 nested: bool,
143 },
144 Ctor(CtorOf, CtorKind),
161 AssocFn,
164 AssocConst,
166
167 Macro(MacroKinds),
169
170 ExternCrate,
172 Use,
173 ForeignMod,
175 AnonConst,
187 OpaqueTy,
189 Field,
193 LifetimeParam,
195 GlobalAsm,
197 Impl {
198 of_trait: bool,
199 },
200 Closure,
207 SyntheticCoroutineBody,
210 TestBinderConstraints,
212}
213
214impl DefKind {
215 pub fn descr(self, def_id: DefId) -> &'static str {
221 match self {
222 DefKind::Fn => "function",
223 DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
224 DefKind::Mod => "module",
225 DefKind::Static { .. } => "static",
226 DefKind::Enum => "enum",
227 DefKind::Variant => "variant",
228 DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant",
229 DefKind::Ctor(CtorOf::Variant, CtorKind::Const) => "unit variant",
230 DefKind::Struct => "struct",
231 DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct",
232 DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct",
233 DefKind::OpaqueTy => "opaque type",
234 DefKind::TyAlias => "type alias",
235 DefKind::TraitAlias => "trait alias",
236 DefKind::AssocTy => "associated type",
237 DefKind::Union => "union",
238 DefKind::Trait => "trait",
239 DefKind::ForeignTy => "foreign type",
240 DefKind::AssocFn => "associated function",
241 DefKind::Const => "constant",
242 DefKind::AssocConst => "associated constant",
243 DefKind::TyParam => "type parameter",
244 DefKind::ConstParam => "const parameter",
245 DefKind::Macro(kinds) => kinds.descr(),
246 DefKind::LifetimeParam => "lifetime parameter",
247 DefKind::Use => "import",
248 DefKind::ForeignMod => "foreign module",
249 DefKind::AnonConst => "constant expression",
250 DefKind::Field => "field",
251 DefKind::Impl { .. } => "implementation",
252 DefKind::Closure => "closure",
253 DefKind::ExternCrate => "extern crate",
254 DefKind::GlobalAsm => "global assembly block",
255 DefKind::SyntheticCoroutineBody => "synthetic mir body",
256 DefKind::TestBinderConstraints => "test_binder_constraints!",
257 }
258 }
259
260 pub fn article(&self) -> &'static str {
266 match *self {
267 DefKind::AssocTy
268 | DefKind::AssocConst
269 | DefKind::AssocFn
270 | DefKind::Enum
271 | DefKind::OpaqueTy
272 | DefKind::Impl { .. }
273 | DefKind::Use
274 | DefKind::ExternCrate => "an",
275 DefKind::Macro(kinds) => kinds.article(),
276 _ => "a",
277 }
278 }
279
280 pub fn ns(&self) -> Option<Namespace> {
281 match self {
282 DefKind::Mod
283 | DefKind::Struct
284 | DefKind::Union
285 | DefKind::Enum
286 | DefKind::Variant
287 | DefKind::Trait
288 | DefKind::TyAlias
289 | DefKind::ForeignTy
290 | DefKind::TraitAlias
291 | DefKind::AssocTy
292 | DefKind::TyParam => Some(Namespace::TypeNS),
293
294 DefKind::Fn
295 | DefKind::Const
296 | DefKind::ConstParam
297 | DefKind::Static { .. }
298 | DefKind::Ctor(..)
299 | DefKind::AssocFn
300 | DefKind::AssocConst => Some(Namespace::ValueNS),
301
302 DefKind::Macro(..) => Some(Namespace::MacroNS),
303
304 DefKind::AnonConst
306 | DefKind::Field
307 | DefKind::LifetimeParam
308 | DefKind::ExternCrate
309 | DefKind::Closure
310 | DefKind::Use
311 | DefKind::ForeignMod
312 | DefKind::GlobalAsm
313 | DefKind::Impl { .. }
314 | DefKind::OpaqueTy
315 | DefKind::SyntheticCoroutineBody
316 | DefKind::TestBinderConstraints => None,
317 }
318 }
319
320 pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData {
323 match self {
324 DefKind::Mod
325 | DefKind::Struct
326 | DefKind::Union
327 | DefKind::Enum
328 | DefKind::Variant
329 | DefKind::Trait
330 | DefKind::TyAlias
331 | DefKind::ForeignTy
332 | DefKind::TraitAlias
333 | DefKind::TyParam
334 | DefKind::ExternCrate => DefPathData::TypeNs(name.unwrap()),
335
336 DefKind::AssocTy => DefPathData::TypeNs(name.unwrap()),
339
340 DefKind::Fn
341 | DefKind::Const
342 | DefKind::ConstParam
343 | DefKind::Static { .. }
344 | DefKind::AssocFn
345 | DefKind::AssocConst
346 | DefKind::Field => DefPathData::ValueNs(name.unwrap()),
347 DefKind::Macro(..) => DefPathData::MacroNs(name.unwrap()),
348 DefKind::LifetimeParam => DefPathData::LifetimeNs(name.unwrap()),
349 DefKind::Ctor(..) => DefPathData::Ctor,
350 DefKind::Use => DefPathData::Use,
351 DefKind::ForeignMod => DefPathData::ForeignMod,
352 DefKind::AnonConst => DefPathData::AnonConst,
353 DefKind::OpaqueTy => DefPathData::OpaqueTy,
354 DefKind::GlobalAsm => DefPathData::GlobalAsm,
355 DefKind::Impl { .. } => DefPathData::Impl,
356 DefKind::Closure => DefPathData::Closure,
357 DefKind::SyntheticCoroutineBody => DefPathData::SyntheticCoroutineBody,
358 DefKind::TestBinderConstraints => DefPathData::TestBinderConstraints,
359 }
360 }
361
362 pub fn is_assoc(self) -> bool {
363 #[allow(non_exhaustive_omitted_patterns)] match self {
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
_ => false,
}matches!(self, DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy)
364 }
365
366 #[inline]
368 pub fn is_module_like(self) -> bool {
369 #[allow(non_exhaustive_omitted_patterns)] match self {
DefKind::Mod | DefKind::Enum | DefKind::Trait => true,
_ => false,
}matches!(self, DefKind::Mod | DefKind::Enum | DefKind::Trait)
370 }
371
372 #[inline]
373 pub fn is_adt(self) -> bool {
374 #[allow(non_exhaustive_omitted_patterns)] match self {
DefKind::Struct | DefKind::Union | DefKind::Enum => true,
_ => false,
}matches!(self, DefKind::Struct | DefKind::Union | DefKind::Enum)
375 }
376
377 #[inline]
378 pub fn is_fn_like(self) -> bool {
379 #[allow(non_exhaustive_omitted_patterns)] match self {
DefKind::Fn | DefKind::AssocFn | DefKind::Closure |
DefKind::SyntheticCoroutineBody => true,
_ => false,
}matches!(
380 self,
381 DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::SyntheticCoroutineBody
382 )
383 }
384
385 pub fn has_generics(self) -> bool {
387 match self {
388 DefKind::AnonConst
389 | DefKind::AssocConst
390 | DefKind::AssocFn
391 | DefKind::AssocTy
392 | DefKind::Closure
393 | DefKind::Const
394 | DefKind::Ctor(..)
395 | DefKind::Enum
396 | DefKind::Field
397 | DefKind::Fn
398 | DefKind::ForeignTy
399 | DefKind::Impl { .. }
400 | DefKind::OpaqueTy
401 | DefKind::Static { .. }
402 | DefKind::Struct
403 | DefKind::SyntheticCoroutineBody
404 | DefKind::Trait
405 | DefKind::TraitAlias
406 | DefKind::TyAlias
407 | DefKind::Union
408 | DefKind::Variant
409 | DefKind::TestBinderConstraints => true,
410 DefKind::ConstParam
411 | DefKind::ExternCrate
412 | DefKind::ForeignMod
413 | DefKind::GlobalAsm
414 | DefKind::LifetimeParam
415 | DefKind::Macro(_)
416 | DefKind::Mod
417 | DefKind::TyParam
418 | DefKind::Use => false,
419 }
420 }
421
422 pub fn has_codegen_attrs(self) -> bool {
424 match self {
425 DefKind::Fn
426 | DefKind::AssocFn
427 | DefKind::Ctor(..)
428 | DefKind::Closure
429 | DefKind::Static { .. }
430 | DefKind::SyntheticCoroutineBody => true,
431 DefKind::Mod
432 | DefKind::Struct
433 | DefKind::Union
434 | DefKind::Enum
435 | DefKind::Variant
436 | DefKind::Trait
437 | DefKind::TyAlias
438 | DefKind::ForeignTy
439 | DefKind::TraitAlias
440 | DefKind::AssocTy
441 | DefKind::Const
442 | DefKind::AssocConst
443 | DefKind::Macro(..)
444 | DefKind::Use
445 | DefKind::ForeignMod
446 | DefKind::OpaqueTy
447 | DefKind::Impl { .. }
448 | DefKind::Field
449 | DefKind::TyParam
450 | DefKind::ConstParam
451 | DefKind::LifetimeParam
452 | DefKind::AnonConst
453 | DefKind::GlobalAsm
454 | DefKind::ExternCrate
455 | DefKind::TestBinderConstraints => false,
456 }
457 }
458}
459
460#[derive(#[automatically_derived]
impl<Id: ::core::clone::Clone> ::core::clone::Clone for Res<Id> {
#[inline]
fn clone(&self) -> Self {
match self {
Self::Def(__self_0, __self_1) =>
Self::Def(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1)),
Self::PrimTy(__self_0) =>
Self::PrimTy(::core::clone::Clone::clone(__self_0)),
Self::SelfTyParam { trait_: __self_0 } =>
Self::SelfTyParam {
trait_: ::core::clone::Clone::clone(__self_0),
},
Self::SelfTyAlias { alias_to: __self_0, is_trait_impl: __self_1 }
=>
Self::SelfTyAlias {
alias_to: ::core::clone::Clone::clone(__self_0),
is_trait_impl: ::core::clone::Clone::clone(__self_1),
},
Self::SelfCtor(__self_0) =>
Self::SelfCtor(::core::clone::Clone::clone(__self_0)),
Self::Local(__self_0) =>
Self::Local(::core::clone::Clone::clone(__self_0)),
Self::ToolMod => Self::ToolMod,
Self::OpenMod(__self_0) =>
Self::OpenMod(::core::clone::Clone::clone(__self_0)),
Self::NonMacroAttr(__self_0) =>
Self::NonMacroAttr(::core::clone::Clone::clone(__self_0)),
Self::Err => Self::Err,
}
}
}Clone, #[automatically_derived]
impl<Id: ::core::marker::Copy> ::core::marker::Copy for Res<Id> { }Copy, #[automatically_derived]
impl<Id: ::core::cmp::PartialEq> ::core::marker::StructuralPartialEq for
Res<Id> {
}
#[automatically_derived]
impl<Id: ::core::cmp::PartialEq> ::core::cmp::PartialEq for Res<Id> {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Def(__self_0, __self_1), Self::Def(__arg1_0, __arg1_1))
=> __self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::PrimTy(__self_0), Self::PrimTy(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::SelfTyParam { trait_: __self_0 }, Self::SelfTyParam {
trait_: __arg1_0 }) => __self_0 == __arg1_0,
(Self::SelfTyAlias {
alias_to: __self_0, is_trait_impl: __self_1 },
Self::SelfTyAlias {
alias_to: __arg1_0, is_trait_impl: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::SelfCtor(__self_0), Self::SelfCtor(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Local(__self_0), Self::Local(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::OpenMod(__self_0), Self::OpenMod(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::NonMacroAttr(__self_0), Self::NonMacroAttr(__arg1_0))
=> __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<Id: ::core::cmp::Eq> ::core::cmp::Eq for Res<Id> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefKind>;
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<hir::PrimTy>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Id>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
let _: ::core::cmp::AssertParamIsEq<NonMacroAttrKind>;
}
}Eq, const _: () =
{
impl<Id, __E: ::rustc_span::SpanEncoder>
::rustc_serialize::Encodable<__E> for Res<Id> where
Id: ::rustc_serialize::Encodable<__E> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
Res::Def(ref __binding_0, ref __binding_1) => { 0usize }
Res::PrimTy(ref __binding_0) => { 1usize }
Res::SelfTyParam { trait_: ref __binding_0 } => { 2usize }
Res::SelfTyAlias {
alias_to: ref __binding_0, is_trait_impl: ref __binding_1 }
=> {
3usize
}
Res::SelfCtor(ref __binding_0) => { 4usize }
Res::Local(ref __binding_0) => { 5usize }
Res::ToolMod => { 6usize }
Res::OpenMod(ref __binding_0) => { 7usize }
Res::NonMacroAttr(ref __binding_0) => { 8usize }
Res::Err => { 9usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
Res::Def(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
Res::PrimTy(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
Res::SelfTyParam { trait_: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
Res::SelfTyAlias {
alias_to: ref __binding_0, is_trait_impl: ref __binding_1 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
Res::SelfCtor(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
Res::Local(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
Res::ToolMod => {}
Res::OpenMod(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
Res::NonMacroAttr(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
Res::Err => {}
}
}
}
};Encodable, const _: () =
{
impl<Id, __D: ::rustc_span::SpanDecoder>
::rustc_serialize::Decodable<__D> for Res<Id> where
Id: ::rustc_serialize::Decodable<__D> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
Res::Def(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
Res::PrimTy(::rustc_serialize::Decodable::decode(__decoder))
}
2usize => {
Res::SelfTyParam {
trait_: ::rustc_serialize::Decodable::decode(__decoder),
}
}
3usize => {
Res::SelfTyAlias {
alias_to: ::rustc_serialize::Decodable::decode(__decoder),
is_trait_impl: ::rustc_serialize::Decodable::decode(__decoder),
}
}
4usize => {
Res::SelfCtor(::rustc_serialize::Decodable::decode(__decoder))
}
5usize => {
Res::Local(::rustc_serialize::Decodable::decode(__decoder))
}
6usize => { Res::ToolMod }
7usize => {
Res::OpenMod(::rustc_serialize::Decodable::decode(__decoder))
}
8usize => {
Res::NonMacroAttr(::rustc_serialize::Decodable::decode(__decoder))
}
9usize => { Res::Err }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Res`, expected 0..10, actual {0}",
n));
}
}
}
}
};Decodable, #[automatically_derived]
impl<Id: ::core::hash::Hash> ::core::hash::Hash for Res<Id> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Def(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::PrimTy(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::SelfTyParam { trait_: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
Self::SelfTyAlias { alias_to: __self_0, is_trait_impl: __self_1 }
=> {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::SelfCtor(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Local(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::OpenMod(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::NonMacroAttr(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, #[automatically_derived]
impl<Id: ::core::fmt::Debug> ::core::fmt::Debug for Res<Id> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Def(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Def",
__self_0, &__self_1),
Self::PrimTy(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "PrimTy",
&__self_0),
Self::SelfTyParam { trait_: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"SelfTyParam", "trait_", &__self_0),
Self::SelfTyAlias { alias_to: __self_0, is_trait_impl: __self_1 }
=>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"SelfTyAlias", "alias_to", __self_0, "is_trait_impl",
&__self_1),
Self::SelfCtor(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"SelfCtor", &__self_0),
Self::Local(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Local",
&__self_0),
Self::ToolMod => ::core::fmt::Formatter::write_str(f, "ToolMod"),
Self::OpenMod(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"OpenMod", &__self_0),
Self::NonMacroAttr(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"NonMacroAttr", &__self_0),
Self::Err => ::core::fmt::Formatter::write_str(f, "Err"),
}
}
}Debug, const _: () =
{
impl<Id> ::rustc_data_structures::stable_hash::StableHash for Res<Id>
where Id: ::rustc_data_structures::stable_hash::StableHash {
#[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 {
Res::Def(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
Res::PrimTy(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Res::SelfTyParam { trait_: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Res::SelfTyAlias {
alias_to: ref __binding_0, is_trait_impl: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
Res::SelfCtor(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Res::Local(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Res::ToolMod => {}
Res::OpenMod(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Res::NonMacroAttr(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Res::Err => {}
}
}
}
};StableHash)]
489pub enum Res<Id = HirId> {
490 Def(DefKind, DefId),
494
495 PrimTy(hir::PrimTy),
500
501 SelfTyParam {
507 trait_: DefId,
509 },
510
511 SelfTyAlias {
540 alias_to: DefId,
543
544 is_trait_impl: bool,
546 },
547
548 SelfCtor(DefId),
556
557 Local(Id),
561
562 ToolMod,
566
567 OpenMod(Symbol),
573
574 NonMacroAttr(NonMacroAttrKind), Err,
588}
589
590impl Res {
591 pub fn in_namespace(self) -> PerNS<Option<Res>> {
592 match self {
593 Res::Def(DefKind::Mod | DefKind::Trait, _) => {
594 PerNS { type_ns: Some(self), value_ns: None, macro_ns: None }
595 }
596 Res::Def(DefKind::Enum, _) => {
597 PerNS { type_ns: None, value_ns: Some(self), macro_ns: None }
598 }
599 Res::Err => {
600 let err = Some(Res::Err);
602 PerNS { type_ns: err, value_ns: err, macro_ns: err }
603 }
604 _ => {
::core::panicking::panic_fmt(format_args!("bad path segment res {0:?}",
self));
}panic!("bad path segment res {self:?}"),
605 }
606 }
607}
608
609impl<Id> IntoDiagArg for Res<Id> {
610 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
611 DiagArgValue::Str(Cow::Borrowed(self.descr()))
612 }
613}
614
615#[derive(#[automatically_derived]
impl ::core::marker::Copy for Namespace { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Namespace { }
#[automatically_derived]
impl ::core::clone::Clone for Namespace {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Namespace { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Namespace {
#[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 Namespace { }Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Namespace {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Namespace {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other))
}
}Ord, #[automatically_derived]
impl ::core::hash::Hash for Namespace {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for Namespace {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Namespace::TypeNS => "TypeNS",
Namespace::ValueNS => "ValueNS",
Namespace::MacroNS => "MacroNS",
})
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for Namespace {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
Namespace::TypeNS => { 0usize }
Namespace::ValueNS => { 1usize }
Namespace::MacroNS => { 2usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for Namespace {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { Namespace::TypeNS }
1usize => { Namespace::ValueNS }
2usize => { Namespace::MacroNS }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Namespace`, expected 0..3, actual {0}",
n));
}
}
}
}
};Decodable)]
618#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Namespace {
#[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 {
Namespace::TypeNS => {}
Namespace::ValueNS => {}
Namespace::MacroNS => {}
}
}
}
};StableHash)]
619pub enum Namespace {
620 TypeNS,
626 ValueNS,
628 MacroNS,
632}
633
634impl Namespace {
635 pub fn descr(self) -> &'static str {
637 match self {
638 Self::TypeNS => "type",
639 Self::ValueNS => "value",
640 Self::MacroNS => "macro",
641 }
642 }
643}
644
645impl IntoDiagArg for Namespace {
646 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
647 DiagArgValue::Str(Cow::Borrowed(self.descr()))
648 }
649}
650
651#[derive(#[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for PerNS<T> { }Copy, #[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for PerNS<T> {
#[inline]
fn clone(&self) -> Self {
Self {
value_ns: ::core::clone::Clone::clone(&self.value_ns),
type_ns: ::core::clone::Clone::clone(&self.type_ns),
macro_ns: ::core::clone::Clone::clone(&self.macro_ns),
}
}
}Clone, #[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for PerNS<T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "PerNS",
"value_ns", &self.value_ns, "type_ns", &self.type_ns, "macro_ns",
&&self.macro_ns)
}
}Debug, const _: () =
{
impl<T> ::rustc_data_structures::stable_hash::StableHash for PerNS<T>
where T: ::rustc_data_structures::stable_hash::StableHash {
#[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 {
PerNS {
value_ns: ref __binding_0,
type_ns: ref __binding_1,
macro_ns: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
653#[derive_const(#[automatically_derived]
const impl<T: [const] ::core::default::Default> ::core::default::Default for
PerNS<T> {
#[inline]
fn default() -> Self {
Self {
value_ns: ::core::default::Default::default(),
type_ns: ::core::default::Default::default(),
macro_ns: ::core::default::Default::default(),
}
}
}Default)]
654pub struct PerNS<T> {
655 pub value_ns: T,
656 pub type_ns: T,
657 pub macro_ns: T,
658}
659
660impl<T> PerNS<T> {
661 pub fn map<U, F: FnMut(T) -> U>(self, mut f: F) -> PerNS<U> {
662 PerNS { value_ns: f(self.value_ns), type_ns: f(self.type_ns), macro_ns: f(self.macro_ns) }
663 }
664
665 pub fn into_iter(self) -> IntoIter<T, 3> {
669 [self.value_ns, self.type_ns, self.macro_ns].into_iter()
670 }
671
672 pub fn iter(&self) -> IntoIter<&T, 3> {
676 [&self.value_ns, &self.type_ns, &self.macro_ns].into_iter()
677 }
678}
679
680impl<T> ::std::ops::Index<Namespace> for PerNS<T> {
681 type Output = T;
682
683 fn index(&self, ns: Namespace) -> &T {
684 match ns {
685 Namespace::ValueNS => &self.value_ns,
686 Namespace::TypeNS => &self.type_ns,
687 Namespace::MacroNS => &self.macro_ns,
688 }
689 }
690}
691
692impl<T> ::std::ops::IndexMut<Namespace> for PerNS<T> {
693 fn index_mut(&mut self, ns: Namespace) -> &mut T {
694 match ns {
695 Namespace::ValueNS => &mut self.value_ns,
696 Namespace::TypeNS => &mut self.type_ns,
697 Namespace::MacroNS => &mut self.macro_ns,
698 }
699 }
700}
701
702impl<T> PerNS<Option<T>> {
703 pub fn is_empty(&self) -> bool {
705 self.type_ns.is_none() && self.value_ns.is_none() && self.macro_ns.is_none()
706 }
707
708 pub fn present_items(self) -> impl Iterator<Item = T> {
714 [self.type_ns, self.value_ns, self.macro_ns].into_iter().flatten()
715 }
716}
717
718impl CtorKind {
719 pub fn from_ast(vdata: &ast::VariantData) -> Option<(CtorKind, NodeId)> {
720 match *vdata {
721 ast::VariantData::Tuple(_, node_id) => Some((CtorKind::Fn, node_id)),
722 ast::VariantData::Unit(node_id) => Some((CtorKind::Const, node_id)),
723 ast::VariantData::Struct { .. } => None,
724 }
725 }
726}
727
728impl NonMacroAttrKind {
729 pub fn descr(self) -> &'static str {
730 match self {
731 NonMacroAttrKind::Builtin(..) => "built-in attribute",
732 NonMacroAttrKind::Tool => "tool attribute",
733 NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
734 "derive helper attribute"
735 }
736 }
737 }
738
739 pub fn article(self) -> &'static str {
742 "a"
743 }
744
745 pub fn is_used(self) -> bool {
747 match self {
748 NonMacroAttrKind::Tool
749 | NonMacroAttrKind::DeriveHelper
750 | NonMacroAttrKind::DeriveHelperCompat => true,
751 NonMacroAttrKind::Builtin(..) => false,
752 }
753 }
754}
755
756impl<Id> Res<Id> {
757 pub fn def_id(&self) -> DefId
759 where
760 Id: Debug,
761 {
762 self.opt_def_id().unwrap_or_else(|| {
::core::panicking::panic_fmt(format_args!("attempted .def_id() on invalid res: {0:?}",
self));
}panic!("attempted .def_id() on invalid res: {self:?}"))
763 }
764
765 pub fn opt_def_id(&self) -> Option<DefId> {
767 match *self {
768 Res::Def(_, id) => Some(id),
769
770 Res::Local(..)
771 | Res::PrimTy(..)
772 | Res::SelfTyParam { .. }
773 | Res::SelfTyAlias { .. }
774 | Res::SelfCtor(..)
775 | Res::ToolMod
776 | Res::OpenMod(..)
777 | Res::NonMacroAttr(..)
778 | Res::Err => None,
779 }
780 }
781
782 pub fn mod_def_id(&self) -> Option<DefId> {
784 match *self {
785 Res::Def(DefKind::Mod, id) => Some(id),
786 _ => None,
787 }
788 }
789
790 #[inline]
792 pub fn module_like_def_id(&self) -> Option<DefId> {
793 match self {
794 Res::Def(def_kind, def_id) if def_kind.is_module_like() => Some(*def_id),
795 _ => None,
796 }
797 }
798
799 pub fn descr(&self) -> &'static str {
801 match *self {
802 Res::Def(kind, def_id) => kind.descr(def_id),
803 Res::SelfCtor(..) => "self constructor",
804 Res::PrimTy(..) => "builtin type",
805 Res::Local(..) => "local variable",
806 Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => "self type",
807 Res::ToolMod => "tool module",
808 Res::OpenMod(..) => "namespaced crate",
809 Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
810 Res::Err => "unresolved item",
811 }
812 }
813
814 pub fn article(&self) -> &'static str {
816 match *self {
817 Res::Def(kind, _) => kind.article(),
818 Res::NonMacroAttr(kind) => kind.article(),
819 Res::Err => "an",
820 _ => "a",
821 }
822 }
823
824 pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Res<R> {
825 match self {
826 Res::Def(kind, id) => Res::Def(kind, id),
827 Res::SelfCtor(id) => Res::SelfCtor(id),
828 Res::PrimTy(id) => Res::PrimTy(id),
829 Res::Local(id) => Res::Local(map(id)),
830 Res::SelfTyParam { trait_ } => Res::SelfTyParam { trait_ },
831 Res::SelfTyAlias { alias_to, is_trait_impl } => {
832 Res::SelfTyAlias { alias_to, is_trait_impl }
833 }
834 Res::ToolMod => Res::ToolMod,
835 Res::OpenMod(sym) => Res::OpenMod(sym),
836 Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
837 Res::Err => Res::Err,
838 }
839 }
840
841 pub fn apply_id<R, E>(self, mut map: impl FnMut(Id) -> Result<R, E>) -> Result<Res<R>, E> {
842 Ok(match self {
843 Res::Def(kind, id) => Res::Def(kind, id),
844 Res::SelfCtor(id) => Res::SelfCtor(id),
845 Res::PrimTy(id) => Res::PrimTy(id),
846 Res::Local(id) => Res::Local(map(id)?),
847 Res::SelfTyParam { trait_ } => Res::SelfTyParam { trait_ },
848 Res::SelfTyAlias { alias_to, is_trait_impl } => {
849 Res::SelfTyAlias { alias_to, is_trait_impl }
850 }
851 Res::ToolMod => Res::ToolMod,
852 Res::OpenMod(sym) => Res::OpenMod(sym),
853 Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
854 Res::Err => Res::Err,
855 })
856 }
857
858 #[track_caller]
859 pub fn expect_non_local<OtherId>(self) -> Res<OtherId> {
860 self.map_id(
861 #[track_caller]
862 |_| { ::core::panicking::panic_fmt(format_args!("unexpected `Res::Local`")); }panic!("unexpected `Res::Local`"),
863 )
864 }
865
866 pub fn macro_kinds(self) -> Option<MacroKinds> {
867 match self {
868 Res::Def(DefKind::Macro(kinds), _) => Some(kinds),
869 Res::NonMacroAttr(..) => Some(MacroKinds::ATTR),
870 _ => None,
871 }
872 }
873
874 pub fn ns(&self) -> Option<Namespace> {
876 match self {
877 Res::Def(kind, ..) => kind.ns(),
878 Res::PrimTy(..)
879 | Res::SelfTyParam { .. }
880 | Res::SelfTyAlias { .. }
881 | Res::ToolMod
882 | Res::OpenMod(..) => Some(Namespace::TypeNS),
883 Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
884 Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
885 Res::Err => None,
886 }
887 }
888
889 pub fn matches_ns(&self, ns: Namespace) -> bool {
891 self.ns().is_none_or(|actual_ns| actual_ns == ns)
892 }
893
894 pub fn expected_in_tuple_struct_pat(&self) -> bool {
896 #[allow(non_exhaustive_omitted_patterns)] match self {
Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..) => true,
_ => false,
}matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..))
897 }
898
899 pub fn expected_in_unit_struct_pat(&self) -> bool {
901 #[allow(non_exhaustive_omitted_patterns)] match self {
Res::Def(DefKind::Ctor(_, CtorKind::Const), _) | Res::SelfCtor(..) =>
true,
_ => false,
}matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Const), _) | Res::SelfCtor(..))
902 }
903}