Why drop_in_place no longer an intrinsic?

Normally compiler magics are placed in intrinsic, so why is there such an exception, even moved out "later"? The documentation and comments don't explain why, the release note for 1.52.0 doesn't mention it, and I can't seem to find a relevant issue in a short time.

std::intrinsics is unstable, too. Unstable is even somewhat inaccurate since, as far as I'm aware, there's no plan to ever make intrinsics stably usable in the std::intrinsics or core::intrinsics path. Ultimately, the design principle here, as far as I'm aware, is that intrinsics are merely an implementation detail to be used in other more proper (and often with better/safer type signatures) API, though sometimes they can also be directly re-exoorted under their proper path, as is currently the case e. g. for transmute in std::mem - Rust.

As whether or not "compiler magic" uses intrinsics is only an implementation detail, such a change is completely irrelevant as far as release notes are concerned. Looking at the standard library source, it also seems like drop_in_place actually was already not a "true" intrinsic for longer than since 1.52.

As for the compiler-internal, technical reasons why a normal intrinsic is not used for drop_in_place and it's a lang item instead, I don't actually know the details here, whether it may be that intrinsics are limited in certain ways, or the way they compiler handles them is inappropriate for drop_in_place for some reason... no idea. It shouldn't be relevant for any rust user, but if you're super curious and this users on this forum don't end up finding the answer for you, then perhaps asking in internals.rust-lang.org might be more successful. Though often, finding the motivation for things like this can be as simple as finding the relevant PRs and reading the comments in those.

Here's the PR (last commit):

Sorry, this is my carelessness.

Actually I should have posted this to the internals......

This is a good idea, maybe.

I think it might be a good idea to have all the "magic" stuff in one place, so that all the code in the rest of std is guaranteed to be no magic. but currently there seems to be some scattered magics besides core::intrinsic, like Box::new.

My motivation was actually to write a minimal and "generally" sound implementation of Vec<T>, using only the compiler intrinsics and alloc functions, without any high-level abstractions, so that C/C++/Rust beginners could understand the principles of vectors. But I soon found out that it doesn't seem easy to not use any high level abstractions in modern Rust, for example you can't even call alloc through the public API without using Layout. Has anyone done this before?

I would not call Layout a "high-level" abstraction. It's a struct with two usizes in it, essentially.

For people curious about Vec, I usually point them at Implementing Vec - The Rustonomicon -- which doesn't try to skip the useful Rust parts, since one of the great things about that part of the nomicon is that it builds up to some useful patterns that can be used in other things too.

Completely correct. There were bugs in the past that exposed some things, so we let those keep working, but nothing else will ever be exposed through intrinsics directly.


Great job, I will recommend them to read.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.