The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Compiler Explorer does Rust. Rust really is strict: some Tweets that helped me learn how strict.

Posted by jpluimers on 2025/05/15

Just remembered that I had a fall 2021 note lying around about Compiler Explorer having evolved and been doing Rust for quite a while now: [Wayback/Archive] Compiler Explorer: G54Mb9Es3

gcc.godbolt.org
Compiler Explorer - Rust (rustc 1.55.0)
pub fn add(a: u64, b: u16) { println!("{}", a + b);

It shows that integer types [Wayback/Archive] u16 and [Wayback/Archive] u64 cannot be added together without conversion or casting. Which is an example of the strictness that Rust requires. I think that is a good thing,

Via this tweet tree (as opinions on idioms vary so it is good to understand why):

And some more documentation links:

Related 2017 blog post: Compiler Explorer – how various C++ compilers translate code into various machine code targets

--jeroen


https://twitter.com/lunasorcery/status/1449400981188382722

 

so I’m actually sitting down and trying to learn some rust and uh..
rustc: error[E0277]: cannot add u16 to u64
I miss integer promotion already

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.