diff mbox series

[042/125] gccrs: Remove dead code associated with `AST::ExternalFunctionItem`

Message ID 20240801145809.366388-44-arthur.cohen@embecosm.com
State New
Headers show
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work | expand

Commit Message

Arthur Cohen Aug. 1, 2024, 2:56 p.m. UTC
From: 0xn4utilus <gyanendrabanjare8@gmail.com>

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit):
	Remove dead code.
	* ast/rust-ast-collector.h: Likewise.
	* ast/rust-ast-full-decls.h (class ExternalFunctionItem):
	Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):
	Likewise.
	* ast/rust-ast-visitor.h: Likewise.
	* ast/rust-ast.cc (ExternalFunctionItem::as_string): Likewise.
	(ExternalFunctionItem::accept_vis): Likewise.
	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Likewise.
	* checks/errors/rust-ast-validation.h: Likewise.
	* checks/errors/rust-feature-gate.h: Likewise.
	* expand/rust-cfg-strip.cc (CfgStrip::visit):
	Likewise.
	* expand/rust-cfg-strip.h: Likewise.
	* expand/rust-derive.h: Likewise.
	* expand/rust-expand-visitor.cc (ExpandVisitor::visit):
	Likewise.
	* expand/rust-expand-visitor.h: Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit):
	Likewise.
	* hir/rust-ast-lower-base.h: Likewise.
	* metadata/rust-export-metadata.cc (ExportContext::emit_function):
	Likewise.
	* parse/rust-parse-impl.h: Likewise.
	* parse/rust-parse.h: Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit):
	Likewise.
	* resolve/rust-ast-resolve-base.h: Likewise.
	* resolve/rust-default-resolver.cc (DefaultResolver::visit):
	Likewise.
	* resolve/rust-default-resolver.h: Likewise.
	* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
	* util/rust-attributes.h: Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/extern_func_with_body.rs: New test.

Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
---
 gcc/rust/ast/rust-ast-collector.cc            | 25 -------
 gcc/rust/ast/rust-ast-collector.h             |  1 -
 gcc/rust/ast/rust-ast-full-decls.h            |  1 -
 gcc/rust/ast/rust-ast-visitor.cc              | 18 -----
 gcc/rust/ast/rust-ast-visitor.h               |  2 -
 gcc/rust/ast/rust-ast.cc                      | 69 -------------------
 gcc/rust/checks/errors/rust-ast-validation.cc | 19 -----
 gcc/rust/checks/errors/rust-ast-validation.h  |  1 -
 gcc/rust/checks/errors/rust-feature-gate.h    |  1 -
 gcc/rust/expand/rust-cfg-strip.cc             | 56 ---------------
 gcc/rust/expand/rust-cfg-strip.h              |  1 -
 gcc/rust/expand/rust-derive.h                 |  1 -
 gcc/rust/expand/rust-expand-visitor.cc        | 17 -----
 gcc/rust/expand/rust-expand-visitor.h         |  1 -
 gcc/rust/hir/rust-ast-lower-base.cc           |  3 -
 gcc/rust/hir/rust-ast-lower-base.h            |  1 -
 gcc/rust/metadata/rust-export-metadata.cc     | 41 +----------
 gcc/rust/parse/rust-parse-impl.h              | 62 -----------------
 gcc/rust/parse/rust-parse.h                   |  2 -
 gcc/rust/resolve/rust-ast-resolve-base.cc     |  4 --
 gcc/rust/resolve/rust-ast-resolve-base.h      |  1 -
 gcc/rust/resolve/rust-default-resolver.cc     |  4 --
 gcc/rust/resolve/rust-default-resolver.h      |  1 -
 gcc/rust/util/rust-attributes.cc              |  4 --
 gcc/rust/util/rust-attributes.h               |  1 -
 .../rust/compile/extern_func_with_body.rs     |  5 ++
 26 files changed, 7 insertions(+), 335 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/extern_func_with_body.rs
diff mbox series

Patch

diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index 744d0eb9d28..eb03dccaf84 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -2084,31 +2084,6 @@  TokenCollector::visit (ExternalStaticItem &item)
   push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
 }
 
-void
-TokenCollector::visit (ExternalFunctionItem &function)
-{
-  visit_items_as_lines (function.get_outer_attrs ());
-  visit (function.get_visibility ());
-
-  auto id = function.get_identifier ().as_string ();
-
-  push (Rust::Token::make (FN_KW, function.get_locus ()));
-  push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
-  if (function.has_generics ())
-    visit (function.get_generic_params ());
-  push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
-
-  visit_items_joined_by_separator (function.get_function_params ());
-
-  push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
-  if (function.has_return_type ())
-    {
-      push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION));
-      visit (function.get_return_type ());
-    }
-  push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
-}
-
 void
 TokenCollector::visit (ExternBlock &block)
 {
diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h
index ec695ef5b31..fdc99bb7086 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -333,7 +333,6 @@  public:
   void visit (TraitImpl &impl);
   void visit (ExternalTypeItem &item);
   void visit (ExternalStaticItem &item);
-  void visit (ExternalFunctionItem &item);
   void visit (ExternBlock &block);
 
   // rust-macro.h
diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h
index 8d5c8dbc821..dd982c448e0 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -203,7 +203,6 @@  class ExternalItem;
 class ExternalTypeItem;
 class ExternalStaticItem;
 class NamedFunctionParam;
-class ExternalFunctionItem;
 class ExternBlock;
 
 // rust-macro.h
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 697c2726309..de4242afeb5 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1004,24 +1004,6 @@  DefaultASTVisitor::visit (AST::NamedFunctionParam &param)
     visit (param.get_type ());
 }
 
-void
-DefaultASTVisitor::visit (AST::ExternalFunctionItem &item)
-{
-  visit_outer_attrs (item);
-  visit (item.get_visibility ());
-  for (auto &generic : item.get_generic_params ())
-    visit (generic);
-
-  if (item.has_where_clause ())
-    visit (item.get_where_clause ());
-
-  for (auto &param : item.get_function_params ())
-    visit (param);
-
-  if (item.has_return_type ())
-    visit (item.get_return_type ());
-}
-
 void
 DefaultASTVisitor::visit (AST::ExternBlock &block)
 {
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index c5c9a025ba6..622e7f766a3 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -164,7 +164,6 @@  public:
   // virtual void visit(ExternalItem& item) = 0;
   virtual void visit (ExternalTypeItem &type) = 0;
   virtual void visit (ExternalStaticItem &item) = 0;
-  virtual void visit (ExternalFunctionItem &item) = 0;
   virtual void visit (ExternBlock &block) = 0;
 
   // rust-macro.h
@@ -338,7 +337,6 @@  protected:
   virtual void visit (AST::TraitImpl &impl) override;
   virtual void visit (AST::ExternalTypeItem &item) override;
   virtual void visit (AST::ExternalStaticItem &item) override;
-  virtual void visit (AST::ExternalFunctionItem &item) override;
   virtual void visit (AST::ExternBlock &block) override;
   virtual void visit (AST::MacroMatchFragment &match) override;
   virtual void visit (AST::MacroMatchRepetition &match) override;
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 5d661989904..6eb3394c146 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -2974,69 +2974,6 @@  ExternalStaticItem::as_string () const
   return str;
 }
 
-std::string
-ExternalFunctionItem::as_string () const
-{
-  // outer attributes
-  std::string str = append_attributes (outer_attrs, OUTER);
-
-  // start visibility on new line and with a space
-  str += "\n" + visibility.as_string () + " ";
-
-  str += "fn ";
-
-  // add name
-  str += item_name.as_string ();
-
-  // generic params
-  str += "\n Generic params: ";
-  if (generic_params.empty ())
-    {
-      str += "none";
-    }
-  else
-    {
-      for (const auto &param : generic_params)
-	{
-	  // DEBUG: null pointer check
-	  if (param == nullptr)
-	    {
-	      rust_debug (
-		"something really terrible has gone wrong - null pointer "
-		"generic param in external function item.");
-	      return "NULL_POINTER_MARK";
-	    }
-
-	  str += "\n  " + param->as_string ();
-	}
-    }
-
-  // function params
-  str += "\n Function params: ";
-  if (function_params.empty ())
-    {
-      str += "none";
-    }
-  else
-    {
-      for (const auto &param : function_params)
-	str += "\n  " + param.as_string ();
-    }
-
-  // add type on new line
-  str += "\n (return) Type: "
-	 + (has_return_type () ? return_type->as_string () : "()");
-
-  // where clause
-  str += "\n Where clause: ";
-  if (has_where_clause ())
-    str += where_clause.as_string ();
-  else
-    str += "none";
-
-  return str;
-}
-
 std::string
 NamedFunctionParam::as_string () const
 {
@@ -4866,12 +4803,6 @@  ExternalStaticItem::accept_vis (ASTVisitor &vis)
   vis.visit (*this);
 }
 
-void
-ExternalFunctionItem::accept_vis (ASTVisitor &vis)
-{
-  vis.visit (*this);
-}
-
 void
 ExternBlock::accept_vis (ASTVisitor &vis)
 {
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index f5a97b0d350..d1edb890ae6 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -64,25 +64,6 @@  ASTValidation::visit (AST::ConstantItem &const_item)
   AST::ContextualASTVisitor::visit (const_item);
 }
 
-void
-ASTValidation::visit (AST::ExternalFunctionItem &item)
-{
-  auto &params = item.get_function_params ();
-
-  if (params.size () == 1 && params[0].is_variadic ())
-    rust_error_at (
-      params[0].get_locus (),
-      "C-variadic function must be declared with at least one named argument");
-
-  for (auto it = params.begin (); it != params.end (); it++)
-    if (it->is_variadic () && it + 1 != params.end ())
-      rust_error_at (
-	it->get_locus (),
-	"%<...%> must be the last argument of a C-variadic function");
-
-  AST::ContextualASTVisitor::visit (item);
-}
-
 void
 ASTValidation::visit (AST::Union &item)
 {
diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h
index 641fb26f089..53352c1a64e 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.h
+++ b/gcc/rust/checks/errors/rust-ast-validation.h
@@ -38,7 +38,6 @@  public:
   virtual void visit (AST::ConstantItem &const_item);
   virtual void visit (AST::Lifetime &lifetime);
   virtual void visit (AST::LoopLabel &label);
-  virtual void visit (AST::ExternalFunctionItem &item);
   virtual void visit (AST::Union &item);
   virtual void visit (AST::Function &function);
   virtual void visit (AST::Trait &trait);
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h
index ef7449aa581..481b5a53061 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -130,7 +130,6 @@  public:
   void visit (AST::Trait &trait) override {}
   void visit (AST::ExternalTypeItem &item) override;
   void visit (AST::ExternalStaticItem &item) override {}
-  void visit (AST::ExternalFunctionItem &item) override {}
   void visit (AST::ExternBlock &block) override;
   void visit (AST::MacroMatchFragment &match) override {}
   void visit (AST::MacroMatchRepetition &match) override {}
diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc
index 2b51a890247..923015fa05e 100644
--- a/gcc/rust/expand/rust-cfg-strip.cc
+++ b/gcc/rust/expand/rust-cfg-strip.cc
@@ -2195,62 +2195,6 @@  CfgStrip::visit (AST::ExternalStaticItem &item)
     rust_error_at (type->get_locus (), "cannot strip type in this position");
 }
 
-void
-CfgStrip::visit (AST::ExternalFunctionItem &item)
-{
-  // strip test based on outer attrs
-  expand_cfg_attrs (item.get_outer_attrs ());
-  if (fails_cfg_with_expand (item.get_outer_attrs ()))
-    {
-      item.mark_for_strip ();
-      return;
-    }
-
-  AST::DefaultASTVisitor::visit (item);
-
-  /* strip function parameters if required - this is specifically
-   * allowed by spec */
-  auto &params = item.get_function_params ();
-  for (auto it = params.begin (); it != params.end ();)
-    {
-      auto &param = *it;
-
-      auto &param_attrs = param.get_outer_attrs ();
-      expand_cfg_attrs (param_attrs);
-      if (fails_cfg_with_expand (param_attrs))
-	{
-	  it = params.erase (it);
-	  continue;
-	}
-
-      if (!param.is_variadic ())
-	{
-	  auto &type = param.get_type ();
-	  if (type->is_marked_for_strip ())
-	    rust_error_at (type->get_locus (),
-			   "cannot strip type in this position");
-	}
-
-      // increment if nothing else happens
-      ++it;
-    }
-  /* NOTE: these are extern function params, which may have different
-   * rules and restrictions to "normal" function params. So expansion
-   * handled separately. */
-
-  /* TODO: assuming that variadic nature cannot be stripped. If this
-   * is not true, then have code here to do so. */
-
-  if (item.has_return_type ())
-    {
-      auto &return_type = item.get_return_type ();
-
-      if (return_type->is_marked_for_strip ())
-	rust_error_at (return_type->get_locus (),
-		       "cannot strip type in this position");
-    }
-}
-
 void
 CfgStrip::visit (AST::ExternBlock &block)
 {
diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h
index a3931823ab1..4a8e6041ff2 100644
--- a/gcc/rust/expand/rust-cfg-strip.h
+++ b/gcc/rust/expand/rust-cfg-strip.h
@@ -150,7 +150,6 @@  public:
   void visit (AST::TraitImpl &impl) override;
   void visit (AST::ExternalTypeItem &item) override;
   void visit (AST::ExternalStaticItem &item) override;
-  void visit (AST::ExternalFunctionItem &item) override;
   void visit (AST::ExternBlock &block) override;
 
   // I don't think it would be possible to strip macros without expansion
diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h
index f953c3decbf..cbe5bbbcbea 100644
--- a/gcc/rust/expand/rust-derive.h
+++ b/gcc/rust/expand/rust-derive.h
@@ -166,7 +166,6 @@  private:
   virtual void visit (TraitImpl &impl) override final{};
   virtual void visit (ExternalTypeItem &type) override final{};
   virtual void visit (ExternalStaticItem &item) override final{};
-  virtual void visit (ExternalFunctionItem &item) override final{};
   virtual void visit (ExternBlock &block) override final{};
   virtual void visit (MacroMatchFragment &match) override final{};
   virtual void visit (MacroMatchRepetition &match) override final{};
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index bd49fd91092..6c1efb1d2e0 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -922,23 +922,6 @@  ExpandVisitor::visit (AST::ExternalStaticItem &static_item)
   maybe_expand_type (static_item.get_type ());
 }
 
-void
-ExpandVisitor::visit (AST::ExternalFunctionItem &item)
-{
-  for (auto &param : item.get_generic_params ())
-    visit (param);
-
-  for (auto &param : item.get_function_params ())
-    if (!param.is_variadic ())
-      maybe_expand_type (param.get_type ());
-
-  if (item.has_return_type ())
-    maybe_expand_type (item.get_return_type ());
-
-  if (item.has_where_clause ())
-    expand_where_clause (item.get_where_clause ());
-}
-
 void
 ExpandVisitor::visit (AST::ExternBlock &block)
 {
diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h
index f40b5773fc1..034aeede2f4 100644
--- a/gcc/rust/expand/rust-expand-visitor.h
+++ b/gcc/rust/expand/rust-expand-visitor.h
@@ -252,7 +252,6 @@  public:
   void visit (AST::TraitImpl &impl) override;
   void visit (AST::ExternalTypeItem &item) override;
   void visit (AST::ExternalStaticItem &item) override;
-  void visit (AST::ExternalFunctionItem &item) override;
   void visit (AST::ExternBlock &block) override;
 
   // I don't think it would be possible to strip macros without expansion
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index 54c05208e7b..ff6ef25a348 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -345,9 +345,6 @@  void
 ASTLoweringBase::visit (AST::ExternalStaticItem &)
 {}
 void
-ASTLoweringBase::visit (AST::ExternalFunctionItem &)
-{}
-void
 ASTLoweringBase::visit (AST::ExternBlock &)
 {}
 
diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h
index 7b0ce375f83..c19e9c03b5f 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -186,7 +186,6 @@  public:
   //  virtual void visit(ExternalItem& item);
   virtual void visit (AST::ExternalTypeItem &item);
   virtual void visit (AST::ExternalStaticItem &item);
-  virtual void visit (AST::ExternalFunctionItem &item);
   virtual void visit (AST::ExternBlock &block);
 
   // rust-macro.h
diff --git a/gcc/rust/metadata/rust-export-metadata.cc b/gcc/rust/metadata/rust-export-metadata.cc
index a946c67422d..589511ef9ce 100644
--- a/gcc/rust/metadata/rust-export-metadata.cc
+++ b/gcc/rust/metadata/rust-export-metadata.cc
@@ -93,46 +93,9 @@  ExportContext::emit_function (const HIR::Function &fn)
       // FIXME assert that this is actually an AST::Function
       AST::Function &function = static_cast<AST::Function &> (vis_item);
 
-      // we can emit an extern block with abi of "rust"
-      Identifier item_name = function.get_function_name ();
-
-      // always empty for extern linkage
-      AST::WhereClause where_clause = AST::WhereClause::create_empty ();
-      std::vector<std::unique_ptr<AST::GenericParam>> generic_params;
-
-      AST::Visibility vis = function.get_visibility ();
-      std::unique_ptr<AST::Type> return_type
-	= std::unique_ptr<AST::Type> (nullptr);
-      if (function.has_return_type ())
-	{
-	  return_type = function.get_return_type ()->clone_type ();
-	}
-
-      std::vector<AST::NamedFunctionParam> function_params;
-      for (auto &p : function.get_function_params ())
-	{
-	  if (p->is_variadic () || p->is_self ())
-	    rust_unreachable ();
-	  auto param = static_cast<AST::FunctionParam *> (p.get ());
-	  std::string name = param->get_pattern ()->as_string ();
-	  std::unique_ptr<AST::Type> param_type
-	    = param->get_type ()->clone_type ();
-
-	  AST::NamedFunctionParam np (name, std::move (param_type), {},
-				      param->get_locus ());
-	  function_params.push_back (std::move (np));
-	}
-
-      AST::ExternalItem *external_item
-	= new AST::ExternalFunctionItem (item_name, {} /* generic_params */,
-					 std::move (return_type), where_clause,
-					 std::move (function_params), vis,
-					 function.get_outer_attrs (),
-					 function.get_locus ());
-
       std::vector<std::unique_ptr<AST::ExternalItem>> external_items;
-      external_items.push_back (
-	std::unique_ptr<AST::ExternalItem> (external_item));
+      external_items.push_back (std::unique_ptr<AST::ExternalItem> (
+	static_cast<AST::ExternalItem *> (&function)));
 
       AST::ExternBlock extern_block (get_string_from_abi (Rust::ABI::RUST),
 				     std::move (external_items),
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 26b24150f7a..b6c2ca3fc0c 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6034,68 +6034,6 @@  Parser<ManagedTokenSource>::parse_named_function_params (
   return params;
 }
 
-template <typename ManagedTokenSource>
-std::unique_ptr<AST::ExternalFunctionItem>
-Parser<ManagedTokenSource>::parse_external_function_item (
-  AST::Visibility vis, AST::AttrVec outer_attrs)
-{
-  location_t locus = lexer.peek_token ()->get_locus ();
-
-  // parse extern function declaration item
-  // skip function token
-  lexer.skip_token ();
-
-  // parse identifier
-  const_TokenPtr ident_tok = expect_token (IDENTIFIER);
-  if (ident_tok == nullptr)
-    {
-      skip_after_semicolon ();
-      return nullptr;
-    }
-  Identifier ident{ident_tok};
-
-  // parse (optional) generic params
-  std::vector<std::unique_ptr<AST::GenericParam>> generic_params
-    = parse_generic_params_in_angles ();
-
-  if (!skip_token (LEFT_PAREN))
-    {
-      skip_after_semicolon ();
-      return nullptr;
-    }
-
-  // parse parameters
-  std::vector<AST::NamedFunctionParam> function_params
-    = parse_named_function_params (
-      [] (TokenId id) { return id == RIGHT_PAREN; });
-
-  if (!skip_token (RIGHT_PAREN))
-    {
-      skip_after_semicolon ();
-      return nullptr;
-    }
-
-  // parse (optional) return type
-  std::unique_ptr<AST::Type> return_type = parse_function_return_type ();
-
-  // parse (optional) where clause
-  AST::WhereClause where_clause = parse_where_clause ();
-
-  if (!skip_token (SEMICOLON))
-    {
-      // skip somewhere?
-      return nullptr;
-    }
-
-  function_params.shrink_to_fit ();
-
-  return std::unique_ptr<AST::ExternalFunctionItem> (
-    new AST::ExternalFunctionItem (
-      std::move (ident), std::move (generic_params), std::move (return_type),
-      std::move (where_clause), std::move (function_params), std::move (vis),
-      std::move (outer_attrs), locus));
-}
-
 // Parses a single extern block item (static or function declaration).
 template <typename ManagedTokenSource>
 std::unique_ptr<AST::ExternalItem>
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index cdddfa6dff9..c00bf9c7e2e 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -310,8 +310,6 @@  private:
   AST::Lifetime lifetime_from_token (const_TokenPtr tok);
   std::unique_ptr<AST::ExternalTypeItem>
   parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);
-  std::unique_ptr<AST::ExternalFunctionItem>
-  parse_external_function_item (AST::Visibility vis, AST::AttrVec outer_attrs);
   AST::NamedFunctionParam parse_named_function_param ();
   template <typename EndTokenPred>
   std::vector<AST::NamedFunctionParam>
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc
index 5a9f54fc7f1..1ef162d37e0 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-base.cc
@@ -430,10 +430,6 @@  void
 ResolverBase::visit (AST::ExternalStaticItem &)
 {}
 
-void
-ResolverBase::visit (AST::ExternalFunctionItem &)
-{}
-
 void
 ResolverBase::visit (AST::ExternBlock &)
 {}
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h
index 3b4d28618e4..648243b6fb6 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.h
+++ b/gcc/rust/resolve/rust-ast-resolve-base.h
@@ -135,7 +135,6 @@  public:
 
   void visit (AST::ExternalTypeItem &);
   void visit (AST::ExternalStaticItem &);
-  void visit (AST::ExternalFunctionItem &);
   void visit (AST::ExternBlock &);
 
   void visit (AST::MacroMatchFragment &);
diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc
index c99f2f64331..789cc4eef42 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -492,10 +492,6 @@  void
 DefaultResolver::visit (AST::ExternalStaticItem &)
 {}
 
-void
-DefaultResolver::visit (AST::ExternalFunctionItem &)
-{}
-
 void
 DefaultResolver::visit (AST::MacroMatchRepetition &)
 {}
diff --git a/gcc/rust/resolve/rust-default-resolver.h b/gcc/rust/resolve/rust-default-resolver.h
index 20458ede7bc..97ad6d78be3 100644
--- a/gcc/rust/resolve/rust-default-resolver.h
+++ b/gcc/rust/resolve/rust-default-resolver.h
@@ -118,7 +118,6 @@  public:
   void visit (AST::TraitItemType &);
   void visit (AST::ExternalTypeItem &);
   void visit (AST::ExternalStaticItem &);
-  void visit (AST::ExternalFunctionItem &);
   void visit (AST::MacroMatchRepetition &);
   void visit (AST::MacroMatcher &);
   void visit (AST::MacroRulesDefinition &);
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 715e9a0b361..eac29808299 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -766,10 +766,6 @@  void
 AttributeChecker::visit (AST::ExternalStaticItem &)
 {}
 
-void
-AttributeChecker::visit (AST::ExternalFunctionItem &)
-{}
-
 void
 AttributeChecker::visit (AST::ExternBlock &block)
 {
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index d78ab0b3319..f557b2d46b3 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -199,7 +199,6 @@  private:
   void visit (AST::TraitImpl &impl) override;
   void visit (AST::ExternalTypeItem &item) override;
   void visit (AST::ExternalStaticItem &item) override;
-  void visit (AST::ExternalFunctionItem &item) override;
   void visit (AST::ExternBlock &block) override;
 
   // rust-macro.h
diff --git a/gcc/testsuite/rust/compile/extern_func_with_body.rs b/gcc/testsuite/rust/compile/extern_func_with_body.rs
new file mode 100644
index 00000000000..180c4340c31
--- /dev/null
+++ b/gcc/testsuite/rust/compile/extern_func_with_body.rs
@@ -0,0 +1,5 @@ 
+extern "C" {
+    fn myfun0(a:i32,...) {}
+    // { dg-error "cannot have a body" "" { target *-*-* } .-1 }
+}
+