tamer: Use `..` for tuple unimportant variant matches
Tbh, I was unaware that this was supported by tuple variants until reading over the Rustc source code for something. (Which I had previously read, but I must have missed it.) This is more proper, in the sense that in a lot of cases we not only care about how many values a tuple has, but if we explicitly match on them using `_`, then any time we modify the number of values, it would _break_ any code doing so. Using this method, we improve maintainability by not causing breakages under those circumstances. But, consequently, it's important that we use this only when we _really_ don't care and don't want to be notified by the compiler. I did not use `..` as a prefix, even where supported, because the intent is to append additional information to tuples. Consequently, I also used `..` in places where no additional fields currently exist, since they may in the future (e.g. introducing `Span` for `IdentObject`).main
parent
739cf7e6eb
commit
581b9d4e65
|
@ -149,16 +149,16 @@ pub enum IdentKind {
|
|||
impl IdentKind {
|
||||
pub fn as_sym(&self) -> SymbolId {
|
||||
match self {
|
||||
Self::Cgen(_) => st::L_CGEN.as_sym(),
|
||||
Self::Class(_) => st::L_CLASS.as_sym(),
|
||||
Self::Const(_, _) => st::L_CONST.as_sym(),
|
||||
Self::Func(_, _) => st::L_FUNC.as_sym(),
|
||||
Self::Gen(_, _) => st::L_GEN.as_sym(),
|
||||
Self::Lparam(_, _) => st::L_LPARAM.as_sym(),
|
||||
Self::Param(_, _) => st::L_PARAM.as_sym(),
|
||||
Self::Rate(_) => st::L_RATE.as_sym(),
|
||||
Self::Cgen(..) => st::L_CGEN.as_sym(),
|
||||
Self::Class(..) => st::L_CLASS.as_sym(),
|
||||
Self::Const(..) => st::L_CONST.as_sym(),
|
||||
Self::Func(..) => st::L_FUNC.as_sym(),
|
||||
Self::Gen(..) => st::L_GEN.as_sym(),
|
||||
Self::Lparam(..) => st::L_LPARAM.as_sym(),
|
||||
Self::Param(..) => st::L_PARAM.as_sym(),
|
||||
Self::Rate(..) => st::L_RATE.as_sym(),
|
||||
Self::Tpl => st::L_TPL.as_sym(),
|
||||
Self::Type(_) => st::L_TYPE.as_sym(),
|
||||
Self::Type(..) => st::L_TYPE.as_sym(),
|
||||
Self::MapHead => st::L_MAP_HEAD.as_sym(),
|
||||
Self::Map => st::L_MAP.as_sym(),
|
||||
Self::MapTail => st::L_MAP_TAIL.as_sym(),
|
||||
|
|
|
@ -83,26 +83,26 @@ pub enum IdentObject {
|
|||
impl IdentObject {
|
||||
pub fn name(&self) -> SymbolId {
|
||||
match self {
|
||||
Self::Missing(name)
|
||||
| Self::Ident(name, _, _)
|
||||
| Self::Extern(name, _, _)
|
||||
| Self::IdentFragment(name, _, _, _) => *name,
|
||||
Self::Missing(name, ..)
|
||||
| Self::Ident(name, ..)
|
||||
| Self::Extern(name, ..)
|
||||
| Self::IdentFragment(name, ..) => *name,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> Option<&IdentKind> {
|
||||
match self {
|
||||
Self::Missing(_) => None,
|
||||
Self::Ident(_, kind, _)
|
||||
| Self::Extern(_, kind, _)
|
||||
| Self::IdentFragment(_, kind, _, _) => Some(kind),
|
||||
Self::Missing(..) => None,
|
||||
Self::Ident(_, kind, ..)
|
||||
| Self::Extern(_, kind, ..)
|
||||
| Self::IdentFragment(_, kind, ..) => Some(kind),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn src(&self) -> Option<&Source> {
|
||||
match self {
|
||||
Self::Missing(_) | Self::Extern(_, _, _) => None,
|
||||
Self::Ident(_, _, src) | Self::IdentFragment(_, _, src, _) => {
|
||||
Self::Missing(..) | Self::Extern(..) => None,
|
||||
Self::Ident(_, _, src, ..) | Self::IdentFragment(_, _, src, ..) => {
|
||||
Some(src)
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +110,7 @@ impl IdentObject {
|
|||
|
||||
pub fn fragment(&self) -> Option<FragmentText> {
|
||||
match self {
|
||||
Self::Missing(_) | Self::Ident(_, _, _) | Self::Extern(_, _, _) => {
|
||||
None
|
||||
}
|
||||
Self::Missing(..) | Self::Ident(..) | Self::Extern(..) => None,
|
||||
Self::IdentFragment(_, _, _, text) => Some(*text),
|
||||
}
|
||||
}
|
||||
|
@ -379,12 +377,14 @@ impl IdentObjectState<IdentObject> for IdentObject {
|
|||
|
||||
// These represent the prolog and epilogue of maps. This
|
||||
// situation will be resolved in the future.
|
||||
IdentObject::IdentFragment(_, IdentKind::MapHead, _, _)
|
||||
| IdentObject::IdentFragment(_, IdentKind::MapTail, _, _)
|
||||
| IdentObject::IdentFragment(_, IdentKind::RetMapHead, _, _)
|
||||
| IdentObject::IdentFragment(_, IdentKind::RetMapTail, _, _) => {
|
||||
Ok(self)
|
||||
}
|
||||
IdentObject::IdentFragment(
|
||||
_,
|
||||
IdentKind::MapHead
|
||||
| IdentKind::MapTail
|
||||
| IdentKind::RetMapHead
|
||||
| IdentKind::RetMapTail,
|
||||
..,
|
||||
) => Ok(self),
|
||||
|
||||
IdentObject::Missing(name) => {
|
||||
Ok(IdentObject::Ident(name, kind, src))
|
||||
|
@ -412,8 +412,7 @@ impl IdentObjectState<IdentObject> for IdentObject {
|
|||
})
|
||||
}
|
||||
|
||||
IdentObject::Ident(_, _, _)
|
||||
| IdentObject::IdentFragment(_, _, _, _) => Ok(self),
|
||||
IdentObject::Ident(..) | IdentObject::IdentFragment(..) => Ok(self),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,18 +455,20 @@ impl IdentObjectState<IdentObject> for IdentObject {
|
|||
// If this is not permissable, then we should have already
|
||||
// prevented the `resolve` transition before this fragment was
|
||||
// encountered.
|
||||
IdentObject::IdentFragment(_, _, ref src, _) if src.override_ => {
|
||||
IdentObject::IdentFragment(_, _, ref src, ..) if src.override_ => {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
// These represent the prolog and epilogue of maps. This
|
||||
// situation will be resolved in the future.
|
||||
IdentObject::IdentFragment(_, IdentKind::MapHead, _, _)
|
||||
| IdentObject::IdentFragment(_, IdentKind::MapTail, _, _)
|
||||
| IdentObject::IdentFragment(_, IdentKind::RetMapHead, _, _)
|
||||
| IdentObject::IdentFragment(_, IdentKind::RetMapTail, _, _) => {
|
||||
Ok(self)
|
||||
}
|
||||
IdentObject::IdentFragment(
|
||||
_,
|
||||
IdentKind::MapHead
|
||||
| IdentKind::MapTail
|
||||
| IdentKind::RetMapHead
|
||||
| IdentKind::RetMapTail,
|
||||
..,
|
||||
) => Ok(self),
|
||||
|
||||
_ => {
|
||||
let msg = format!(
|
||||
|
|
|
@ -124,7 +124,7 @@ where
|
|||
|
||||
let is_all_funcs = scc.iter().all(|nx| {
|
||||
let ident = Asg::get(asg, *nx).expect("missing node");
|
||||
matches!(ident.kind(), Some(IdentKind::Func(_, _)))
|
||||
matches!(ident.kind(), Some(IdentKind::Func(..)))
|
||||
});
|
||||
|
||||
if is_all_funcs {
|
||||
|
|
|
@ -116,17 +116,17 @@ impl<'a> XmleSections<'a> for Sections<'a> {
|
|||
|
||||
match ident.resolved()?.kind() {
|
||||
Some(kind) => match kind {
|
||||
IdentKind::Cgen(_)
|
||||
| IdentKind::Gen(_, _)
|
||||
| IdentKind::Lparam(_, _) => {
|
||||
IdentKind::Cgen(..)
|
||||
| IdentKind::Gen(..)
|
||||
| IdentKind::Lparam(..) => {
|
||||
// These types do not have fragments.
|
||||
}
|
||||
IdentKind::Meta
|
||||
| IdentKind::Worksheet
|
||||
| IdentKind::Param(_, _)
|
||||
| IdentKind::Type(_)
|
||||
| IdentKind::Func(_, _)
|
||||
| IdentKind::Const(_, _) => {
|
||||
| IdentKind::Param(..)
|
||||
| IdentKind::Type(..)
|
||||
| IdentKind::Func(..)
|
||||
| IdentKind::Const(..) => {
|
||||
self.st.push(expect_frag(name, frag)?)
|
||||
}
|
||||
IdentKind::MapHead | IdentKind::Map | IdentKind::MapTail => {
|
||||
|
@ -144,7 +144,7 @@ impl<'a> XmleSections<'a> for Sections<'a> {
|
|||
self.retmap.push(expect_frag(name, frag)?)
|
||||
}
|
||||
// TODO: Why do templates have fragments?
|
||||
IdentKind::Class(_) | IdentKind::Rate(_) | IdentKind::Tpl => {
|
||||
IdentKind::Class(..) | IdentKind::Rate(..) | IdentKind::Tpl => {
|
||||
self.exec.push(expect_frag(name, frag)?)
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue