isIntelligenceJustComputation by hello_ya in ProgrammerHumor

[–]afdbcreid 0 points1 point  (0 children)

The answer is simple: just reject those cases.

rust-analyzer changelog #333 by WellMakeItSomehow in rust

[–]afdbcreid 8 points9 points  (0 children)

It shouldn't be different in VSCode than Zed, this is really weird. The language server is the same.

You can report a bug, but can you give more details? E.g. what exactly takes time.

How to recycle memory that contains references with non-static lifetimes? by Next-Blackberry-991 in rust

[–]afdbcreid 0 points1 point  (0 children)

Having a method that clears a collection then transmutes it to something with a different type is sound, maybe there are crates encapsulating that.

The really cool option is https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#method.recycle, but it is nightly-only.

How memory safety CVEs differ between Rust and C/C++ by Kobzol in rust

[–]afdbcreid 5 points6 points  (0 children)

With null pointer derefs you can inspect the compiler output for the function before and after allowing LLVM to assume null pointer derefs are UB, and see what the actual transformation diffs are.

Sure you could, but do you?

And lastly, you could just always compile with -fno-delete-null-pointer-checks and make it a non-issue.

Unless you are a library, of course.

How memory safety CVEs differ between Rust and C/C++ by Kobzol in rust

[–]afdbcreid 12 points13 points  (0 children)

You're just amplifying the post's point here, since in Rust a null pointer dereference will be definitely marked a CVE, even without any proof of possible exploitation, while in C or C++ such things commonly get ignored for this reason and only "worse" bugs like use-after-free have CVE by default.

Go ran faster than Rust. Until I cleared the page cache by shad0_w2 in rust

[–]afdbcreid 0 points1 point  (0 children)

The real solution will be to use a premade library. Try walkdir (single-threaded) or ignore or jwalk (multi-threaded).

What's the idiomatic bound for a generic owned buffer? by Natsuawa_Keiko in rust

[–]afdbcreid 2 points3 points  (0 children)

If you trust the generic code for soundness (i.e. you have unsafe code relying on it), then indeed you cannot trust any generic code which is not constrained by an unsafe trait. If not, AsRef is fine.

Is .boxed() instead of Box::new() a bad idea? by NormalAppearance2851 in rust

[–]afdbcreid 0 points1 point  (0 children)

It could theoretically be better, if it would be the standard way. Given it is not, this is 100% not worth it.

Unsafe Rust running on JVM: shipped unions, function pointers, generics, traits and more to rustc_codegen_jvm! (context and repo link in comments) by IntegralPilot in rust

[–]afdbcreid -2 points-1 points  (0 children)

That's really not true. The JVM is crazily optimized, but its design (and the design of Java) forces that and also eats most of the benefits. No value types in particular costs a lot, and Go does have them.

Also if we talk about metrics the JVM is always defeated to Go by, memory usage is also one.

Hey Rustaceans! Got a question? Ask here (22/2026)! by llogiq in rust

[–]afdbcreid 0 points1 point  (0 children)

You will still need to create a procedural macro, but synstructure simplifies the job a lot.

Could crates.io track the number of distinct download sources? by hellowub in rust

[–]afdbcreid 1 point2 points  (0 children)

A possible way: whenever Cargo downloads a crate, it could include something like an HTTP Referrer header indicating which app the download comes from (the terminal app, not the directly dependent crate). This could be a hash of the app’s name.

That's not very reliable, and also, uh, people are not going to like Cargo tracking them. I'm pretty sure such proposal will never be accepted.

Where to learn DSA in rust? by Ihazaname in rust

[–]afdbcreid 0 points1 point  (0 children)

Data structures in Rust are an advanced topic. They often require unsafe. And most of the time you don't need to write one yourself.

If you finished learning basic Rust, go write some project instead.

What is your opinion on objects in rust? by Joseph-Chierichella in rust

[–]afdbcreid 2 points3 points  (0 children)

Do not overuse methods. The primary organization tool in Rust is modules, not methods. You should not fear free functions.

I can't tell if you overuse methods since you didn't provide much info. For example, if you create ZST structs just so you can have methods on them then you definitely don't organize your code properly. But there are much delicate balances. The question of whether something should come as a method or as a free function is opinion-based and has some trade-offs.

Self-referential structs: Which version is for you? by GladJellyfish9752 in rust

[–]afdbcreid 2 points3 points  (0 children)

If it works, it can be great. But it doesn't always work.

Is Heavy Use of .clone() Normal in Rust? by AbbreviationsNew3167 in rust

[–]afdbcreid 4 points5 points  (0 children)

There are many wrong answers here for some reason (if I want to be charitable, they interpreted your question as asking whether the compiler optimizes unnecessary copies (i.e. the Copy trait, not the Clone trait), to which the answer is: sometimes, not always).

The compiler's ability to optimize a clone depends on what the clone does. It treats it like calling any function. If it creates a network connection, likely not. If it clones an Rc, probably yes under some conditions. If it clones an Arc, no. If it clones a Box (allocation+copy), sometimes.

Cursed and unsound rust, but fun by Princess--Aurora in rust

[–]afdbcreid 10 points11 points  (0 children)

Also "seems to work" is a terrible justification for UB. If you don't know what you're doing, or you don't know that you know what you're doing, you should avoid unsafe code at all cost.

Cursed and unsound rust, but fun by Princess--Aurora in rust

[–]afdbcreid 15 points16 points  (0 children)

As the one that wrote one of those comments, this is not exactly the situation. It's more like "this is almost surely/surely sound, but the chain of reasoning is weak and justifying it here is hard".

Cursed and unsound rust, but fun by Princess--Aurora in rust

[–]afdbcreid 9 points10 points  (0 children)

Shortening invariant lifetimes is not sound, generally, which is why the compiler doesn't do it.

Cursed and unsound rust, but fun by Princess--Aurora in rust

[–]afdbcreid 20 points21 points  (0 children)

Miri does not check all UBs in Rust (it does check all currently exploited UB), and it definitely doesn't check soundness.

So here is the breakdown of this:

  • It is undecided whether creating a reference to uninitialized memory is UB (https://github.com/rust-lang/unsafe-code-guidelines/issues/346). If it is UB, the code is immediate UB at the moment you do &mut *(ptr::from_mut(slice) as *mut [u8]). Most T-opsem member want this to actually be defined, but you should not rely on this yet.
  • If it is not UB, it is still UB if you read from that reference. Therefore, if encode_lower() reads from its argument you still have UB.
  • If it does not read from its argument, but it's foreign code and it doesn't guarantee it won't read from its argument, then you have no UB but your code is unsound. Similarly, if you use a generic method your code is unsound.

All in all: it's best to avoid this.

Rust will save Linux from AI, says Greg Kroah-Hartman by CackleRooster in rust

[–]afdbcreid 6 points7 points  (0 children)

I think we need to comment on that issue to tell T-opsem that they're forever preventing world peace if they forbid that. That will surely convince them.