aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/Make-lang.in1
-rw-r--r--gcc/rust/ast/rust-ast-dump.cc750
-rw-r--r--gcc/rust/ast/rust-ast-dump.h239
-rw-r--r--gcc/rust/lint/rust-lint-marklive.h6
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.cc2
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.cc49
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.h7
-rw-r--r--gcc/testsuite/rust/compile/torture/arrays_index3.rs15
8 files changed, 1046 insertions, 23 deletions
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 5d97a16..2b107c1 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -69,6 +69,7 @@ GRS_OBJS = \
rust/rust-cfg-parser.o \
rust/rust-parse.o \
rust/rust-ast-full-test.o \
+ rust/rust-ast-dump.o \
rust/rust-session-manager.o \
rust/rust-compile.o \
rust/rust-mangle.o \
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
new file mode 100644
index 0000000..64966c9
--- /dev/null
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -0,0 +1,750 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-ast-dump.h"
+
+namespace Rust {
+namespace AST {
+
+Indent::Indent () : tabs (0) {}
+
+std::ostream &
+operator<< (std::ostream &stream, const Indent &indent)
+{
+ return stream << std::string (indent.tabs, '\t');
+}
+
+void
+Indent::increment ()
+{
+ tabs++;
+}
+
+void
+Indent::decrement ()
+{
+ rust_assert (tabs != 0);
+ tabs--;
+}
+
+Dump::Dump (std::ostream &stream) : stream (stream), indentation (Indent ()) {}
+
+void
+Dump::go (AST::Crate &crate)
+{
+ for (auto &item : crate.items)
+ item->accept_vis (*this);
+}
+
+void
+Dump::format_function_param (FunctionParam &param)
+{
+ param.get_pattern ()->accept_vis (*this);
+ stream << ": ";
+ param.get_type ()->accept_vis (*this);
+}
+
+void
+Dump::visit (Token &tok)
+{}
+
+void
+Dump::visit (DelimTokenTree &delim_tok_tree)
+{}
+
+void
+Dump::visit (AttrInputMetaItemContainer &input)
+{}
+
+void
+Dump::visit (IdentifierExpr &ident_expr)
+{}
+
+void
+Dump::visit (Lifetime &lifetime)
+{}
+
+void
+Dump::visit (LifetimeParam &lifetime_param)
+{}
+
+// rust-path.h
+void
+Dump::visit (PathInExpression &path)
+{}
+
+void
+Dump::visit (TypePathSegment &segment)
+{}
+
+void
+Dump::visit (TypePathSegmentGeneric &segment)
+{}
+
+void
+Dump::visit (TypePathSegmentFunction &segment)
+{}
+
+void
+Dump::visit (TypePath &path)
+{}
+
+void
+Dump::visit (QualifiedPathInExpression &path)
+{}
+
+void
+Dump::visit (QualifiedPathInType &path)
+{}
+
+// rust-expr.h
+void
+Dump::visit (LiteralExpr &expr)
+{}
+
+void
+Dump::visit (AttrInputLiteral &attr_input)
+{}
+
+void
+Dump::visit (MetaItemLitExpr &meta_item)
+{}
+
+void
+Dump::visit (MetaItemPathLit &meta_item)
+{}
+
+void
+Dump::visit (BorrowExpr &expr)
+{}
+
+void
+Dump::visit (DereferenceExpr &expr)
+{}
+
+void
+Dump::visit (ErrorPropagationExpr &expr)
+{}
+
+void
+Dump::visit (NegationExpr &expr)
+{}
+
+void
+Dump::visit (ArithmeticOrLogicalExpr &expr)
+{}
+
+void
+Dump::visit (ComparisonExpr &expr)
+{}
+
+void
+Dump::visit (LazyBooleanExpr &expr)
+{}
+
+void
+Dump::visit (TypeCastExpr &expr)
+{}
+
+void
+Dump::visit (AssignmentExpr &expr)
+{}
+
+void
+Dump::visit (CompoundAssignmentExpr &expr)
+{}
+
+void
+Dump::visit (GroupedExpr &expr)
+{}
+
+void
+Dump::visit (ArrayElemsValues &elems)
+{}
+
+void
+Dump::visit (ArrayElemsCopied &elems)
+{}
+
+void
+Dump::visit (ArrayExpr &expr)
+{}
+
+void
+Dump::visit (ArrayIndexExpr &expr)
+{}
+
+void
+Dump::visit (TupleExpr &expr)
+{}
+
+void
+Dump::visit (TupleIndexExpr &expr)
+{}
+
+void
+Dump::visit (StructExprStruct &expr)
+{}
+
+void
+Dump::visit (StructExprFieldIdentifier &field)
+{}
+
+void
+Dump::visit (StructExprFieldIdentifierValue &field)
+{}
+
+void
+Dump::visit (StructExprFieldIndexValue &field)
+{}
+
+void
+Dump::visit (StructExprStructFields &expr)
+{}
+
+void
+Dump::visit (StructExprStructBase &expr)
+{}
+
+void
+Dump::visit (CallExpr &expr)
+{}
+
+void
+Dump::visit (MethodCallExpr &expr)
+{}
+
+void
+Dump::visit (FieldAccessExpr &expr)
+{}
+
+void
+Dump::visit (ClosureExprInner &expr)
+{}
+
+void
+Dump::visit (BlockExpr &expr)
+{
+ stream << "{\n";
+ indentation.increment ();
+
+ for (auto &stmt : expr.get_statements ())
+ {
+ stream << indentation;
+ stmt->accept_vis (*this);
+ stream << ";\n";
+ }
+
+ if (expr.has_tail_expr ())
+ expr.get_tail_expr ()->accept_vis (*this);
+
+ stream << "\n}\n";
+ indentation.increment ();
+}
+
+void
+Dump::visit (ClosureExprInnerTyped &expr)
+{}
+
+void
+Dump::visit (ContinueExpr &expr)
+{}
+
+void
+Dump::visit (BreakExpr &expr)
+{}
+
+void
+Dump::visit (RangeFromToExpr &expr)
+{}
+
+void
+Dump::visit (RangeFromExpr &expr)
+{}
+
+void
+Dump::visit (RangeToExpr &expr)
+{}
+
+void
+Dump::visit (RangeFullExpr &expr)
+{}
+
+void
+Dump::visit (RangeFromToInclExpr &expr)
+{}
+
+void
+Dump::visit (RangeToInclExpr &expr)
+{}
+
+void
+Dump::visit (ReturnExpr &expr)
+{}
+
+void
+Dump::visit (UnsafeBlockExpr &expr)
+{}
+
+void
+Dump::visit (LoopExpr &expr)
+{}
+
+void
+Dump::visit (WhileLoopExpr &expr)
+{}
+
+void
+Dump::visit (WhileLetLoopExpr &expr)
+{}
+
+void
+Dump::visit (ForLoopExpr &expr)
+{}
+
+void
+Dump::visit (IfExpr &expr)
+{}
+
+void
+Dump::visit (IfExprConseqElse &expr)
+{}
+
+void
+Dump::visit (IfExprConseqIf &expr)
+{}
+
+void
+Dump::visit (IfExprConseqIfLet &expr)
+{}
+
+void
+Dump::visit (IfLetExpr &expr)
+{}
+
+void
+Dump::visit (IfLetExprConseqElse &expr)
+{}
+
+void
+Dump::visit (IfLetExprConseqIf &expr)
+{}
+
+void
+Dump::visit (IfLetExprConseqIfLet &expr)
+{}
+
+void
+Dump::visit (MatchExpr &expr)
+{}
+
+void
+Dump::visit (AwaitExpr &expr)
+{}
+
+void
+Dump::visit (AsyncBlockExpr &expr)
+{}
+
+// rust-item.h
+void
+Dump::visit (TypeParam &param)
+{}
+
+void
+Dump::visit (LifetimeWhereClauseItem &item)
+{}
+
+void
+Dump::visit (TypeBoundWhereClauseItem &item)
+{}
+
+void
+Dump::visit (Method &method)
+{}
+
+void
+Dump::visit (Module &module)
+{}
+
+void
+Dump::visit (ExternCrate &crate)
+{}
+
+void
+Dump::visit (UseTreeGlob &use_tree)
+{}
+
+void
+Dump::visit (UseTreeList &use_tree)
+{}
+
+void
+Dump::visit (UseTreeRebind &use_tree)
+{}
+
+void
+Dump::visit (UseDeclaration &use_decl)
+{}
+
+void
+Dump::visit (Function &function)
+{
+ stream << "fn " << function.get_function_name () << '(';
+
+ auto &params = function.get_function_params ();
+ if (params.size () >= 1)
+ {
+ format_function_param (params[0]);
+ for (size_t i = 1; i < params.size (); i++)
+ {
+ stream << ", ";
+ format_function_param (params[i]);
+ }
+ }
+
+ stream << ") ";
+
+ if (function.has_return_type ())
+ {
+ stream << "-> ";
+ function.get_return_type ()->accept_vis (*this);
+ }
+
+ auto &block = function.get_definition ();
+ if (!block)
+ stream << ';';
+ else
+ block->accept_vis (*this);
+
+ stream << '\n';
+}
+
+void
+Dump::visit (TypeAlias &type_alias)
+{}
+
+void
+Dump::visit (StructStruct &struct_item)
+{}
+
+void
+Dump::visit (TupleStruct &tuple_struct)
+{}
+
+void
+Dump::visit (EnumItem &item)
+{}
+
+void
+Dump::visit (EnumItemTuple &item)
+{}
+
+void
+Dump::visit (EnumItemStruct &item)
+{}
+
+void
+Dump::visit (EnumItemDiscriminant &item)
+{}
+
+void
+Dump::visit (Enum &enum_item)
+{}
+
+void
+Dump::visit (Union &union_item)
+{}
+
+void
+Dump::visit (ConstantItem &const_item)
+{}
+
+void
+Dump::visit (StaticItem &static_item)
+{}
+
+void
+Dump::visit (TraitItemFunc &item)
+{}
+
+void
+Dump::visit (TraitItemMethod &item)
+{}
+
+void
+Dump::visit (TraitItemConst &item)
+{}
+
+void
+Dump::visit (TraitItemType &item)
+{}
+
+void
+Dump::visit (Trait &trait)
+{}
+
+void
+Dump::visit (InherentImpl &impl)
+{}
+
+void
+Dump::visit (TraitImpl &impl)
+{}
+
+void
+Dump::visit (ExternalStaticItem &item)
+{}
+
+void
+Dump::visit (ExternalFunctionItem &item)
+{}
+
+void
+Dump::visit (ExternBlock &block)
+{}
+
+// rust-macro.h
+void
+Dump::visit (MacroMatchFragment &match)
+{}
+
+void
+Dump::visit (MacroMatchRepetition &match)
+{}
+
+void
+Dump::visit (MacroMatcher &matcher)
+{}
+
+void
+Dump::visit (MacroRulesDefinition &rules_def)
+{}
+
+void
+Dump::visit (MacroInvocation &macro_invoc)
+{}
+
+void
+Dump::visit (MetaItemPath &meta_item)
+{}
+
+void
+Dump::visit (MetaItemSeq &meta_item)
+{}
+
+void
+Dump::visit (MetaWord &meta_item)
+{}
+
+void
+Dump::visit (MetaNameValueStr &meta_item)
+{}
+
+void
+Dump::visit (MetaListPaths &meta_item)
+{}
+
+void
+Dump::visit (MetaListNameValueStr &meta_item)
+{}
+
+// rust-pattern.h
+void
+Dump::visit (LiteralPattern &pattern)
+{}
+
+void
+Dump::visit (IdentifierPattern &pattern)
+{
+ stream << pattern.get_ident ();
+}
+
+void
+Dump::visit (WildcardPattern &pattern)
+{}
+
+// void Dump::visit(RangePatternBound& bound){}
+
+void
+Dump::visit (RangePatternBoundLiteral &bound)
+{}
+
+void
+Dump::visit (RangePatternBoundPath &bound)
+{}
+
+void
+Dump::visit (RangePatternBoundQualPath &bound)
+{}
+
+void
+Dump::visit (RangePattern &pattern)
+{}
+
+void
+Dump::visit (ReferencePattern &pattern)
+{}
+
+// void Dump::visit(StructPatternField& field){}
+
+void
+Dump::visit (StructPatternFieldTuplePat &field)
+{}
+
+void
+Dump::visit (StructPatternFieldIdentPat &field)
+{}
+
+void
+Dump::visit (StructPatternFieldIdent &field)
+{}
+
+void
+Dump::visit (StructPattern &pattern)
+{}
+
+// void Dump::visit(TupleStructItems& tuple_items){}
+
+void
+Dump::visit (TupleStructItemsNoRange &tuple_items)
+{}
+
+void
+Dump::visit (TupleStructItemsRange &tuple_items)
+{}
+
+void
+Dump::visit (TupleStructPattern &pattern)
+{}
+
+// void Dump::visit(TuplePatternItems& tuple_items){}
+
+void
+Dump::visit (TuplePatternItemsMultiple &tuple_items)
+{}
+
+void
+Dump::visit (TuplePatternItemsRanged &tuple_items)
+{}
+
+void
+Dump::visit (TuplePattern &pattern)
+{}
+
+void
+Dump::visit (GroupedPattern &pattern)
+{}
+
+void
+Dump::visit (SlicePattern &pattern)
+{}
+
+// rust-stmt.h
+void
+Dump::visit (EmptyStmt &stmt)
+{}
+
+void
+Dump::visit (LetStmt &stmt)
+{
+ stream << "let ";
+ auto &pattern = stmt.get_pattern ();
+ if (pattern)
+ pattern->accept_vis (*this);
+
+ if (stmt.has_type ())
+ {
+ stream << ": ";
+ stmt.get_type ()->accept_vis (*this);
+ }
+
+ if (stmt.has_init_expr ())
+ {
+ stream << " = ";
+ stmt.get_init_expr ()->accept_vis (*this);
+ }
+}
+
+void
+Dump::visit (ExprStmtWithoutBlock &stmt)
+{}
+
+void
+Dump::visit (ExprStmtWithBlock &stmt)
+{}
+
+// rust-type.h
+void
+Dump::visit (TraitBound &bound)
+{}
+
+void
+Dump::visit (ImplTraitType &type)
+{}
+
+void
+Dump::visit (TraitObjectType &type)
+{}
+
+void
+Dump::visit (ParenthesisedType &type)
+{}
+
+void
+Dump::visit (ImplTraitTypeOneBound &type)
+{}
+
+void
+Dump::visit (TraitObjectTypeOneBound &type)
+{}
+
+void
+Dump::visit (TupleType &type)
+{}
+
+void
+Dump::visit (NeverType &type)
+{}
+
+void
+Dump::visit (RawPointerType &type)
+{}
+
+void
+Dump::visit (ReferenceType &type)
+{}
+
+void
+Dump::visit (ArrayType &type)
+{}
+
+void
+Dump::visit (SliceType &type)
+{}
+
+void
+Dump::visit (InferredType &type)
+{}
+
+void
+Dump::visit (BareFunctionType &type)
+{}
+
+} // namespace AST
+} // namespace Rust
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
new file mode 100644
index 0000000..436c2b5
--- /dev/null
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -0,0 +1,239 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-ast-visitor.h"
+#include "rust-ast.h"
+#include "rust-ast-full.h"
+
+#ifndef RUST_AST_DUMP_H
+#define RUST_AST_DUMP_H
+
+namespace Rust {
+namespace AST {
+
+// TODO: We might want to reuse this class somewhere else
+class Indent
+{
+public:
+ Indent ();
+
+ friend std::ostream &operator<< (std::ostream &stream, const Indent &indent);
+
+ void increment ();
+ void decrement ();
+
+private:
+ size_t tabs;
+};
+
+class Dump : public ASTVisitor
+{
+public:
+ Dump (std::ostream &stream);
+
+ /**
+ * Run the visitor on an entire crate and its items
+ */
+ void go (AST::Crate &crate);
+
+private:
+ std::ostream &stream;
+ Indent indentation;
+
+ /**
+ * Format a function's definition parameter
+ */
+ void format_function_param (FunctionParam &param);
+
+ // rust-ast.h
+ void visit (Token &tok);
+ void visit (DelimTokenTree &delim_tok_tree);
+ void visit (AttrInputMetaItemContainer &input);
+ void visit (IdentifierExpr &ident_expr);
+ void visit (Lifetime &lifetime);
+ void visit (LifetimeParam &lifetime_param);
+
+ // rust-path.h
+ void visit (PathInExpression &path);
+ void visit (TypePathSegment &segment);
+ void visit (TypePathSegmentGeneric &segment);
+ void visit (TypePathSegmentFunction &segment);
+ void visit (TypePath &path);
+ void visit (QualifiedPathInExpression &path);
+ void visit (QualifiedPathInType &path);
+
+ // rust-expr.h
+ void visit (LiteralExpr &expr);
+ void visit (AttrInputLiteral &attr_input);
+ void visit (MetaItemLitExpr &meta_item);
+ void visit (MetaItemPathLit &meta_item);
+ void visit (BorrowExpr &expr);
+ void visit (DereferenceExpr &expr);
+ void visit (ErrorPropagationExpr &expr);
+ void visit (NegationExpr &expr);
+ void visit (ArithmeticOrLogicalExpr &expr);
+ void visit (ComparisonExpr &expr);
+ void visit (LazyBooleanExpr &expr);
+ void visit (TypeCastExpr &expr);
+ void visit (AssignmentExpr &expr);
+ void visit (CompoundAssignmentExpr &expr);
+ void visit (GroupedExpr &expr);
+ void visit (ArrayElemsValues &elems);
+ void visit (ArrayElemsCopied &elems);
+ void visit (ArrayExpr &expr);
+ void visit (ArrayIndexExpr &expr);
+ void visit (TupleExpr &expr);
+ void visit (TupleIndexExpr &expr);
+ void visit (StructExprStruct &expr);
+ void visit (StructExprFieldIdentifier &field);
+ void visit (StructExprFieldIdentifierValue &field);
+ void visit (StructExprFieldIndexValue &field);
+ void visit (StructExprStructFields &expr);
+ void visit (StructExprStructBase &expr);
+ void visit (CallExpr &expr);
+ void visit (MethodCallExpr &expr);
+ void visit (FieldAccessExpr &expr);
+ void visit (ClosureExprInner &expr);
+ void visit (BlockExpr &expr);
+ void visit (ClosureExprInnerTyped &expr);
+ void visit (ContinueExpr &expr);
+ void visit (BreakExpr &expr);
+ void visit (RangeFromToExpr &expr);
+ void visit (RangeFromExpr &expr);
+ void visit (RangeToExpr &expr);
+ void visit (RangeFullExpr &expr);
+ void visit (RangeFromToInclExpr &expr);
+ void visit (RangeToInclExpr &expr);
+ void visit (ReturnExpr &expr);
+ void visit (UnsafeBlockExpr &expr);
+ void visit (LoopExpr &expr);
+ void visit (WhileLoopExpr &expr);
+ void visit (WhileLetLoopExpr &expr);
+ void visit (ForLoopExpr &expr);
+ void visit (IfExpr &expr);
+ void visit (IfExprConseqElse &expr);
+ void visit (IfExprConseqIf &expr);
+ void visit (IfExprConseqIfLet &expr);
+ void visit (IfLetExpr &expr);
+ void visit (IfLetExprConseqElse &expr);
+ void visit (IfLetExprConseqIf &expr);
+ void visit (IfLetExprConseqIfLet &expr);
+ void visit (MatchExpr &expr);
+ void visit (AwaitExpr &expr);
+ void visit (AsyncBlockExpr &expr);
+
+ // rust-item.h
+ void visit (TypeParam &param);
+ void visit (LifetimeWhereClauseItem &item);
+ void visit (TypeBoundWhereClauseItem &item);
+ void visit (Method &method);
+ void visit (Module &module);
+ void visit (ExternCrate &crate);
+ void visit (UseTreeGlob &use_tree);
+ void visit (UseTreeList &use_tree);
+ void visit (UseTreeRebind &use_tree);
+ void visit (UseDeclaration &use_decl);
+ void visit (Function &function);
+ void visit (TypeAlias &type_alias);
+ void visit (StructStruct &struct_item);
+ void visit (TupleStruct &tuple_struct);
+ void visit (EnumItem &item);
+ void visit (EnumItemTuple &item);
+ void visit (EnumItemStruct &item);
+ void visit (EnumItemDiscriminant &item);
+ void visit (Enum &enum_item);
+ void visit (Union &union_item);
+ void visit (ConstantItem &const_item);
+ void visit (StaticItem &static_item);
+ void visit (TraitItemFunc &item);
+ void visit (TraitItemMethod &item);
+ void visit (TraitItemConst &item);
+ void visit (TraitItemType &item);
+ void visit (Trait &trait);
+ void visit (InherentImpl &impl);
+ void visit (TraitImpl &impl);
+ void visit (ExternalStaticItem &item);
+ void visit (ExternalFunctionItem &item);
+ void visit (ExternBlock &block);
+
+ // rust-macro.h
+ void visit (MacroMatchFragment &match);
+ void visit (MacroMatchRepetition &match);
+ void visit (MacroMatcher &matcher);
+ void visit (MacroRulesDefinition &rules_def);
+ void visit (MacroInvocation &macro_invoc);
+ void visit (MetaItemPath &meta_item);
+ void visit (MetaItemSeq &meta_item);
+ void visit (MetaWord &meta_item);
+ void visit (MetaNameValueStr &meta_item);
+ void visit (MetaListPaths &meta_item);
+ void visit (MetaListNameValueStr &meta_item);
+
+ // rust-pattern.h
+ void visit (LiteralPattern &pattern);
+ void visit (IdentifierPattern &pattern);
+ void visit (WildcardPattern &pattern);
+ // void visit(RangePatternBound& bound);
+ void visit (RangePatternBoundLiteral &bound);
+ void visit (RangePatternBoundPath &bound);
+ void visit (RangePatternBoundQualPath &bound);
+ void visit (RangePattern &pattern);
+ void visit (ReferencePattern &pattern);
+ // void visit(StructPatternField& field);
+ void visit (StructPatternFieldTuplePat &field);
+ void visit (StructPatternFieldIdentPat &field);
+ void visit (StructPatternFieldIdent &field);
+ void visit (StructPattern &pattern);
+ // void visit(TupleStructItems& tuple_items);
+ void visit (TupleStructItemsNoRange &tuple_items);
+ void visit (TupleStructItemsRange &tuple_items);
+ void visit (TupleStructPattern &pattern);
+ // void visit(TuplePatternItems& tuple_items);
+ void visit (TuplePatternItemsMultiple &tuple_items);
+ void visit (TuplePatternItemsRanged &tuple_items);
+ void visit (TuplePattern &pattern);
+ void visit (GroupedPattern &pattern);
+ void visit (SlicePattern &pattern);
+
+ // rust-stmt.h
+ void visit (EmptyStmt &stmt);
+ void visit (LetStmt &stmt);
+ void visit (ExprStmtWithoutBlock &stmt);
+ void visit (ExprStmtWithBlock &stmt);
+
+ // rust-type.h
+ void visit (TraitBound &bound);
+ void visit (ImplTraitType &type);
+ void visit (TraitObjectType &type);
+ void visit (ParenthesisedType &type);
+ void visit (ImplTraitTypeOneBound &type);
+ void visit (TraitObjectTypeOneBound &type);
+ void visit (TupleType &type);
+ void visit (NeverType &type);
+ void visit (RawPointerType &type);
+ void visit (ReferenceType &type);
+ void visit (ArrayType &type);
+ void visit (SliceType &type);
+ void visit (InferredType &type);
+ void visit (BareFunctionType &type);
+};
+
+} // namespace AST
+} // namespace Rust
+
+#endif // !RUST_AST_DUMP_H
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index 529afa6..ef37e17 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -78,6 +78,12 @@ public:
expr.get_internal_elements ()->accept_vis (*this);
}
+ void visit (HIR::ArrayIndexExpr &expr) override
+ {
+ expr.get_array_expr ()->accept_vis (*this);
+ expr.get_index_expr ()->accept_vis (*this);
+ }
+
void visit (HIR::ArrayElemsValues &expr) override
{
for (auto &elem : expr.get_values ())
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 38e7713..603037e 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -613,6 +613,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
resolver->get_name_scope ().pop ();
return;
}
+ rust_assert (!self_cpath.is_empty ());
// Setup paths
bool canonicalize_type_args = !impl_block.has_generics ();
@@ -637,6 +638,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
= CanonicalPath::new_seg (impl_block.get_node_id (), seg_buf);
cpath = canonical_prefix.append (seg);
}
+
// done setup paths
auto Self
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 14178801..2b5c684 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -209,43 +209,58 @@ ResolveTypeToCanonicalPath::visit (AST::SliceType &slice)
void
ResolveType::visit (AST::ReferenceType &type)
{
- type.get_type_referenced ()->accept_vis (*this);
-
- if (canonical_path != nullptr && canonical_path->size () > 0)
+ CanonicalPath path = CanonicalPath::create_empty ();
+ resolved_node
+ = ResolveType::go (type.get_type_referenced ().get (), type.get_node_id (),
+ canonicalize_type_with_generics, &path);
+ if (canonical_path != nullptr)
{
- std::string seg = canonical_path->get ();
- *canonical_path = CanonicalPath::new_seg (type.get_node_id (), "&" + seg);
+ std::string ref_type_str = type.is_mut () ? "mut" : "";
+ std::string ref_path = "&" + ref_type_str + " " + path.get ();
+ *canonical_path = canonical_path->append (
+ CanonicalPath::new_seg (type.get_node_id (), ref_path));
}
}
void
ResolveType::visit (AST::RawPointerType &type)
{
- type.get_type_pointed_to ()->accept_vis (*this);
-
- if (canonical_path != nullptr && canonical_path->size () > 0)
+ CanonicalPath path = CanonicalPath::create_empty ();
+ resolved_node
+ = ResolveType::go (type.get_type_pointed_to ().get (), type.get_node_id (),
+ canonicalize_type_with_generics, &path);
+ if (canonical_path != nullptr)
{
- std::string seg = canonical_path->get ();
- *canonical_path = CanonicalPath::new_seg (type.get_node_id (), "*" + seg);
+ std::string ptr_type_str
+ = type.get_pointer_type () == AST::RawPointerType::CONST ? "const"
+ : "mut";
+ std::string ptr_path = "*" + ptr_type_str + " " + path.get ();
+ *canonical_path = canonical_path->append (
+ CanonicalPath::new_seg (type.get_node_id (), ptr_path));
}
}
void
ResolveType::visit (AST::InferredType &type)
-{
- ok = true;
-}
+{}
void
ResolveType::visit (AST::NeverType &type)
-{
- ok = true;
-}
+{}
void
ResolveType::visit (AST::SliceType &type)
{
- type.get_elem_type ()->accept_vis (*this);
+ CanonicalPath path = CanonicalPath::create_empty ();
+ resolved_node
+ = ResolveType::go (type.get_elem_type ().get (), type.get_node_id (),
+ canonicalize_type_with_generics, &path);
+ if (canonical_path != nullptr)
+ {
+ std::string slice_path = "[" + path.get () + "]";
+ *canonical_path = canonical_path->append (
+ CanonicalPath::new_seg (type.get_node_id (), slice_path));
+ }
}
ResolveRelativeTypePath::ResolveRelativeTypePath (CanonicalPath qualified_path)
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index 9334135..d10cec2 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -211,15 +211,12 @@ public:
ResolveType resolver (parent, canonicalize_type_with_generics,
canonical_path);
type->accept_vis (resolver);
- if (!resolver.ok)
- rust_error_at (type->get_locus (), "unresolved type");
return resolver.resolved_node;
};
void visit (AST::BareFunctionType &fntype) override
{
- ok = true;
for (auto &param : fntype.get_function_params ())
ResolveType::go (param.get_type ().get (), fntype.get_node_id ());
@@ -253,8 +250,6 @@ public:
return;
}
- ok = !rel_canonical_path.is_empty ();
-
// lets try and resolve in one go else leave it up to the type resolver to
// figure outer
@@ -331,7 +326,7 @@ public:
void visit (AST::QualifiedPathInType &path) override
{
- ok = ResolveRelativeTypePath::go (path);
+ ResolveRelativeTypePath::go (path);
}
void visit (AST::ArrayType &type) override;
diff --git a/gcc/testsuite/rust/compile/torture/arrays_index3.rs b/gcc/testsuite/rust/compile/torture/arrays_index3.rs
new file mode 100644
index 0000000..8fa0a22
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/arrays_index3.rs
@@ -0,0 +1,15 @@
+fn foo() -> usize {
+ 1
+}
+
+fn bar() -> [i32; 1] {
+ [0]
+}
+
+
+
+fn main() -> () {
+ let a = [10];
+ let _b = a[foo()];
+ let _c = bar()[foo()];
+}