File tree Expand file tree Collapse file tree 4 files changed +9
-13
lines changed Expand file tree Collapse file tree 4 files changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -48,9 +48,8 @@ impl Name {
4848
4949 /// Resolve a name from the text of token.
5050 fn resolve ( raw_text : & str ) -> Name {
51- let raw_start = "r#" ;
52- if raw_text. starts_with ( raw_start) {
53- Name :: new_text ( SmolStr :: new ( & raw_text[ raw_start. len ( ) ..] ) )
51+ if let Some ( text) = raw_text. strip_prefix ( "r#" ) {
52+ Name :: new_text ( SmolStr :: new ( text) )
5453 } else {
5554 Name :: new_text ( raw_text. into ( ) )
5655 }
Original file line number Diff line number Diff line change @@ -333,8 +333,7 @@ impl ast::Use {
333333 . and_then ( ast:: Whitespace :: cast) ;
334334 if let Some ( next_ws) = next_ws {
335335 let ws_text = next_ws. syntax ( ) . text ( ) ;
336- if ws_text. starts_with ( '\n' ) {
337- let rest = & ws_text[ 1 ..] ;
336+ if let Some ( rest) = ws_text. strip_prefix ( '\n' ) {
338337 if rest. is_empty ( ) {
339338 res. delete ( next_ws. syntax ( ) )
340339 } else {
Original file line number Diff line number Diff line change @@ -154,8 +154,8 @@ fn hide_hash_comments(text: &str) -> String {
154154fn reveal_hash_comments ( text : & str ) -> String {
155155 text. split ( '\n' ) // want final newline
156156 . map ( |it| {
157- if it. starts_with ( "# " ) {
158- & it [ 2 .. ]
157+ if let Some ( stripped ) = it. strip_prefix ( "# " ) {
158+ stripped
159159 } else if it == "#" {
160160 ""
161161 } else {
Original file line number Diff line number Diff line change @@ -60,12 +60,10 @@ fn collect_tests(s: &str) -> Vec<Test> {
6060 let mut res = Vec :: new ( ) ;
6161 for comment_block in extract_comment_blocks ( s) {
6262 let first_line = & comment_block[ 0 ] ;
63- let ( name, ok) = if first_line. starts_with ( "test " ) {
64- let name = first_line[ "test " . len ( ) ..] . to_string ( ) ;
65- ( name, true )
66- } else if first_line. starts_with ( "test_err " ) {
67- let name = first_line[ "test_err " . len ( ) ..] . to_string ( ) ;
68- ( name, false )
63+ let ( name, ok) = if let Some ( name) = first_line. strip_prefix ( "test " ) {
64+ ( name. to_string ( ) , true )
65+ } else if let Some ( name) = first_line. strip_prefix ( "test_err " ) {
66+ ( name. to_string ( ) , false )
6967 } else {
7068 continue ;
7169 } ;
You can’t perform that action at this time.
0 commit comments