@@ -43,18 +43,18 @@ pub struct TokenMap {
4343
4444/// Convert the syntax tree (what user has written) to a `TokenTree` (what macro
4545/// will consume).
46- pub fn ast_to_token_tree ( ast : & impl ast:: AstNode ) -> Option < ( tt:: Subtree , TokenMap ) > {
46+ pub fn ast_to_token_tree ( ast : & impl ast:: AstNode ) -> ( tt:: Subtree , TokenMap ) {
4747 syntax_node_to_token_tree ( ast. syntax ( ) )
4848}
4949
5050/// Convert the syntax node to a `TokenTree` (what macro
5151/// will consume).
52- pub fn syntax_node_to_token_tree ( node : & SyntaxNode ) -> Option < ( tt:: Subtree , TokenMap ) > {
52+ pub fn syntax_node_to_token_tree ( node : & SyntaxNode ) -> ( tt:: Subtree , TokenMap ) {
5353 let global_offset = node. text_range ( ) . start ( ) ;
5454 let mut c = Convertor :: new ( node, global_offset) ;
55- let subtree = c. go ( ) ? ;
55+ let subtree = c. go ( ) ;
5656 c. id_alloc . map . entries . shrink_to_fit ( ) ;
57- Some ( ( subtree, c. id_alloc . map ) )
57+ ( subtree, c. id_alloc . map )
5858}
5959
6060// The following items are what `rustc` macro can be parsed into :
@@ -108,7 +108,7 @@ pub fn parse_to_token_tree(text: &str) -> Option<(tt::Subtree, TokenMap)> {
108108 } ,
109109 } ;
110110
111- let subtree = conv. go ( ) ? ;
111+ let subtree = conv. go ( ) ;
112112 Some ( ( subtree, conv. id_alloc . map ) )
113113}
114114
@@ -319,18 +319,18 @@ trait SrcToken: std::fmt::Debug {
319319trait TokenConvertor {
320320 type Token : SrcToken ;
321321
322- fn go ( & mut self ) -> Option < tt:: Subtree > {
322+ fn go ( & mut self ) -> tt:: Subtree {
323323 let mut subtree = tt:: Subtree :: default ( ) ;
324324 subtree. delimiter = None ;
325325 while self . peek ( ) . is_some ( ) {
326326 self . collect_leaf ( & mut subtree. token_trees ) ;
327327 }
328328 if subtree. token_trees . len ( ) == 1 {
329329 if let tt:: TokenTree :: Subtree ( first) = & subtree. token_trees [ 0 ] {
330- return Some ( first. clone ( ) ) ;
330+ return first. clone ( ) ;
331331 }
332332 }
333- Some ( subtree)
333+ subtree
334334 }
335335
336336 fn collect_leaf ( & mut self , result : & mut Vec < tt:: TokenTree > ) {
@@ -858,7 +858,7 @@ mod tests {
858858 // - T!['}']
859859 // - WHITE_SPACE
860860 let token_tree = ast:: TokenTree :: cast ( token_tree) . unwrap ( ) ;
861- let tt = ast_to_token_tree ( & token_tree) . unwrap ( ) . 0 ;
861+ let tt = ast_to_token_tree ( & token_tree) . 0 ;
862862
863863 assert_eq ! ( tt. delimiter_kind( ) , Some ( tt:: DelimiterKind :: Brace ) ) ;
864864 }
@@ -867,7 +867,7 @@ mod tests {
867867 fn test_token_tree_multi_char_punct ( ) {
868868 let source_file = ast:: SourceFile :: parse ( "struct Foo { a: x::Y }" ) . ok ( ) . unwrap ( ) ;
869869 let struct_def = source_file. syntax ( ) . descendants ( ) . find_map ( ast:: Struct :: cast) . unwrap ( ) ;
870- let tt = ast_to_token_tree ( & struct_def) . unwrap ( ) . 0 ;
870+ let tt = ast_to_token_tree ( & struct_def) . 0 ;
871871 token_tree_to_syntax_node ( & tt, FragmentKind :: Item ) . unwrap ( ) ;
872872 }
873873}
0 commit comments