Unreserve braced enum variants in value namespace
This commit is contained in:
parent
1cbc45942d
commit
7a5376d23c
71 changed files with 364 additions and 642 deletions
|
@ -28,8 +28,6 @@ pub enum CtorKind {
|
|||
Fn,
|
||||
/// Constructor constant automatically created by a unit struct/variant.
|
||||
Const,
|
||||
/// Unusable name in value namespace created by a struct variant.
|
||||
Fictive,
|
||||
}
|
||||
|
||||
/// An attribute that is not a macro; e.g., `#[inline]` or `#[rustfmt::skip]`.
|
||||
|
@ -132,13 +130,9 @@ impl DefKind {
|
|||
DefKind::Variant => "variant",
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant",
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Const) => "unit variant",
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Fictive) => "struct variant",
|
||||
DefKind::Struct => "struct",
|
||||
DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct",
|
||||
DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct",
|
||||
DefKind::Ctor(CtorOf::Struct, CtorKind::Fictive) => {
|
||||
panic!("impossible struct constructor")
|
||||
}
|
||||
DefKind::OpaqueTy => "opaque type",
|
||||
DefKind::ImplTraitPlaceholder => "opaque type in trait",
|
||||
DefKind::TyAlias => "type alias",
|
||||
|
@ -562,19 +556,11 @@ impl<T> PerNS<Option<T>> {
|
|||
}
|
||||
|
||||
impl CtorKind {
|
||||
pub fn from_ast(vdata: &ast::VariantData) -> CtorKind {
|
||||
pub fn from_ast(vdata: &ast::VariantData) -> Option<(CtorKind, NodeId)> {
|
||||
match *vdata {
|
||||
ast::VariantData::Tuple(..) => CtorKind::Fn,
|
||||
ast::VariantData::Unit(..) => CtorKind::Const,
|
||||
ast::VariantData::Struct(..) => CtorKind::Fictive,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_hir(vdata: &hir::VariantData<'_>) -> CtorKind {
|
||||
match *vdata {
|
||||
hir::VariantData::Tuple(..) => CtorKind::Fn,
|
||||
hir::VariantData::Unit(..) => CtorKind::Const,
|
||||
hir::VariantData::Struct(..) => CtorKind::Fictive,
|
||||
ast::VariantData::Tuple(_, node_id) => Some((CtorKind::Fn, node_id)),
|
||||
ast::VariantData::Unit(node_id) => Some((CtorKind::Const, node_id)),
|
||||
ast::VariantData::Struct(..) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2913,20 +2913,29 @@ impl<'hir> VariantData<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the `LocalDefId` of this variant's constructor, if it has one.
|
||||
pub fn ctor_def_id(&self) -> Option<LocalDefId> {
|
||||
pub fn ctor(&self) -> Option<(CtorKind, HirId, LocalDefId)> {
|
||||
match *self {
|
||||
VariantData::Struct(_, _) => None,
|
||||
VariantData::Tuple(_, _, def_id) | VariantData::Unit(_, def_id) => Some(def_id),
|
||||
VariantData::Tuple(_, hir_id, def_id) => Some((CtorKind::Fn, hir_id, def_id)),
|
||||
VariantData::Unit(hir_id, def_id) => Some((CtorKind::Const, hir_id, def_id)),
|
||||
VariantData::Struct(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn ctor_kind(&self) -> Option<CtorKind> {
|
||||
self.ctor().map(|(kind, ..)| kind)
|
||||
}
|
||||
|
||||
/// Return the `HirId` of this variant's constructor, if it has one.
|
||||
#[inline]
|
||||
pub fn ctor_hir_id(&self) -> Option<HirId> {
|
||||
match *self {
|
||||
VariantData::Struct(_, _) => None,
|
||||
VariantData::Tuple(_, hir_id, _) | VariantData::Unit(hir_id, _) => Some(hir_id),
|
||||
}
|
||||
self.ctor().map(|(_, hir_id, _)| hir_id)
|
||||
}
|
||||
|
||||
/// Return the `LocalDefId` of this variant's constructor, if it has one.
|
||||
#[inline]
|
||||
pub fn ctor_def_id(&self) -> Option<LocalDefId> {
|
||||
self.ctor().map(|(.., def_id)| def_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue