File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ impl Name {
191
191
// FIXME: Remove this in favor of `display`, see fixme on `as_str`
192
192
#[ doc( hidden) ]
193
193
pub fn display_no_db ( & self , edition : Edition ) -> impl fmt:: Display + ' _ {
194
- Display { name : self , needs_escaping : is_raw_identifier ( self . symbol . as_str ( ) , edition) }
194
+ Display { name : self , edition }
195
195
}
196
196
197
197
pub fn symbol ( & self ) -> & Symbol {
@@ -201,15 +201,20 @@ impl Name {
201
201
202
202
struct Display < ' a > {
203
203
name : & ' a Name ,
204
- needs_escaping : bool ,
204
+ edition : Edition ,
205
205
}
206
206
207
207
impl fmt:: Display for Display < ' _ > {
208
208
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
209
- if self . needs_escaping {
210
- write ! ( f, "r#" ) ?;
209
+ let mut symbol = self . name . symbol . as_str ( ) ;
210
+ if let Some ( s) = symbol. strip_prefix ( '\'' ) {
211
+ f. write_str ( "'" ) ?;
212
+ symbol = s;
211
213
}
212
- fmt:: Display :: fmt ( self . name . symbol . as_str ( ) , f)
214
+ if is_raw_identifier ( symbol, self . edition ) {
215
+ f. write_str ( "r#" ) ?;
216
+ }
217
+ f. write_str ( symbol)
213
218
}
214
219
}
215
220
Original file line number Diff line number Diff line change @@ -2110,3 +2110,19 @@ fn foo() {
2110
2110
"# ] ] ,
2111
2111
) ;
2112
2112
}
2113
+
2114
+ #[ test]
2115
+ fn escaped_label ( ) {
2116
+ check (
2117
+ r#"
2118
+ fn main() {
2119
+ 'r#break: {
2120
+ break '$0;
2121
+ }
2122
+ }
2123
+ "# ,
2124
+ expect ! [ [ r#"
2125
+ lb 'r#break
2126
+ "# ] ] ,
2127
+ ) ;
2128
+ }
You can’t perform that action at this time.
0 commit comments