return PathInExpression (std::move (path_segments), {}, loc);
}
-std::unique_ptr<Expr>
-AstBuilder::struct_expr_struct (std::string struct_name)
-{
- return std::unique_ptr<Expr> (
- new StructExprStruct (path_in_expression ({struct_name}), {}, {}, loc));
-}
-
std::unique_ptr<Expr>
AstBuilder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr)
AstBuilder::let (std::unique_ptr<Pattern> pattern, std::unique_ptr<Type> type,
std::unique_ptr<Expr> init)
{
- return std::unique_ptr<Stmt> (
- new LetStmt (/* needs a pattern here, not just a name */ nullptr,
- std::move (init), std::move (type), {}, loc));
+ return std::unique_ptr<Stmt> (new LetStmt (std::move (pattern),
+ std::move (init), std::move (type),
+ {}, loc));
}
std::unique_ptr<Expr>
return std::unique_ptr<Expr> (new DereferenceExpr (std::move (of), {}, loc));
}
+std::unique_ptr<Expr>
+AstBuilder::struct_expr_struct (std::string struct_name)
+{
+ return std::unique_ptr<Expr> (
+ new StructExprStruct (path_in_expression ({struct_name}), {}, {}, loc));
+}
+
std::unique_ptr<Expr>
AstBuilder::struct_expr (std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields)
new FieldAccessExpr (std::move (instance), field, {}, loc));
}
+std::unique_ptr<Pattern>
+AstBuilder::wildcard ()
+{
+ return std::unique_ptr<Pattern> (new WildcardPattern (loc));
+}
+
} // namespace AST
} // namespace Rust
std::unique_ptr<Expr> field_access (std::unique_ptr<Expr> &&instance,
std::string field);
+ /* Create a wildcard pattern (`_`) */
+ std::unique_ptr<Pattern> wildcard ();
+
private:
/**
* Location of the generated AST nodes
void
DeriveClone::visit_union (Union &item)
{
- rust_sorry_at (item.get_locus (), "cannot derive %qs for these items yet",
- "Clone");
+ // FIXME: Should be $crate::core::clone::AssertParamIsCopy (or similar)
+
+ // <Self>
+ auto arg = GenericArg::create_type (builder.single_type_path ("Self"));
+
+ // AssertParamIsCopy::<Self>
+ auto type = std::unique_ptr<TypePathSegment> (
+ new TypePathSegmentGeneric (PathIdentSegment ("AssertParamIsCopy", loc),
+ false, GenericArgs ({}, {arg}, {}, loc), loc));
+ auto type_paths = std::vector<std::unique_ptr<TypePathSegment>> ();
+ type_paths.emplace_back (std::move (type));
+
+ auto full_path
+ = std::unique_ptr<Type> (new TypePath ({std::move (type_paths)}, loc));
+
+ auto stmts = std::vector<std::unique_ptr<Stmt>> ();
+ stmts.emplace_back (
+ builder.let (builder.wildcard (), std::move (full_path), nullptr));
+ auto tail_expr = builder.deref (builder.identifier ("self"));
+
+ auto block = builder.block (std::move (stmts), std::move (tail_expr));
+
+ expanded = clone_impl (clone_fn (std::move (block)), item.get_identifier ());
}
} // namespace AST
--- /dev/null
+pub trait Copy {}
+pub trait Clone {
+ fn clone(&self) -> Self;
+}
+
+struct PhantomData<T>;
+
+pub struct AssertParamIsCopy<T: Copy> {
+ _field: PhantomData<T>,
+}
+
+#[derive(Clone)] // { dg-error "bounds not satisfied for U .Copy. is not satisfied" }
+union U {
+ i: i32,
+ f: f64,
+}
--- /dev/null
+pub trait Copy {}
+pub trait Clone {
+ fn clone(&self) -> Self;
+}
+
+#[lang = "phantom_data"]
+pub struct PhantomData<T>;
+
+pub struct AssertParamIsCopy<T: Copy> {
+ pub _field: PhantomData<T>,
+}
+
+impl Copy for i32 {}
+impl Copy for i64 {}
+impl Copy for U {}
+
+#[derive(Clone)]
+union U {
+ i: i32,
+ f: f64,
+}