Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not parent, but not a rust programmer:

> If I write a Rust program which relies on this for a constant, it works fine, because it is constant, but if I try to compile it with Rust 1.68 (from earlier this year) it won't work.

How would it not work? If your program compiles and runs with 1.69, then surely that's because it never tries to modify the value. But if your program never tries to modify the value, how would it fail with 1.68?



`const` in Rust is for compile-time constants.

In this case, the fn `std::net::SocketAddr::new` was made a const fn recently--but was a regular fn before.

>that's because it never tries to modify the value

That's something different. If you want variables that are read-only, you don't need any extra keyword. It's the normal case:

let x = 5;

If you want a mutable variable, you add a `mut` keyword.

let mut x = 5;

But if you want a compile-time constant, you use `const` instead.

const x: u32 = 5;

The latter will be evaluated by the compiler at compile time (so interpreted) and substituted BEFORE the user runs the program. This is new-ish stuff and is slowly worming its way into the standard library.


The GP is missing a small bit of context: because this construct is now const, it can be used in const contexts, like to initialize a static variable. Doing so didn't work in 1.68, but does now in 1.69.


But older code will still work with the new compiler right?


That is the Rust stability commitment: Rust code will always* compile with any subsequent release.

* Modulo soundness bugs being fixed. I've personally encountered 2 instances of that since 1.0, and they all occurred before 2017.


Yes


> a Rust program which relies on this for a constant

https://godbolt.org/z/ceY3q3eW4


Sorry, I'm not reading 1100 words of privacy policy to get a chance to read whatever that is.


I recommend just reading or closing the privacy policy -- it's a single screen (on my device) and is quite reasonable. Because "whatever that is" is a godbolt link... and godbolt is one of the absolutely most valuable and greatest tools available for software developers who work in compiled languages. It's definitely worth becoming familiar with.


> godbolt is one of the absolutely most valuable and greatest tools available for software developers who work in compiled languages.

That's a bold claim for a tool that doesn't even have a Wikipedia entry.

Edit: or a subreddit.


Gosh, this website is becoming reddit more and more everyday. YOU don't have a wikipedia entry. Are you also now classified as "whatever that is"? Of course not.

I would implore you to open your mind up to resources that aren't popular social media because that's where the real gold/value is in development/engineering.


> YOU don't have a wikipedia entry.

I'm not claiming to be "one of the absolutely most valuable and greatest tools available" though. (Well, maybe the "greatest tool" part ;-) And if someone else claimed that about me, I'd think that either there was something very wrong with them, or that one of my parents had started using alt accounts I didn't know about.

Considering some of the software tools that do have dedicated wikipedia pages and subreddits, and that I'd never heard of godbolt before, I don't think it's out of line to be skeptical of such a hyperbolic claim.


(For what it's worth, I suspect if you took a random poll of Hacker News commenters, at least 90% would know what godbolt is. In fact, until I saw this thread, I thought it was just something like the C language which _everyone_ knows exists - it certainly deserves to be - although of course every day there's a new lucky 10000.)


Yes. I am comfortable depending this claim -- purely as a user, no association with the tool developers.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: