A subtle change between syntax::ast and rustc::front::hir


The Expr_ variant ExprLit with a LitStr now no longer contains the string as it appears in the code, but already backslash-escaped.

I noticed this when clippy failed its dogfooding test on zero-width-whitespace because of the string literal “\u{200B}” – which does not even contain a non-latin1 character, but because of escaping was tripping the lint.

To solve this, I had to use codemap's span_to_snippet function, which fortunately works as expected. Whoever tries to use the new hir functions to extract strings should probably be mindful of this.

1 Like

To be clear, by “backslash escaped” you mean that any backslash-escapes have been converted to the true character they represent (e.g. the string "\u{ff}" is stored as "ÿ" in the HIR)?



closed #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.