Search code examples
visual-studio-coderustwhitespacerust-rustlings

Wrote an Invisible whitespace in VScode, but showed in command line


I was playing with rustlings untile I've reached the exercise primitive_types2.rs.

To print in output Neither alphabetic nor numeric! I've started to mess up with ALT + NUMPAD and I've generated this line.

let your_character = '­☻';

If you copy-paste it, you will notice that there is an invisible whitespace before the smile (try to delete or move the cursor with arrows).

Compiling of exercises/04_primitive_types/primitive_types2.rs failed! Please try again. Here's the output:
error: character literal may only contain one codepoint
  --> exercises/04_primitive_types/primitive_types2.rs:22:26
   |
22 |     let your_character = '­☻';// Finish this line like the example! What's your favorite character?
   |                          ^^^^
   |
help: if you meant to write a `str` literal, use double quotes
   |
22 |     let your_character = "­☻";// Finish this line like the example! What's your favorite character?
   |                          ~~~~

error: aborting due to 1 previous error

This white space is printed in Output. enter image description here

Looking around, I've found some information about it, but if I paste them in VSCode, they're highlighted by a yellow rectangle. enter image description here enter image description here

Is there a way to figure out how I generated it?

How can I avoid, find, and fix this problem if it happens in a real-world scenario?


Solution

  • Is there a way to figure out how I generated it?

    I copy-pasted into an online text-to-hex converter and identified that what you have there is U+00AD 'SOFT HYPHEN'. To generate it, by default:

    • on Windows: hold ALT, type +AD, then release ALT; or
    • on Linux: hold CTRL and SHIFT, type UAD, then release CTRL and SHIFT.

    (I don't believe, by default, there is any keyboard shortcut on macOS that will produce this character).

    How can I avoid, find, and fix this problem if it happens in a real-world scenario?

    I'd recommend the Gremlins tracker extension.