Odd hello world example

Hello there! A former coworker told me that he was playing around with Rust and made a Hello World that loops something like 4 trillion times and managed to get the compiler to just spin almost indefinitely. I left the company though and didn't think to ask for the source code before doing so, and I haven't managed to replicate what he reported. I thought it would be an interesting exercise in what not to do in Rust, and perhaps learn more about the compiler as a result, so I'm curious if anyone can provide insight into how he managed that.

How about:

fn main() {
    loop {
        println!("Hello world!");

Four trillion, indefinitely, all the same :slight_smile:

I think your question is far to vague.

Suggest starting with the Rust book to learn what to do or not do with Rust:


haha, that would do it! I have read the book one and a half times so far, which is why I thought I understood how he managed it and didn't to think to ask for the code until I tried to replicate it. It's possible he was just trolling me though, because he knew I like Rust.

There's quadratic behavior in multiple parts of the compiler. They are rare enough that you're unlikely to hit them in every day code and being worked on regularly. No need to be defensive when pointed out that rustc is not perfect, because it isn't, you just need to look at the issue tracker to confirm it :blush:

For example, from a recent post https://github.com/rust-lang/rust/issues/39352

1 Like

Oh, sorry for appearing defensive! I'm definitely a newbie, both in Rust and low level languages in general. Also, there were some extenuating circumstances for why I thought my coworker may been trolling me, heh.

Or... Otherwise you can also say this:

for _ in 0..4_000_000_000_000u128 {
    println!("Hello World!");

If there's a specific number of times you want to spin.

If this was SO :smiley::

closed as: "Unclear what you're asking"

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