void
ASTLoweringExpr::visit (AST::AnonConst &expr)
{
- auto inner_expr = ASTLoweringExpr::translate (expr.get_inner_expr ());
-
auto &mappings = Analysis::Mappings::get ();
auto crate_num = mappings.get_current_crate ();
auto mapping = Analysis::NodeMapping (crate_num, expr.get_node_id (),
mappings.get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
- translated = new HIR::AnonConst (std::move (mapping),
- std::unique_ptr<Expr> (inner_expr),
- expr.get_locus ());
+ if (expr.is_deferred ())
+ {
+ translated = new HIR::AnonConst (std::move (mapping), expr.get_locus ());
+ }
+ else
+ {
+ auto inner_expr = ASTLoweringExpr::translate (expr.get_inner_expr ());
+
+ translated = new HIR::AnonConst (std::move (mapping),
+ std::unique_ptr<Expr> (inner_expr),
+ expr.get_locus ());
+ }
}
void
#include "rust-hir-expr.h"
#include "rust-hir-map.h"
+#include "optional.h"
#include "rust-operators.h"
#include "rust-hir-stmt.h"
AnonConst::AnonConst (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> &&expr, location_t locus)
: ExprWithBlock (std::move (mappings), {}), locus (locus),
- expr (std::move (expr))
+ kind (Kind::Explicit), expr (std::move (expr))
{
- rust_assert (this->expr);
+ rust_assert (this->expr.value ());
}
-AnonConst::AnonConst (const AnonConst &other)
- : ExprWithBlock (other), locus (other.locus), expr (other.expr->clone_expr ())
+AnonConst::AnonConst (Analysis::NodeMapping mappings, location_t locus)
+ : ExprWithBlock (std::move (mappings), {}), locus (locus),
+ kind (Kind::DeferredInference), expr (tl::nullopt)
{}
+AnonConst::AnonConst (const AnonConst &other)
+ : ExprWithBlock (other), locus (other.locus), kind (other.kind)
+{
+ if (other.expr)
+ expr = other.expr.value ()->clone_expr ();
+}
+
AnonConst
AnonConst::operator= (const AnonConst &other)
{
ExprWithBlock::operator= (other);
locus = other.locus;
- expr = other.expr->clone_expr ();
+ kind = other.kind;
+
+ if (other.expr)
+ expr = other.expr.value ()->clone_expr ();
return *this;
}
class AnonConst : public ExprWithBlock
{
public:
+ enum class Kind
+ {
+ Explicit,
+ DeferredInference
+ };
+
AnonConst (Analysis::NodeMapping mappings, std::unique_ptr<Expr> &&expr,
location_t locus = UNKNOWN_LOCATION);
+ AnonConst (Analysis::NodeMapping mappings,
+ location_t locus = UNKNOWN_LOCATION);
AnonConst (const AnonConst &other);
AnonConst operator= (const AnonConst &other);
}
location_t get_locus () const override { return locus; }
- Expr &get_inner_expr () { return *expr; }
- const Expr &get_inner_expr () const { return *expr; }
+
+ Expr &get_inner_expr ()
+ {
+ rust_assert (kind == Kind::Explicit);
+ return *expr.value ();
+ }
+
+ const Expr &get_inner_expr () const
+ {
+ rust_assert (kind == Kind::Explicit);
+ return *expr.value ();
+ }
+
+ bool is_deferred () const { return kind == Kind::DeferredInference; }
private:
location_t locus;
- std::unique_ptr<Expr> expr;
+ Kind kind;
+ tl::optional<std::unique_ptr<Expr>> expr;
AnonConst *clone_expr_with_block_impl () const override
{
void
DefaultHIRVisitor::walk (AnonConst &expr)
{
- expr.get_inner_expr ().accept_vis (*this);
+ if (!expr.is_deferred ())
+ expr.get_inner_expr ().accept_vis (*this);
}
void
}
} // namespace HIR
-} // namespace Rust
\ No newline at end of file
+} // namespace Rust
void
TypeCheckExpr::visit (HIR::AnonConst &expr)
{
+ // FIXME: How do we typecheck a deferred inference const?
+
+ rust_assert (!expr.is_deferred ());
+
infered = TypeCheckExpr::Resolve (expr.get_inner_expr ());
}
--- /dev/null
+// { dg-additional-options "-frust-compile-until=typecheck" }
+
+// #![feature(generic_arg_infer)]
+
+fn main() {
+ let a: [u32; _] = [15u32];
+}