@@ -131,7 +131,8 @@ FeatureGate::visit (AST::MacroRulesDefinition &rules_def)
void
FeatureGate::visit (AST::Function &function)
{
- check_rustc_attri (function.get_outer_attrs ());
+ if (!function.is_external ())
+ check_rustc_attri (function.get_outer_attrs ());
}
void
@@ -65,7 +65,7 @@ public:
item.get_outer_attrs (), item.get_locus ());
}
- void visit (AST::ExternalFunctionItem &function) override
+ void visit (AST::Function &function) override
{
std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
HIR::WhereClause where_clause (std::move (where_clause_items));
@@ -88,12 +88,25 @@ public:
std::vector<HIR::NamedFunctionParam> function_params;
for (auto it = begin; it != end; it++)
{
+ auto param = static_cast<AST::FunctionParam *> (it->get ());
+
+ if (param->is_variadic () || param->is_self ())
+ continue;
+ auto param_kind = param->get_pattern ()->get_pattern_kind ();
+
+ rust_assert (param_kind == AST::Pattern::Kind::Identifier
+ || param_kind == AST::Pattern::Kind::Wildcard);
+ auto param_ident = static_cast<AST::IdentifierPattern *> (
+ param->get_pattern ().get ());
+ Identifier param_name = param_kind == AST::Pattern::Kind::Identifier
+ ? param_ident->get_ident ()
+ : std::string ("_");
+
HIR::Type *param_type
- = ASTLoweringType::translate (it->get_type ().get ());
- Identifier param_name = it->get_name ();
+ = ASTLoweringType::translate (param->get_type ().get ());
auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, it->get_node_id (),
+ Analysis::NodeMapping mapping (crate_num, param->get_node_id (),
mappings->get_next_hir_id (crate_num),
mappings->get_next_localdef_id (
crate_num));
@@ -109,7 +122,7 @@ public:
mappings->get_next_localdef_id (crate_num));
translated = new HIR::ExternalFunctionItem (
- mapping, function.get_identifier (), std::move (generic_params),
+ mapping, function.get_function_name (), std::move (generic_params),
std::unique_ptr<HIR::Type> (return_type), std::move (where_clause),
std::move (function_params), is_variadic, std::move (vis),
function.get_outer_attrs (), function.get_locus ());
@@ -6165,8 +6165,7 @@ Parser<ManagedTokenSource>::parse_external_item ()
std::move (outer_attrs), locus));
}
case FN_KW:
- return parse_external_function_item (std::move (vis),
- std::move (outer_attrs));
+ return parse_function (std::move (vis), std::move (outer_attrs), true);
case TYPE:
return parse_external_type_item (std::move (vis),
@@ -10476,7 +10475,9 @@ Parser<ManagedTokenSource>::parse_pattern ()
{
lexer.skip_token ();
alts.push_back (parse_pattern_no_alt ());
- } while (lexer.peek_token ()->get_id () == PIPE);
+ }
+
+ while (lexer.peek_token ()->get_id () == PIPE);
/* alternates */
return std::unique_ptr<AST::Pattern> (
@@ -189,11 +189,11 @@ public:
item->accept_vis (resolver);
};
- void visit (AST::ExternalFunctionItem &function) override
+ void visit (AST::Function &function) override
{
auto decl
= CanonicalPath::new_seg (function.get_node_id (),
- function.get_identifier ().as_string ());
+ function.get_function_name ().as_string ());
auto path = prefix.append (decl);
resolver->get_name_scope ().insert (
@@ -1009,11 +1009,12 @@ ResolveExternItem::go (AST::ExternalItem *item, const CanonicalPath &prefix,
}
void
-ResolveExternItem::visit (AST::ExternalFunctionItem &function)
+ResolveExternItem::visit (AST::Function &function)
{
NodeId scope_node_id = function.get_node_id ();
- auto decl = CanonicalPath::new_seg (function.get_node_id (),
- function.get_identifier ().as_string ());
+ auto decl
+ = CanonicalPath::new_seg (function.get_node_id (),
+ function.get_function_name ().as_string ());
auto path = prefix.append (decl);
auto cpath = canonical_prefix.append (decl);
@@ -1038,9 +1039,12 @@ ResolveExternItem::visit (AST::ExternalFunctionItem &function)
// we make a new scope so the names of parameters are resolved and shadowed
// correctly
- for (auto ¶m : function.get_function_params ())
- if (!param.is_variadic ())
- ResolveType::go (param.get_type ().get ());
+ for (auto &it : function.get_function_params ())
+ if (!it->is_variadic ())
+ {
+ auto param = static_cast<AST::FunctionParam *> (it.get ());
+ ResolveType::go (param->get_type ().get ());
+ }
// done
resolver->get_name_scope ().pop ();
@@ -111,7 +111,7 @@ public:
static void go (AST::ExternalItem *item, const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
- void visit (AST::ExternalFunctionItem &function) override;
+ void visit (AST::Function &function) override;
void visit (AST::ExternalStaticItem &item) override;
private:
@@ -62,7 +62,8 @@ DefaultResolver::visit (AST::Function &function)
if (p->is_variadic ())
{
auto param = static_cast<AST::VariadicParam *> (p.get ());
- param->get_pattern ()->accept_vis (*this);
+ if (param->has_pattern ())
+ param->get_pattern ()->accept_vis (*this);
}
else if (p->is_self ())
{