@@ -42,16 +42,13 @@ pub fn expand_assert<'cx>(
42
42
tts : if let Some ( ts) = custom_msg_args {
43
43
ts. into ( )
44
44
} else {
45
- // `expr_to_string` escapes the string literals with `.escape_default()`
46
- // which escapes all non-ASCII characters with `\u`.
47
- let escaped_expr = escape_format_string ( & unescape_printable_unicode (
48
- & pprust:: expr_to_string ( & cond_expr) ,
49
- ) ) ;
50
-
51
45
TokenStream :: from ( TokenTree :: Token (
52
46
DUMMY_SP ,
53
47
token:: Literal (
54
- token:: Lit :: Str_ ( Name :: intern ( & format ! ( "assertion failed: {}" , escaped_expr) ) ) ,
48
+ token:: Lit :: Str_ ( Name :: intern ( & format ! (
49
+ "assertion failed: {}" ,
50
+ pprust:: expr_to_string( & cond_expr) . escape_debug( )
51
+ ) ) ) ,
55
52
None ,
56
53
) ,
57
54
) ) . into ( )
@@ -71,53 +68,3 @@ pub fn expand_assert<'cx>(
71
68
) ;
72
69
MacEager :: expr ( if_expr)
73
70
}
74
-
75
- /// Escapes a string for use as a formatting string.
76
- fn escape_format_string ( s : & str ) -> String {
77
- let mut res = String :: with_capacity ( s. len ( ) ) ;
78
- for c in s. chars ( ) {
79
- res. extend ( c. escape_debug ( ) ) ;
80
- match c {
81
- '{' | '}' => res. push ( c) ,
82
- _ => { }
83
- }
84
- }
85
- res
86
- }
87
-
88
- #[ test]
89
- fn test_escape_format_string ( ) {
90
- assert ! ( escape_format_string( r"foo{}\" ) == r"foo{{}}\\" ) ;
91
- }
92
-
93
- /// Unescapes the escaped unicodes (`\u{...}`) that are printable.
94
- fn unescape_printable_unicode ( mut s : & str ) -> String {
95
- use std:: { char, u32} ;
96
-
97
- let mut res = String :: with_capacity ( s. len ( ) ) ;
98
-
99
- loop {
100
- if let Some ( start) = s. find ( r"\u{" ) {
101
- res. push_str ( & s[ 0 ..start] ) ;
102
- s = & s[ start..] ;
103
- s. find ( '}' )
104
- . and_then ( |end| {
105
- let v = u32:: from_str_radix ( & s[ 3 ..end] , 16 ) . ok ( ) ?;
106
- let c = char:: from_u32 ( v) ?;
107
- // Escape unprintable characters.
108
- res. extend ( c. escape_debug ( ) ) ;
109
- s = & s[ end + 1 ..] ;
110
- Some ( ( ) )
111
- } )
112
- . expect ( "lexer should have rejected invalid escape sequences" ) ;
113
- } else {
114
- res. push_str ( s) ;
115
- return res;
116
- }
117
- }
118
- }
119
-
120
- #[ test]
121
- fn test_unescape_printable_unicode ( ) {
122
- assert ! ( unescape_printable_unicode( r"\u{2603}\n\u{0}" ) == r"☃\n\u{0}" ) ;
123
- }
0 commit comments