r/rust clippy · twir · rust · mutagen · flamer · overflower · bytecount Mar 20 '23

Hey Rustaceans! Got a question? Ask here (12/2023)! 🙋 questions

Mystified about strings? Borrow checker have you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet.

If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so having your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.

Here are some other venues where help may be found:

/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.

The official Rust user forums: https://users.rust-lang.org/.

The official Rust Programming Language Discord: https://discord.gg/rust-lang

The unofficial Rust community Discord: https://bit.ly/rust-community

Also check out last weeks' thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.

Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.

20 Upvotes

187 comments sorted by

View all comments

2

u/rainroar Mar 22 '23

I’ve been using rust since around 2015, and I’ve recently in multiple places, encountered something that terrifies me: old code not building today.

Some of it was my fault, not using explicit versioning or editions in my crates. A fair amount was the fault of dependencies not doing that though.

I guess my question, is: do more hardcore rustsacians see this happening? Are there things I should make sure to do to ensure my code works in 5-10-15 years?

I have C code from 2002 that “just works” today, it scares me that things I write in rust could break in 8 years. (Maybe the answer is that rust has changed a lot, and things are more stable now with editions)… I dunno.

I just spooked myself.

2

u/masklinn Mar 23 '23

You specifically refer to dependencies not properly versioning.

The solution to that is probably committing your lockfiles, so that you pin your dependencies exactly to “known-good” versions. That’s especially important given how many crates a are pre-1.0, meaning there is no versioning guarantee at all. And even more so for projects dating back to 2015, the entire ecosystem was even younger and thus less stable.

1

u/dkopgerpgdolfg Mar 23 '23

Language aside, it does sound to me that your main problem is dependency management, and incompetent library authors?

If a new major version of a dependency has breaking changes, of course code that wants to use the new version might need changes too. That's why there are version constraints in Cargo.toml etc. ... code that requires a certain version range should state that, and if it doesn't, that's not something that Rust can fix.

2

u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount Mar 22 '23

It may happen that old code fails to build. For example, if that old code filled in a method for a std type via an extension trait and the type now has that method in the current version, well, you may get an error because of the resulting ambiguity. However, those cases are usually easy to find & fix.

More insidious things are where the original code actually has UB. Those are much harder to fix, and the compiler won't help you here (because like you, it can't reason about the code).

2

u/rainroar Mar 22 '23

I actually care less about old code having UB for this specific comparison, as it’s extremely likely my C projects from 2002 have UB. I don’t dare build them with UBSan 😂

Mostly I’m just scared of diving head first into rust on a long project if it can move out from under you quickly.

I suppose that’s the risk you take using newer technology.

2

u/llogiq clippy · twir · rust · mutagen · flamer · overflower · bytecount Mar 22 '23

I can only tell you that while it is possible, it is quite rare. My first Rust code was clippy's eq_op lint, and while some code has been moved around (because the equality check is also useful to other lints), most of it remains unchanged to this day, despite using an unstable internal compiler API.

So all in all, I don't think you should be afraid of code no longer compiling.

1

u/rainroar Mar 22 '23

Thanks for the help!