@@ -548,7 +548,7 @@ Builder::discriminant_value (std::string binding_name, std::string instance)
{
auto intrinsic = ptrify (
path_in_expression ({get_path_start (), "intrinsics", "discriminant_value"},
- true));
+ has_opening_scope ()));
return let (identifier_pattern (binding_name), nullptr,
call (std::move (intrinsic), identifier (instance)));
@@ -742,10 +742,11 @@ Builder::new_generic_args (GenericArgs &args)
std::unique_ptr<Expr>
Builder::qualified_call (std::vector<std::string> &&segments,
+ bool has_opening_scope,
std::vector<std::unique_ptr<Expr>> &&args) const
{
- auto path = std::unique_ptr<Expr> (
- new PathInExpression (path_in_expression (std::move (segments))));
+ auto path = std::unique_ptr<Expr> (new PathInExpression (
+ path_in_expression (std::move (segments), has_opening_scope)));
return call (std::move (path), std::move (args));
}
@@ -184,7 +184,7 @@ public:
= {}) const;
std::unique_ptr<Expr>
- qualified_call (std::vector<std::string> &&segments,
+ qualified_call (std::vector<std::string> &&segments, bool has_opening_scope,
std::vector<std::unique_ptr<Expr>> &&args) const;
/* Self parameter for a function definition (`&self`) */
@@ -381,6 +381,19 @@ public:
rust_unreachable ();
}
}
+
+ bool has_opening_scope () const
+ {
+ switch (item_source)
+ {
+ case Builder::Source::InCore:
+ return false;
+ case Builder::Source::Any:
+ return true;
+ default:
+ rust_unreachable ();
+ }
+ }
};
} // namespace AST
@@ -44,6 +44,7 @@ DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
// FIXME: Misses :: prefix to avoid collision with potential core module
return builder.qualified_call ({builder.get_path_start (), "clone", "Clone",
"clone"},
+ builder.has_opening_scope (),
std::move (args));
}
@@ -54,11 +54,13 @@ DeriveDebug::stub_debug_fn ()
auto self = builder.self_ref_param ();
- auto return_type = ptrify (
- builder.type_path ({builder.get_path_start (), "fmt", "Result"}, true));
+ auto return_type
+ = ptrify (builder.type_path ({builder.get_path_start (), "fmt", "Result"},
+ builder.has_opening_scope ()));
auto mut_fmt_type_inner = ptrify (
- builder.type_path ({builder.get_path_start (), "fmt", "Formatter"}, true));
+ builder.type_path ({builder.get_path_start (), "fmt", "Formatter"},
+ builder.has_opening_scope ()));
auto mut_fmt_type
= builder.reference_type (std::move (mut_fmt_type_inner), true);
@@ -83,7 +85,7 @@ DeriveDebug::stub_derive_impl (
auto debug = [this] () {
return builder.type_path ({builder.get_path_start (), "fmt", "Debug"},
- true);
+ builder.has_opening_scope ());
};
auto generics = setup_impl_generics (name, type_generics, [&, this] () {
return builder.trait_bound (debug ());
@@ -44,7 +44,7 @@ DeriveDefault::default_call (std::unique_ptr<Type> &&type)
{
auto default_trait
= builder.type_path ({builder.get_path_start (), "default", "Default"},
- true);
+ builder.has_opening_scope ());
auto default_fn
= builder.qualified_path_in_expression (std::move (type), default_trait,
@@ -73,7 +73,7 @@ DeriveDefault::default_impl (
{
auto default_path = [this] () {
return builder.type_path ({builder.get_path_start (), "default", "Default"},
- true);
+ builder.has_opening_scope ());
};
auto trait_items = vec (std::move (default_fn));
@@ -30,7 +30,8 @@ namespace AST {
static TypePath
get_eq_trait_path (Builder &builder)
{
- return builder.type_path ({builder.get_path_start (), "cmp", "Eq"}, true);
+ return builder.type_path ({builder.get_path_start (), "cmp", "Eq"},
+ builder.has_opening_scope ());
}
DeriveEq::DeriveEq (location_t loc, Builder::Source item_source)
@@ -45,7 +45,7 @@ DeriveHash::hash_call (std::unique_ptr<Expr> &&value)
{
auto hash = builder.path_in_expression ({builder.get_path_start (), "hash",
"Hash", "hash"},
- true);
+ builder.has_opening_scope ());
return builder.call (ptrify (hash),
vec (std::move (value),
@@ -67,7 +67,8 @@ DeriveHash::hash_fn (std::unique_ptr<BlockExpr> &&block)
auto params = vec (builder.self_ref_param (), std::move (state_param));
auto bounds = vec (builder.trait_bound (
- builder.type_path ({builder.get_path_start (), "hash", "Hasher"}, true)));
+ builder.type_path ({builder.get_path_start (), "hash", "Hasher"},
+ builder.has_opening_scope ())));
auto generics = vec (
builder.generic_type_param (DeriveHash::state_type, std::move (bounds)));
@@ -82,7 +83,7 @@ DeriveHash::hash_impl (
{
auto hash_path = [this] () {
return builder.type_path ({builder.get_path_start (), "hash", "Hash"},
- true);
+ builder.has_opening_scope ());
};
auto trait_items = vec (std::move (hash_fn));
@@ -43,8 +43,10 @@ std::unique_ptr<Expr>
DeriveOrd::cmp_call (std::unique_ptr<Expr> &&self_expr,
std::unique_ptr<Expr> &&other_expr)
{
- auto cmp_fn_path = builder.path_in_expression (
- {builder.get_path_start (), "cmp", trait (ordering), fn (ordering)}, true);
+ auto cmp_fn_path
+ = builder.path_in_expression ({builder.get_path_start (), "cmp",
+ trait (ordering), fn (ordering)},
+ builder.has_opening_scope ());
return builder.call (ptrify (cmp_fn_path),
vec (builder.ref (std::move (self_expr)),
@@ -60,7 +62,8 @@ DeriveOrd::cmp_impl (
auto trait = ordering == Ordering::Partial ? "PartialOrd" : "Ord";
auto trait_path = [&, this] () {
- return builder.type_path ({builder.get_path_start (), "cmp", trait}, true);
+ return builder.type_path ({builder.get_path_start (), "cmp", trait},
+ builder.has_opening_scope ());
};
auto trait_bound
@@ -81,7 +84,8 @@ DeriveOrd::cmp_fn (std::unique_ptr<BlockExpr> &&block, Identifier type_name)
{
// Ordering
auto return_type
- = builder.type_path ({builder.get_path_start (), "cmp", "Ordering"}, true);
+ = builder.type_path ({builder.get_path_start (), "cmp", "Ordering"},
+ builder.has_opening_scope ());
// In the case of PartialOrd, we return an Option<Ordering>
if (ordering == Ordering::Partial)
@@ -96,7 +100,7 @@ DeriveOrd::cmp_fn (std::unique_ptr<BlockExpr> &&block, Identifier type_name)
return_type
= builder.type_path (vec (std::move (core), std::move (option),
std::move (generic_seg)),
- true);
+ builder.has_opening_scope ());
}
// &self, other: &Self
@@ -118,8 +122,10 @@ DeriveOrd::cmp_fn (std::unique_ptr<BlockExpr> &&block, Identifier type_name)
std::unique_ptr<Pattern>
DeriveOrd::make_equal ()
{
- std::unique_ptr<Pattern> equal = ptrify (builder.path_in_expression (
- {builder.get_path_start (), "cmp", "Ordering", "Equal"}, true));
+ std::unique_ptr<Pattern> equal
+ = ptrify (builder.path_in_expression ({builder.get_path_start (), "cmp",
+ "Ordering", "Equal"},
+ builder.has_opening_scope ()));
// We need to wrap the pattern in Option::Some if we are doing partial
// ordering
@@ -153,8 +159,10 @@ DeriveOrd::recursive_match (std::vector<SelfOther> &&members)
{
if (members.empty ())
{
- std::unique_ptr<Expr> value = ptrify (builder.path_in_expression (
- {builder.get_path_start (), "cmp", "Ordering", "Equal"}, true));
+ std::unique_ptr<Expr> value
+ = ptrify (builder.path_in_expression ({builder.get_path_start (), "cmp",
+ "Ordering", "Equal"},
+ builder.has_opening_scope ()));
if (ordering == Ordering::Partial)
value = builder.call (ptrify (builder.path_in_expression (
@@ -35,13 +35,15 @@ static std::unique_ptr<AST::Expr>
format_arg (const AST::Builder &builder, std::unique_ptr<AST::Expr> &&to_format,
const std::string &trait)
{
- auto formatter_fn = std::unique_ptr<AST::Expr> (
- new AST::PathInExpression (builder.path_in_expression (
- {builder.get_path_start (), "fmt", trait, "fmt"})));
+ auto formatter_fn = std::unique_ptr<AST::Expr> (new AST::PathInExpression (
+ builder.path_in_expression ({builder.get_path_start (), "fmt", trait,
+ "fmt"},
+ builder.has_opening_scope ())));
- auto path = std::unique_ptr<AST::Expr> (
- new AST::PathInExpression (builder.path_in_expression (
- {builder.get_path_start (), "fmt", "ArgumentV1", "new"})));
+ auto path = std::unique_ptr<AST::Expr> (new AST::PathInExpression (
+ builder.path_in_expression ({builder.get_path_start (), "fmt", "ArgumentV1",
+ "new"},
+ builder.has_opening_scope ())));
auto args = std::vector<std::unique_ptr<AST::Expr>> ();
args.emplace_back (std::move (to_format));
@@ -127,9 +129,10 @@ expand_format_args (AST::FormatArgs &fmt,
auto pieces = builder.ref (builder.array (std::move (static_pieces)));
auto args_slice = builder.ref (builder.array (std::move (args_array)));
- auto final_path
- = std::make_unique<AST::PathInExpression> (builder.path_in_expression (
- {builder.get_path_start (), "fmt", "Arguments", "new_v1"}));
+ auto final_path = std::make_unique<AST::PathInExpression> (
+ builder.path_in_expression ({builder.get_path_start (), "fmt", "Arguments",
+ "new_v1"},
+ builder.has_opening_scope ()));
auto final_args = std::vector<std::unique_ptr<AST::Expr>> ();
final_args.emplace_back (std::move (pieces));
final_args.emplace_back (std::move (args_slice));