-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make lang-items private #301
Comments
@rustbot second -- this seems like a good idea to me, though I think @ecstatic-morse or @oli-obk should review. |
Jup, I'll gladly do any reviews on this |
While I'm supportive of the idea, I'd like to point out (Consequentially, its fine if we adjust the language item design further. I remember @eddyb wanting to change something about how intrinsics/language items worked). |
Indeed. For cg_clif I have a crate called |
Yes to all of that. (In my view, no-core is "perma-unstable": that is, we never intend to support people providing their own variants of core.) |
I know my use case is pretty exotic. I have seen at least one other user: lrs, which is an alternative for libcore that among other things doesn't have any functions that panic. |
@bjorn3 to be clear, I also have a "mini core" that I use for debugging purposes. I don't mean that we shouldn't have the capability, but I do mean that we shouldn't expose it on stable, and I think that we should feel free to make changes to libcore impl. details and lang item definitions liberally. |
TL;DR
tcx.lang_items().my_lang_item().unwrap()
is an anti-pattern which triggers ICEs in#![no_core]
. This MCP proposes to refactor the current implementation of lang-items to prevent it.Links and Details
In
#![no_core]
, we cannot assume that any lang-items are present. At present, due torequire_lang_item
overunwrap
. rust#72170lang_items\(\).*\.unwrap\(\)
rust#72216the compiler should be free from these kind of ICEs. However,
tcx.lang_items().my_lang_item().unwrap()
is an anti-pattern that we want to avoid reintroducing in the future. Following some discussion the idea (credit to @ecstatic-morse) is to introduce an opaque option representing the presence (or lack thereof) of lang-items:To avoid having to explicitly match on this
enum
everywhere where we normally do something likemethods would be implemented for
LangItemRecord
to allow for comparison withDefId
s (silently returningfalse
if the item is missing).By including the
Missing
variant, I am hoping that themissing
anditems
field of theLanguageItems
struct can be unified and we can pre-allocate an array ofLangItemRecord
s with each initially assumedMissing
. This is likely a longer term proposal though and the immediate priority is to preventunwrap
s.The
rustc-dev-guide
is also sadly lacking with respect to descriptions of the various kinds of lang-items and how they're used so I'll be working on supporting documentation as part of this work.Mentors or Reviewers
@oli-obk
@ecstatic-morse
(Assuming both of you are still interested 😅)
The text was updated successfully, but these errors were encountered: