From b1d5817dd18b7b5fc102a63b084b1ee7ff4f9996 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 23:40:41 +0200 Subject: Convert code to text-size --- crates/ra_mbe/src/syntax_bridge.rs | 69 ++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'crates/ra_mbe/src') diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 2b4390eb2..fa9787266 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -5,7 +5,7 @@ use ra_syntax::{ ast::{self, make::tokens::doc_comment}, tokenize, AstToken, Parse, SmolStr, SyntaxKind, SyntaxKind::*, - SyntaxNode, SyntaxToken, SyntaxTreeBuilder, TextRange, TextUnit, Token as RawToken, T, + SyntaxNode, SyntaxToken, SyntaxTreeBuilder, TextRange, TextSize, Token as RawToken, T, }; use rustc_hash::FxHashMap; use tt::buffer::{Cursor, TokenBuffer}; @@ -99,11 +99,11 @@ pub fn parse_to_token_tree(text: &str) -> Option<(tt::Subtree, TokenMap)> { let mut conv = RawConvertor { text, - offset: TextUnit::default(), + offset: TextSize::default(), inner: tokens.iter(), id_alloc: TokenIdAlloc { map: Default::default(), - global_offset: TextUnit::default(), + global_offset: TextSize::default(), next_id: 0, }, }; @@ -227,7 +227,7 @@ fn convert_doc_comment(token: &ra_syntax::SyntaxToken) -> Option { text: &'a str, - offset: TextUnit, + offset: TextSize, id_alloc: TokenIdAlloc, inner: std::slice::Iter<'a, RawToken>, } @@ -314,7 +314,7 @@ trait TokenConvertor { } result.push(if k.is_punct() { - assert_eq!(range.len().to_usize(), 1); + assert_eq!(range.len(), TextSize::of('.')); let delim = match k { T!['('] => Some((tt::DelimiterKind::Parenthesis, T![')'])), T!['{'] => Some((tt::DelimiterKind::Brace, T!['}'])), @@ -381,8 +381,8 @@ trait TokenConvertor { k if k.is_keyword() => make_leaf!(Ident), k if k.is_literal() => make_leaf!(Literal), LIFETIME => { - let char_unit = TextUnit::from_usize(1); - let r = TextRange::offset_len(range.start(), char_unit); + let char_unit = TextSize::of('\''); + let r = TextRange::at(range.start(), char_unit); let apostrophe = tt::Leaf::from(tt::Punct { char: '\'', spacing: tt::Spacing::Joint, @@ -390,8 +390,7 @@ trait TokenConvertor { }); result.push(apostrophe.into()); - let r = - TextRange::offset_len(range.start() + char_unit, range.len() - char_unit); + let r = TextRange::at(range.start() + char_unit, range.len() - char_unit); let ident = tt::Leaf::from(tt::Ident { text: SmolStr::new(&token.to_text()[1..]), id: self.id_alloc().alloc(r), @@ -440,7 +439,7 @@ impl<'a> TokenConvertor for RawConvertor<'a> { fn bump(&mut self) -> Option<(Self::Token, TextRange)> { let token = self.inner.next()?; - let range = TextRange::offset_len(self.offset, token.len); + let range = TextRange::at(self.offset, token.len); self.offset += token.len; Some(((*token, &self.text[range]), range)) @@ -450,7 +449,7 @@ impl<'a> TokenConvertor for RawConvertor<'a> { let token = self.inner.as_slice().get(0).cloned(); token.map(|it| { - let range = TextRange::offset_len(self.offset, it.len); + let range = TextRange::at(self.offset, it.len); (it, &self.text[range]) }) } @@ -464,11 +463,11 @@ struct Convertor { id_alloc: TokenIdAlloc, current: Option, range: TextRange, - punct_offset: Option<(SyntaxToken, TextUnit)>, + punct_offset: Option<(SyntaxToken, TextSize)>, } impl Convertor { - fn new(node: &SyntaxNode, global_offset: TextUnit) -> Convertor { + fn new(node: &SyntaxNode, global_offset: TextSize) -> Convertor { Convertor { id_alloc: { TokenIdAlloc { map: TokenMap::default(), global_offset, next_id: 0 } }, current: node.first_token(), @@ -481,7 +480,7 @@ impl Convertor { #[derive(Debug)] enum SynToken { Ordiniary(SyntaxToken), - Punch(SyntaxToken, TextUnit), + Punch(SyntaxToken, TextSize), } impl SynToken { @@ -500,7 +499,7 @@ impl SrcToken for SynToken { fn to_char(&self) -> Option { match self { SynToken::Ordiniary(_) => None, - SynToken::Punch(it, i) => it.text().chars().nth(i.to_usize()), + SynToken::Punch(it, i) => it.text().chars().nth((*i).into()), } } fn to_text(&self) -> SmolStr { @@ -516,26 +515,26 @@ impl TokenConvertor for Convertor { fn bump(&mut self) -> Option<(Self::Token, TextRange)> { if let Some((punct, offset)) = self.punct_offset.clone() { - if offset.to_usize() + 1 < punct.text().len() { - let offset = offset + TextUnit::from_usize(1); + if usize::from(offset) + 1 < punct.text().len() { + let offset = offset + TextSize::from_usize(1); let range = punct.text_range(); self.punct_offset = Some((punct.clone(), offset)); - let range = TextRange::offset_len(range.start() + offset, TextUnit::from_usize(1)); + let range = TextRange::at(range.start() + offset, TextSize::of('.')); return Some((SynToken::Punch(punct, offset), range)); } } let curr = self.current.clone()?; - if !curr.text_range().is_subrange(&self.range) { + if !&self.range.contains_range(curr.text_range()) { return None; } self.current = curr.next_token(); let token = if curr.kind().is_punct() { let range = curr.text_range(); - let range = TextRange::offset_len(range.start(), TextUnit::from_usize(1)); - self.punct_offset = Some((curr.clone(), TextUnit::from_usize(0))); - (SynToken::Punch(curr, TextUnit::from_usize(0)), range) + let range = TextRange::at(range.start(), TextSize::from_usize(1)); + self.punct_offset = Some((curr.clone(), TextSize::from_usize(0))); + (SynToken::Punch(curr, TextSize::from_usize(0)), range) } else { self.punct_offset = None; let range = curr.text_range(); @@ -547,19 +546,19 @@ impl TokenConvertor for Convertor { fn peek(&self) -> Option { if let Some((punct, mut offset)) = self.punct_offset.clone() { - offset = offset + TextUnit::from_usize(1); - if offset.to_usize() < punct.text().len() { + offset = offset + TextSize::from_usize(1); + if usize::from(offset) < punct.text().len() { return Some(SynToken::Punch(punct, offset)); } } let curr = self.current.clone()?; - if !curr.text_range().is_subrange(&self.range) { + if !self.range.contains_range(curr.text_range()) { return None; } let token = if curr.kind().is_punct() { - SynToken::Punch(curr, TextUnit::from_usize(0)) + SynToken::Punch(curr, TextSize::from_usize(0)) } else { SynToken::Ordiniary(curr) }; @@ -574,8 +573,8 @@ impl TokenConvertor for Convertor { struct TtTreeSink<'a> { buf: String, cursor: Cursor<'a>, - open_delims: FxHashMap, - text_pos: TextUnit, + open_delims: FxHashMap, + text_pos: TextSize, inner: SyntaxTreeBuilder, token_map: TokenMap, @@ -641,7 +640,7 @@ impl<'a> TreeSink for TtTreeSink<'a> { } tt::Leaf::Literal(lit) => (lit.text.clone(), lit.id), }; - let range = TextRange::offset_len(self.text_pos, TextUnit::of_str(&text)); + let range = TextRange::at(self.text_pos, TextSize::of(text.as_str())); self.token_map.insert(id, range); self.cursor = self.cursor.bump(); text @@ -658,10 +657,8 @@ impl<'a> TreeSink for TtTreeSink<'a> { self.cursor = self.cursor.bump(); if let Some(id) = parent.delimiter.map(|it| it.id) { if let Some(open_delim) = self.open_delims.get(&id) { - let open_range = - TextRange::offset_len(*open_delim, TextUnit::from_usize(1)); - let close_range = - TextRange::offset_len(self.text_pos, TextUnit::from_usize(1)); + let open_range = TextRange::at(*open_delim, TextSize::of('(')); + let close_range = TextRange::at(self.text_pos, TextSize::of('(')); self.token_map.insert_delim(id, open_range, close_range); } } @@ -672,7 +669,7 @@ impl<'a> TreeSink for TtTreeSink<'a> { } }; self.buf += &text; - self.text_pos += TextUnit::of_str(&text); + self.text_pos += TextSize::of(text.as_str()); } let text = SmolStr::new(self.buf.as_str()); @@ -690,7 +687,7 @@ impl<'a> TreeSink for TtTreeSink<'a> { // other parts of RA such that we don't add whitespace here. if curr.spacing == tt::Spacing::Alone && curr.char != ';' { self.inner.token(WHITESPACE, " ".into()); - self.text_pos += TextUnit::of_char(' '); + self.text_pos += TextSize::of(' '); } } } -- cgit v1.2.3 From 8843588fca7a6022b86800d5d2539594c0de93cf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 23:51:02 +0200 Subject: Convert tests to text-size --- crates/ra_mbe/src/tests.rs | 408 ++++++++++++++++++++++----------------------- 1 file changed, 204 insertions(+), 204 deletions(-) (limited to 'crates/ra_mbe/src') diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index 100ed41f2..bee59c5c4 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs @@ -257,30 +257,30 @@ fn test_expr_order() { let dump = format!("{:#?}", expanded); assert_eq_text!( dump.trim(), - r#"MACRO_ITEMS@[0; 15) - FN_DEF@[0; 15) - FN_KW@[0; 2) "fn" - NAME@[2; 5) - IDENT@[2; 5) "bar" - PARAM_LIST@[5; 7) - L_PAREN@[5; 6) "(" - R_PAREN@[6; 7) ")" - BLOCK_EXPR@[7; 15) - BLOCK@[7; 15) - L_CURLY@[7; 8) "{" - EXPR_STMT@[8; 14) - BIN_EXPR@[8; 13) - BIN_EXPR@[8; 11) - LITERAL@[8; 9) - INT_NUMBER@[8; 9) "1" - PLUS@[9; 10) "+" - LITERAL@[10; 11) - INT_NUMBER@[10; 11) "1" - STAR@[11; 12) "*" - LITERAL@[12; 13) - INT_NUMBER@[12; 13) "2" - SEMICOLON@[13; 14) ";" - R_CURLY@[14; 15) "}""#, + r#"MACRO_ITEMS@0..15 + FN_DEF@0..15 + FN_KW@0..2 "fn" + NAME@2..5 + IDENT@2..5 "bar" + PARAM_LIST@5..7 + L_PAREN@5..6 "(" + R_PAREN@6..7 ")" + BLOCK_EXPR@7..15 + BLOCK@7..15 + L_CURLY@7..8 "{" + EXPR_STMT@8..14 + BIN_EXPR@8..13 + BIN_EXPR@8..11 + LITERAL@8..9 + INT_NUMBER@8..9 "1" + PLUS@9..10 "+" + LITERAL@10..11 + INT_NUMBER@10..11 "1" + STAR@11..12 "*" + LITERAL@12..13 + INT_NUMBER@12..13 "2" + SEMICOLON@13..14 ";" + R_CURLY@14..15 "}""#, ); } @@ -490,39 +490,39 @@ fn test_expand_to_item_list() { assert_eq!( format!("{:#?}", tree).trim(), r#" -MACRO_ITEMS@[0; 40) - STRUCT_DEF@[0; 20) - STRUCT_KW@[0; 6) "struct" - NAME@[6; 9) - IDENT@[6; 9) "Foo" - RECORD_FIELD_DEF_LIST@[9; 20) - L_CURLY@[9; 10) "{" - RECORD_FIELD_DEF@[10; 19) - NAME@[10; 15) - IDENT@[10; 15) "field" - COLON@[15; 16) ":" - PATH_TYPE@[16; 19) - PATH@[16; 19) - PATH_SEGMENT@[16; 19) - NAME_REF@[16; 19) - IDENT@[16; 19) "u32" - R_CURLY@[19; 20) "}" - STRUCT_DEF@[20; 40) - STRUCT_KW@[20; 26) "struct" - NAME@[26; 29) - IDENT@[26; 29) "Bar" - RECORD_FIELD_DEF_LIST@[29; 40) - L_CURLY@[29; 30) "{" - RECORD_FIELD_DEF@[30; 39) - NAME@[30; 35) - IDENT@[30; 35) "field" - COLON@[35; 36) ":" - PATH_TYPE@[36; 39) - PATH@[36; 39) - PATH_SEGMENT@[36; 39) - NAME_REF@[36; 39) - IDENT@[36; 39) "u32" - R_CURLY@[39; 40) "}""# +MACRO_ITEMS@0..40 + STRUCT_DEF@0..20 + STRUCT_KW@0..6 "struct" + NAME@6..9 + IDENT@6..9 "Foo" + RECORD_FIELD_DEF_LIST@9..20 + L_CURLY@9..10 "{" + RECORD_FIELD_DEF@10..19 + NAME@10..15 + IDENT@10..15 "field" + COLON@15..16 ":" + PATH_TYPE@16..19 + PATH@16..19 + PATH_SEGMENT@16..19 + NAME_REF@16..19 + IDENT@16..19 "u32" + R_CURLY@19..20 "}" + STRUCT_DEF@20..40 + STRUCT_KW@20..26 "struct" + NAME@26..29 + IDENT@26..29 "Bar" + RECORD_FIELD_DEF_LIST@29..40 + L_CURLY@29..30 "{" + RECORD_FIELD_DEF@30..39 + NAME@30..35 + IDENT@30..35 "field" + COLON@35..36 ":" + PATH_TYPE@36..39 + PATH@36..39 + PATH_SEGMENT@36..39 + NAME_REF@36..39 + IDENT@36..39 "u32" + R_CURLY@39..40 "}""# .trim() ); } @@ -623,37 +623,37 @@ fn test_tt_to_stmts() { assert_eq!( format!("{:#?}", stmts).trim(), - r#"MACRO_STMTS@[0; 15) - LET_STMT@[0; 7) - LET_KW@[0; 3) "let" - BIND_PAT@[3; 4) - NAME@[3; 4) - IDENT@[3; 4) "a" - EQ@[4; 5) "=" - LITERAL@[5; 6) - INT_NUMBER@[5; 6) "0" - SEMICOLON@[6; 7) ";" - EXPR_STMT@[7; 14) - BIN_EXPR@[7; 13) - PATH_EXPR@[7; 8) - PATH@[7; 8) - PATH_SEGMENT@[7; 8) - NAME_REF@[7; 8) - IDENT@[7; 8) "a" - EQ@[8; 9) "=" - BIN_EXPR@[9; 13) - LITERAL@[9; 11) - INT_NUMBER@[9; 11) "10" - PLUS@[11; 12) "+" - LITERAL@[12; 13) - INT_NUMBER@[12; 13) "1" - SEMICOLON@[13; 14) ";" - EXPR_STMT@[14; 15) - PATH_EXPR@[14; 15) - PATH@[14; 15) - PATH_SEGMENT@[14; 15) - NAME_REF@[14; 15) - IDENT@[14; 15) "a""#, + r#"MACRO_STMTS@0..15 + LET_STMT@0..7 + LET_KW@0..3 "let" + BIND_PAT@3..4 + NAME@3..4 + IDENT@3..4 "a" + EQ@4..5 "=" + LITERAL@5..6 + INT_NUMBER@5..6 "0" + SEMICOLON@6..7 ";" + EXPR_STMT@7..14 + BIN_EXPR@7..13 + PATH_EXPR@7..8 + PATH@7..8 + PATH_SEGMENT@7..8 + NAME_REF@7..8 + IDENT@7..8 "a" + EQ@8..9 "=" + BIN_EXPR@9..13 + LITERAL@9..11 + INT_NUMBER@9..11 "10" + PLUS@11..12 "+" + LITERAL@12..13 + INT_NUMBER@12..13 "1" + SEMICOLON@13..14 ";" + EXPR_STMT@14..15 + PATH_EXPR@14..15 + PATH@14..15 + PATH_SEGMENT@14..15 + NAME_REF@14..15 + IDENT@14..15 "a""#, ); } @@ -974,20 +974,20 @@ fn test_tt_composite2() { let res = format!("{:#?}", &node); assert_eq_text!( res.trim(), - r###"MACRO_ITEMS@[0; 10) - MACRO_CALL@[0; 10) - PATH@[0; 3) - PATH_SEGMENT@[0; 3) - NAME_REF@[0; 3) - IDENT@[0; 3) "abs" - BANG@[3; 4) "!" - TOKEN_TREE@[4; 10) - L_PAREN@[4; 5) "(" - EQ@[5; 6) "=" - R_ANGLE@[6; 7) ">" - WHITESPACE@[7; 8) " " - POUND@[8; 9) "#" - R_PAREN@[9; 10) ")""### + r###"MACRO_ITEMS@0..10 + MACRO_CALL@0..10 + PATH@0..3 + PATH_SEGMENT@0..3 + NAME_REF@0..3 + IDENT@0..3 "abs" + BANG@3..4 "!" + TOKEN_TREE@4..10 + L_PAREN@4..5 "(" + EQ@5..6 "=" + R_ANGLE@6..7 ">" + WHITESPACE@7..8 " " + POUND@8..9 "#" + R_PAREN@9..10 ")""### ); } @@ -1113,69 +1113,69 @@ fn test_vec() { assert_eq!( format!("{:#?}", tree).trim(), - r#"BLOCK_EXPR@[0; 45) - BLOCK@[0; 45) - L_CURLY@[0; 1) "{" - LET_STMT@[1; 20) - LET_KW@[1; 4) "let" - BIND_PAT@[4; 8) - MUT_KW@[4; 7) "mut" - NAME@[7; 8) - IDENT@[7; 8) "v" - EQ@[8; 9) "=" - CALL_EXPR@[9; 19) - PATH_EXPR@[9; 17) - PATH@[9; 17) - PATH@[9; 12) - PATH_SEGMENT@[9; 12) - NAME_REF@[9; 12) - IDENT@[9; 12) "Vec" - COLON2@[12; 14) "::" - PATH_SEGMENT@[14; 17) - NAME_REF@[14; 17) - IDENT@[14; 17) "new" - ARG_LIST@[17; 19) - L_PAREN@[17; 18) "(" - R_PAREN@[18; 19) ")" - SEMICOLON@[19; 20) ";" - EXPR_STMT@[20; 33) - METHOD_CALL_EXPR@[20; 32) - PATH_EXPR@[20; 21) - PATH@[20; 21) - PATH_SEGMENT@[20; 21) - NAME_REF@[20; 21) - IDENT@[20; 21) "v" - DOT@[21; 22) "." - NAME_REF@[22; 26) - IDENT@[22; 26) "push" - ARG_LIST@[26; 32) - L_PAREN@[26; 27) "(" - LITERAL@[27; 31) - INT_NUMBER@[27; 31) "1u32" - R_PAREN@[31; 32) ")" - SEMICOLON@[32; 33) ";" - EXPR_STMT@[33; 43) - METHOD_CALL_EXPR@[33; 42) - PATH_EXPR@[33; 34) - PATH@[33; 34) - PATH_SEGMENT@[33; 34) - NAME_REF@[33; 34) - IDENT@[33; 34) "v" - DOT@[34; 35) "." - NAME_REF@[35; 39) - IDENT@[35; 39) "push" - ARG_LIST@[39; 42) - L_PAREN@[39; 40) "(" - LITERAL@[40; 41) - INT_NUMBER@[40; 41) "2" - R_PAREN@[41; 42) ")" - SEMICOLON@[42; 43) ";" - PATH_EXPR@[43; 44) - PATH@[43; 44) - PATH_SEGMENT@[43; 44) - NAME_REF@[43; 44) - IDENT@[43; 44) "v" - R_CURLY@[44; 45) "}""# + r#"BLOCK_EXPR@0..45 + BLOCK@0..45 + L_CURLY@0..1 "{" + LET_STMT@1..20 + LET_KW@1..4 "let" + BIND_PAT@4..8 + MUT_KW@4..7 "mut" + NAME@7..8 + IDENT@7..8 "v" + EQ@8..9 "=" + CALL_EXPR@9..19 + PATH_EXPR@9..17 + PATH@9..17 + PATH@9..12 + PATH_SEGMENT@9..12 + NAME_REF@9..12 + IDENT@9..12 "Vec" + COLON2@12..14 "::" + PATH_SEGMENT@14..17 + NAME_REF@14..17 + IDENT@14..17 "new" + ARG_LIST@17..19 + L_PAREN@17..18 "(" + R_PAREN@18..19 ")" + SEMICOLON@19..20 ";" + EXPR_STMT@20..33 + METHOD_CALL_EXPR@20..32 + PATH_EXPR@20..21 + PATH@20..21 + PATH_SEGMENT@20..21 + NAME_REF@20..21 + IDENT@20..21 "v" + DOT@21..22 "." + NAME_REF@22..26 + IDENT@22..26 "push" + ARG_LIST@26..32 + L_PAREN@26..27 "(" + LITERAL@27..31 + INT_NUMBER@27..31 "1u32" + R_PAREN@31..32 ")" + SEMICOLON@32..33 ";" + EXPR_STMT@33..43 + METHOD_CALL_EXPR@33..42 + PATH_EXPR@33..34 + PATH@33..34 + PATH_SEGMENT@33..34 + NAME_REF@33..34 + IDENT@33..34 "v" + DOT@34..35 "." + NAME_REF@35..39 + IDENT@35..39 "push" + ARG_LIST@39..42 + L_PAREN@39..40 "(" + LITERAL@40..41 + INT_NUMBER@40..41 "2" + R_PAREN@41..42 ")" + SEMICOLON@42..43 ";" + PATH_EXPR@43..44 + PATH@43..44 + PATH_SEGMENT@43..44 + NAME_REF@43..44 + IDENT@43..44 "v" + R_CURLY@44..45 "}""# ); } @@ -1798,45 +1798,45 @@ fn test_no_space_after_semi_colon() { let dump = format!("{:#?}", expanded); assert_eq_text!( dump.trim(), - r###"MACRO_ITEMS@[0; 52) - MODULE@[0; 26) - ATTR@[0; 21) - POUND@[0; 1) "#" - L_BRACK@[1; 2) "[" - PATH@[2; 5) - PATH_SEGMENT@[2; 5) - NAME_REF@[2; 5) - IDENT@[2; 5) "cfg" - TOKEN_TREE@[5; 20) - L_PAREN@[5; 6) "(" - IDENT@[6; 13) "feature" - EQ@[13; 14) "=" - STRING@[14; 19) "\"std\"" - R_PAREN@[19; 20) ")" - R_BRACK@[20; 21) "]" - MOD_KW@[21; 24) "mod" - NAME@[24; 25) - IDENT@[24; 25) "m" - SEMICOLON@[25; 26) ";" - MODULE@[26; 52) - ATTR@[26; 47) - POUND@[26; 27) "#" - L_BRACK@[27; 28) "[" - PATH@[28; 31) - PATH_SEGMENT@[28; 31) - NAME_REF@[28; 31) - IDENT@[28; 31) "cfg" - TOKEN_TREE@[31; 46) - L_PAREN@[31; 32) "(" - IDENT@[32; 39) "feature" - EQ@[39; 40) "=" - STRING@[40; 45) "\"std\"" - R_PAREN@[45; 46) ")" - R_BRACK@[46; 47) "]" - MOD_KW@[47; 50) "mod" - NAME@[50; 51) - IDENT@[50; 51) "f" - SEMICOLON@[51; 52) ";""###, + r###"MACRO_ITEMS@0..52 + MODULE@0..26 + ATTR@0..21 + POUND@0..1 "#" + L_BRACK@1..2 "[" + PATH@2..5 + PATH_SEGMENT@2..5 + NAME_REF@2..5 + IDENT@2..5 "cfg" + TOKEN_TREE@5..20 + L_PAREN@5..6 "(" + IDENT@6..13 "feature" + EQ@13..14 "=" + STRING@14..19 "\"std\"" + R_PAREN@19..20 ")" + R_BRACK@20..21 "]" + MOD_KW@21..24 "mod" + NAME@24..25 + IDENT@24..25 "m" + SEMICOLON@25..26 ";" + MODULE@26..52 + ATTR@26..47 + POUND@26..27 "#" + L_BRACK@27..28 "[" + PATH@28..31 + PATH_SEGMENT@28..31 + NAME_REF@28..31 + IDENT@28..31 "cfg" + TOKEN_TREE@31..46 + L_PAREN@31..32 "(" + IDENT@32..39 "feature" + EQ@39..40 "=" + STRING@40..45 "\"std\"" + R_PAREN@45..46 ")" + R_BRACK@46..47 "]" + MOD_KW@47..50 "mod" + NAME@50..51 + IDENT@50..51 "f" + SEMICOLON@51..52 ";""###, ); } -- cgit v1.2.3 From 63a462f37ca584e1a585a69e30823ce25d4d252f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Apr 2020 00:57:47 +0200 Subject: Switch to TryFrom --- crates/ra_mbe/src/syntax_bridge.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_mbe/src') diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index fa9787266..bb28acfd9 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -516,7 +516,7 @@ impl TokenConvertor for Convertor { fn bump(&mut self) -> Option<(Self::Token, TextRange)> { if let Some((punct, offset)) = self.punct_offset.clone() { if usize::from(offset) + 1 < punct.text().len() { - let offset = offset + TextSize::from_usize(1); + let offset = offset + TextSize::of('.'); let range = punct.text_range(); self.punct_offset = Some((punct.clone(), offset)); let range = TextRange::at(range.start() + offset, TextSize::of('.')); @@ -532,9 +532,9 @@ impl TokenConvertor for Convertor { let token = if curr.kind().is_punct() { let range = curr.text_range(); - let range = TextRange::at(range.start(), TextSize::from_usize(1)); - self.punct_offset = Some((curr.clone(), TextSize::from_usize(0))); - (SynToken::Punch(curr, TextSize::from_usize(0)), range) + let range = TextRange::at(range.start(), TextSize::of('.')); + self.punct_offset = Some((curr.clone(), 0.into())); + (SynToken::Punch(curr, 0.into()), range) } else { self.punct_offset = None; let range = curr.text_range(); @@ -546,7 +546,7 @@ impl TokenConvertor for Convertor { fn peek(&self) -> Option { if let Some((punct, mut offset)) = self.punct_offset.clone() { - offset = offset + TextSize::from_usize(1); + offset = offset + TextSize::of('.'); if usize::from(offset) < punct.text().len() { return Some(SynToken::Punch(punct, offset)); } @@ -558,7 +558,7 @@ impl TokenConvertor for Convertor { } let token = if curr.kind().is_punct() { - SynToken::Punch(curr, TextSize::from_usize(0)) + SynToken::Punch(curr, 0.into()) } else { SynToken::Ordiniary(curr) }; -- cgit v1.2.3