Please help me set up VStudio2019 Community for Rust - UTF8 issues

Hello. Total newbie here. I'm learning several technologies for a qualification as System Administrator and some of them involve programming using the Microsoft/.NET stack (C#, JS, SQL Server, XSLT). I'm still on the basics, but a few decades ago (god I'm old...) I had a semester of programming with Pascal and some of it stuck.
At the same time as I'm learning C# (it's going well) I found out about Rust (the Youtube algo likes you guys!) and I share many values of the language.

My teacher specifically said I should install VS Community because I would expose myself to random breakage with VSCode. There's not a lot of info about setting up Rust on VS Community but I followed this tutorial (thanks, Jonathan!) which was for VS2017 but on my 2019 seems to be working. Then I started with the Rust Book, and on chapter 2 (the guessing game) fell through the cracks.

I have already programmed a guessing game on C# so I thought it would be easy, but then as soon as I do a println!() that includes any "special" non-ASCII characters (the initial user prompts), cargo will not even build.

error: couldn't read src\main.rs: stream did not contain valid UTF-8

--verbose

Caused by:
process didn't exit successfully: rustc --edition=2018 --crate-name jogo_adivinha src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=6180934d13871009 -C extra-filename=-61 80934d13871009 --out-dir "E:\OneDrive - Cinel\VStudio\rust\projects\jogo_adivinha\target\debug\deps" -C "incremental=E:\OneDrive - Cinel\VStudio\rust\projects\jogo_adivinha\target\debug\incremental" -L "dependency=E :\OneDrive - Cinel\VStudio\rust\projects\jogo_adivinha\target\debug\deps" (exit code: 1)

I'm running rustc 1.38.0 and stable-x86_64-pc-windows-msvc ; I have the nightly msvc (and 1.40.0) installed because the tutorial recommended it for the natvis files; the VSCommunity is in English, and the only language pack is English. However, the OS is in Portuguese and localized to Portuguese. The Windows SDK is installed and the Build Tools are installed - if I remove all non ASCII characters from the strings inside my println!(), everything builds.

Inside VS Community, I'm using Daniel Griffen's Rust extension and Whack Whack Terminal to have a shell that allows me to interact with cargo.

I don't need UTF-8 string support to learn Rust, but I'd like to find a way of integrating Rust on my final project (just to show that there is another world outside the MS .NET stack), and if it can't echo proper Portuguese nobody will take it seriously.

Thank you for any help. Regards, tigas.

Quoting the str source:

String slices are always valid UTF-8.

What kind of string are you trying to produce, and could you possibly make a playground reproduction?

It seems that for some reason rustc is unhappy with your character, so you might need to do something about it.

PS. Welcome to Rust and have a wonderful time learning it!

What is the encoding shown in File -> Advanced Save Options?

Thank you!

Here's the current link to the playground with the code.. That one single character (a non 7-bit ASCII character) is enough to stop rustc.

I can't find that option on Visual Studio 2019 Community. However, I found something very suspect on 'Tools -> Options... -> Environment -> Documents' (but I had to use search): "Save documents as Unicode when data cannot be saved in codepage". It was disabled by default. I enabled it, but the error remains.

Notepad++ opens the main.rs file as UTF-8. Now here's the really stupid thing. If I add the non-ASCII character on N++ and save it, it builds. If I reopen main.rs on VS19C, I can now put all the extended characters I want and it still builds.
This smells fishy.

The "hello_cargo" project's main.rs opened in N++ as ANSI (aha!).
I created a new project in cargo, and that main.rs, unopened in VS19, loads in N++ as UTF-8.
I opened that main.rs on VS2019 and saved it (after adding an ASCII character). All OK, N++ is still UTF-8.
I added a non-ASCII character - now main.rs loads in N++ as ANSI and the character is badly encoded :thinking:

It's ISO Latin-1 vs UTF-8 shenanigans. Visual Studio 2019 (or something else) is converting the encodings to ISO Latin-1 if I save over the cargo-created main.rs. I used a hex editor to view the files, and adding the character "á" in N++ results in having the hex values C3A1 in the file (correct UTF-8, AFAICT) while adding the same character in VS2019 results in the hex E1, which would be "á" in ISO Latin 1, but it's also U+00E1

OK, so I think it's either VS2019 or some Windows library somewhere acting up. :sob: rustc builds correctly if I use N++ to edit the code at least once, because then VS2019 stops misbehaving. Thank you for the help.

Ah! That's a great deduction.

A note about IDEs for rust though, most people don't use VS, as though it lacks most rust support, instead they prefer either vscode, atom or a larger IDE like eclipse or Intellij Idea. In this case I'd like to go on a limb and say that VS has bad rust support and you'd probably have more problems with it than using vscode. Do note though, that you still need it installed for its C++ tools (Unless you use GNU or WSL with bash).

I'm currently using IntelliJ Idea/Rust and have found that it's rust support is comparable VS's C# support.

I'm on mobile right now though, so I can't test if Idea handles the characters well.