Synthesize default action of () if type is ()

This commit is contained in:
Niko Matsakis 2016-03-22 04:22:42 -04:00
parent 487004bddb
commit 7b4a4a870c
2 changed files with 18 additions and 1 deletions

View File

@ -164,6 +164,13 @@ pub enum TypeRepr {
}
impl TypeRepr {
pub fn is_unit(&self) -> bool {
match *self {
TypeRepr::Tuple(ref v) => v.is_empty(),
_ => false,
}
}
pub fn usize() -> TypeRepr {
TypeRepr::Nominal(NominalTypeRepr {
path: Path::usize(),

View File

@ -257,7 +257,17 @@ impl LowerState {
{
let action = match action {
Some(s) => s,
None => format!("(<>)"),
None => {
// If the user declared a type `()`, or we inferred
// it, then there is only one possible action that
// will type-check (`()`), so supply that. Otherwise,
// default is to include all selected items.
if nt_type.is_unit() {
format!("()")
} else {
format!("(<>)")
}
}
};
// Note that the action fn takes ALL of the symbols in `expr`