@@ -258,7 +258,7 @@ pub(crate) fn complete_postfix(
258258}
259259
260260fn get_receiver_text ( receiver : & ast:: Expr , receiver_is_ambiguous_float_literal : bool ) -> String {
261- let text = if receiver_is_ambiguous_float_literal {
261+ let mut text = if receiver_is_ambiguous_float_literal {
262262 let text = receiver. syntax ( ) . text ( ) ;
263263 let without_dot = ..text. len ( ) - TextSize :: of ( '.' ) ;
264264 text. slice ( without_dot) . to_string ( )
@@ -267,12 +267,18 @@ fn get_receiver_text(receiver: &ast::Expr, receiver_is_ambiguous_float_literal:
267267 } ;
268268
269269 // The receiver texts should be interpreted as-is, as they are expected to be
270- // normal Rust expressions. We escape '\' and '$' so they don't get treated as
271- // snippet-specific constructs.
272- //
273- // Note that we don't need to escape the other characters that can be escaped,
274- // because they wouldn't be treated as snippet-specific constructs without '$'.
275- text. replace ( '\\' , "\\ \\ " ) . replace ( '$' , "\\ $" )
270+ // normal Rust expressions.
271+ escape_snippet_bits ( & mut text) ;
272+ text
273+ }
274+
275+ /// Escapes `\` and `$` so that they don't get interpreted as snippet-specific constructs.
276+ ///
277+ /// Note that we don't need to escape the other characters that can be escaped,
278+ /// because they wouldn't be treated as snippet-specific constructs without '$'.
279+ fn escape_snippet_bits ( text : & mut String ) {
280+ stdx:: replace ( text, '\\' , "\\ \\ " ) ;
281+ stdx:: replace ( text, '$' , "\\ $" ) ;
276282}
277283
278284fn include_references ( initial_element : & ast:: Expr ) -> ( ast:: Expr , ast:: Expr ) {
0 commit comments