@@ -1515,6 +1515,7 @@ class SingleASTNode
1515
1515
TRAIT,
1516
1516
IMPL,
1517
1517
TRAIT_IMPL,
1518
+ TYPE,
1518
1519
};
1519
1520
1520
1521
private:
@@ -1528,6 +1529,7 @@ class SingleASTNode
1528
1529
std::unique_ptr<TraitItem> trait_item;
1529
1530
std::unique_ptr<InherentImplItem> impl_item;
1530
1531
std::unique_ptr<TraitImplItem> trait_impl_item;
1532
+ std::unique_ptr<Type> type;
1531
1533
1532
1534
public:
1533
1535
SingleASTNode (std::unique_ptr<Expr> expr)
@@ -1558,6 +1560,10 @@ class SingleASTNode
1558
1560
: kind (TRAIT_IMPL), trait_impl_item (std::move (trait_impl_item))
1559
1561
{}
1560
1562
1563
+ SingleASTNode (std::unique_ptr<Type> type)
1564
+ : kind (TYPE), type (std::move (type))
1565
+ {}
1566
+
1561
1567
SingleASTNode (SingleASTNode const &other)
1562
1568
{
1563
1569
kind = other.kind ;
@@ -1590,6 +1596,10 @@ class SingleASTNode
1590
1596
case TRAIT_IMPL:
1591
1597
trait_impl_item = other.trait_impl_item ->clone_trait_impl_item ();
1592
1598
break ;
1599
+
1600
+ case TYPE:
1601
+ type = other.type ->clone_type ();
1602
+ break ;
1593
1603
}
1594
1604
}
1595
1605
@@ -1625,6 +1635,10 @@ class SingleASTNode
1625
1635
case TRAIT_IMPL:
1626
1636
trait_impl_item = other.trait_impl_item ->clone_trait_impl_item ();
1627
1637
break ;
1638
+
1639
+ case TYPE:
1640
+ type = other.type ->clone_type ();
1641
+ break ;
1628
1642
}
1629
1643
return *this ;
1630
1644
}
@@ -1699,6 +1713,12 @@ class SingleASTNode
1699
1713
return std::move (trait_impl_item);
1700
1714
}
1701
1715
1716
+ std::unique_ptr<Type> take_type ()
1717
+ {
1718
+ rust_assert (!is_error ());
1719
+ return std::move (type);
1720
+ }
1721
+
1702
1722
void accept_vis (ASTVisitor &vis)
1703
1723
{
1704
1724
switch (kind)
@@ -1730,6 +1750,10 @@ class SingleASTNode
1730
1750
case TRAIT_IMPL:
1731
1751
trait_impl_item->accept_vis (vis);
1732
1752
break ;
1753
+
1754
+ case TYPE:
1755
+ type->accept_vis (vis);
1756
+ break ;
1733
1757
}
1734
1758
}
1735
1759
@@ -1751,6 +1775,8 @@ class SingleASTNode
1751
1775
return impl_item == nullptr ;
1752
1776
case TRAIT_IMPL:
1753
1777
return trait_impl_item == nullptr ;
1778
+ case TYPE:
1779
+ return type == nullptr ;
1754
1780
}
1755
1781
1756
1782
gcc_unreachable ();
@@ -1774,7 +1800,9 @@ class SingleASTNode
1774
1800
case IMPL:
1775
1801
return " Impl Item: " + impl_item->as_string ();
1776
1802
case TRAIT_IMPL:
1777
- return " Trait Impl Item: " + impl_item->as_string ();
1803
+ return " Trait Impl Item: " + trait_impl_item->as_string ();
1804
+ case TYPE:
1805
+ return " Type: " + type->as_string ();
1778
1806
}
1779
1807
1780
1808
gcc_unreachable ();
@@ -1799,6 +1827,18 @@ class ASTFragment
1799
1827
std::vector<SingleASTNode> nodes;
1800
1828
bool fragment_is_error;
1801
1829
1830
+ /* *
1831
+ * We need to make a special case for Expression and Type fragments as only
1832
+ * one Node will be extracted from the `nodes` vector
1833
+ */
1834
+
1835
+ bool is_single_fragment () const { return nodes.size () == 1 ; }
1836
+
1837
+ bool is_single_fragment_kind (SingleASTNode::NodeType kind) const
1838
+ {
1839
+ return is_single_fragment () && nodes[0 ].get_kind () == kind;
1840
+ }
1841
+
1802
1842
public:
1803
1843
ASTFragment (std::vector<SingleASTNode> nodes, bool fragment_is_error = false )
1804
1844
: nodes (std::move (nodes)), fragment_is_error (fragment_is_error)
@@ -1839,21 +1879,16 @@ class ASTFragment
1839
1879
1840
1880
bool should_expand () const { return !is_error () && !nodes.empty (); }
1841
1881
1842
- /* *
1843
- * We need to make a special case for Expression fragments as only one
1844
- * Node will be extracted from the `nodes` vector
1845
- */
1846
-
1847
- bool is_expression_fragment () const
1882
+ std::unique_ptr<Expr> take_expression_fragment ()
1848
1883
{
1849
- return nodes. size () == 1
1850
- && nodes[0 ].get_kind () == SingleASTNode::NodeType::EXPRESSION ;
1884
+ rust_assert ( is_single_fragment_kind (SingleASTNode::NodeType::EXPRESSION));
1885
+ return nodes[0 ].take_expr ();
1851
1886
}
1852
1887
1853
- std::unique_ptr<Expr> take_expression_fragment ()
1888
+ std::unique_ptr<Type> take_type_fragment ()
1854
1889
{
1855
- rust_assert (is_expression_fragment ( ));
1856
- return nodes[0 ].take_expr ();
1890
+ rust_assert (is_single_fragment_kind (SingleASTNode::NodeType::TYPE ));
1891
+ return nodes[0 ].take_type ();
1857
1892
}
1858
1893
1859
1894
void accept_vis (ASTVisitor &vis)
0 commit comments