@@ -1827,6 +1827,18 @@ class ASTFragment
1827
1827
std::vector<SingleASTNode> nodes;
1828
1828
bool fragment_is_error;
1829
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
+
1830
1842
public:
1831
1843
ASTFragment (std::vector<SingleASTNode> nodes, bool fragment_is_error = false )
1832
1844
: nodes (std::move (nodes)), fragment_is_error (fragment_is_error)
@@ -1867,21 +1879,16 @@ class ASTFragment
1867
1879
1868
1880
bool should_expand () const { return !is_error () && !nodes.empty (); }
1869
1881
1870
- /* *
1871
- * We need to make a special case for Expression fragments as only one
1872
- * Node will be extracted from the `nodes` vector
1873
- */
1874
-
1875
- bool is_expression_fragment () const
1882
+ std::unique_ptr<Expr> take_expression_fragment ()
1876
1883
{
1877
- return nodes. size () == 1
1878
- && nodes[0 ].get_kind () == SingleASTNode::NodeType::EXPRESSION ;
1884
+ rust_assert ( is_single_fragment_kind (SingleASTNode::NodeType::EXPRESSION));
1885
+ return nodes[0 ].take_expr ();
1879
1886
}
1880
1887
1881
- std::unique_ptr<Expr> take_expression_fragment ()
1888
+ std::unique_ptr<Type> take_type_fragment ()
1882
1889
{
1883
- rust_assert (is_expression_fragment ( ));
1884
- return nodes[0 ].take_expr ();
1890
+ rust_assert (is_single_fragment_kind (SingleASTNode::NodeType::TYPE ));
1891
+ return nodes[0 ].take_type ();
1885
1892
}
1886
1893
1887
1894
void accept_vis (ASTVisitor &vis)
0 commit comments