bool
BaseType::is_unit () const
{
+ const TyTy::BaseType *x = destructure ();
+ switch (x->get_kind ())
+ {
+ case PARAM:
+ case PROJECTION:
+ case PLACEHOLDER:
+ case FNPTR:
+ case FNDEF:
+ case ARRAY:
+ case SLICE:
+ case POINTER:
+ case REF:
+ case CLOSURE:
+ case INFER:
+ case BOOL:
+ case CHAR:
+ case INT:
+ case UINT:
+ case FLOAT:
+ case USIZE:
+ case ISIZE:
+
+ case STR:
+ case DYNAMIC:
+ case ERROR:
+ return false;
+
+ // FIXME ! is coerceable to () so we need to fix that
+ case NEVER:
+ return true;
+
+ case TUPLE: {
+ const TupleType &tuple = *static_cast<const TupleType *> (x);
+ return tuple.num_fields () == 0;
+ }
+
+ case ADT: {
+ const ADTType &adt = *static_cast<const ADTType *> (x);
+ if (adt.is_enum ())
+ return false;
+
+ for (const auto &variant : adt.get_variants ())
+ {
+ if (variant->num_fields () > 0)
+ return false;
+ }
+
+ return true;
+ }
+ }
return false;
}
{Resolver::CanonicalPath::create_empty (), Location ()}, refs)
{}
-bool
-ErrorType::is_unit () const
-{
- return true;
-}
-
std::string
ErrorType::get_name () const
{
return new TupleType (ref, Linemap::predeclared_location ());
}
-bool
-TupleType::is_unit () const
-{
- return this->fields.empty ();
-}
-
size_t
TupleType::num_fields () const
{
return as_string ();
}
-bool
-NeverType::is_unit () const
-{
- return true;
-}
-
void
NeverType::accept_vis (TyVisitor &vis)
{
return as_string ();
}
-bool
-PlaceholderType::is_unit () const
-{
- rust_assert (can_resolve ());
- return resolve ()->is_unit ();
-}
-
std::string
PlaceholderType::get_symbol () const
{
base (base), trait (trait), item (item)
{}
-bool
-ProjectionType::is_unit () const
-{
- return false;
-}
-
std::string
ProjectionType::get_name () const
{
virtual ~BaseType ();
HirId get_ref () const;
-
void set_ref (HirId id);
HirId get_ty_ref () const;
-
void set_ty_ref (HirId id);
virtual void accept_vis (TyVisitor &vis) = 0;
-
virtual void accept_vis (TyConstVisitor &vis) const = 0;
virtual std::string as_string () const = 0;
-
virtual std::string get_name () const = 0;
// similar to unify but does not actually perform type unification but
virtual bool is_equal (const BaseType &other) const;
bool satisfies_bound (const TypeBoundPredicate &predicate) const;
-
bool bounds_compatible (const BaseType &other, Location locus,
bool emit_error) const;
-
void inherit_bounds (const BaseType &other);
-
void inherit_bounds (
const std::vector<TyTy::TypeBoundPredicate> &specified_bounds);
- virtual bool is_unit () const;
+ // is_unit returns whether this is just a unit-struct
+ bool is_unit () const;
+ // is_concrete returns true if the type is fully resolved to concrete
+ // primitives
bool is_concrete () const;
+ // return the type-kind
TypeKind get_kind () const;
/* Returns a pointer to a clone of this. The caller is responsible for
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
- bool is_unit () const override;
-
std::string as_string () const override;
bool can_eq (const BaseType *other, bool emit_errors) const override final;
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
- bool is_unit () const override;
-
std::string as_string () const override;
bool can_eq (const BaseType *other, bool emit_errors) const override final;
bool is_union () const { return adt_kind == UNION; }
bool is_enum () const { return adt_kind == ENUM; }
- bool is_unit () const override
- {
- if (number_of_variants () == 0)
- return true;
-
- if (number_of_variants () == 1)
- return variants.at (0)->num_fields () == 0;
-
- return false;
- }
-
void accept_vis (TyVisitor &vis) override;
void accept_vis (TyConstVisitor &vis) const override;
BaseType *monomorphized_clone () const final override;
std::string get_name () const override final;
-
- bool is_unit () const override;
};
// used at the type in associated types in traits
std::string get_name () const override final;
- bool is_unit () const override;
-
std::string get_symbol () const;
void set_associated_type (HirId ref);
std::string get_name () const override final;
- bool is_unit () const override;
-
bool needs_generic_substitutions () const override final;
bool supports_substitutions () const override final;