-
Notifications
You must be signed in to change notification settings - Fork 13.4k
resolve: Bind primitive types to items in libcore #32274
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Why not |
Lang items have to be unique, no? |
I would still allow the impls to be in different crates (if I'm understanding this right) but move the types in |
The problem is not in impls, but in shadowing. |
@petrochenkov What's in |
Hm, only |
@petrochenkov Even if stabilized, couldn't move everything but |
|
@petrochenkov Why do all of these things depend on an unicode library that we don't want to have in |
// Check if the resolution is a #[primitive_type] item in type namespace, | ||
// replace that item with a primitive type with the same name. | ||
if let Some(PathResolution{base_def, ..}) = resolution { | ||
if let Some(def_id) = base_def.opt_def_id() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to check for Def::Err
explicitly instead of introducing the method opt_def_id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Def::Err
and Def::SelfTy
, but anyway, def kind doesn't matter here, only the presence of def_id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
Reviewed, looks good to me. |
(The failure caught by Travis happens only during docs generation for |
Could |
@drbo I believe the issue is that |
I know there are plans to make a snapshot in the near future, it would be ideal to land this PR before that snapshot. |
eh we're still in "make snapshots whenever" mode so it's not like we can't have one for another 6 months :) I went ahead and kicked one off as @eddyb requested it, but if this lands we can just make a new one. |
☔ The latest upstream changes (presumably #32302) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
☔ The latest upstream changes (presumably #32054) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
Closing as per #32131 (comment) |
This is a more radical alternative to #32131
A new attribute
#[primitive_type]
is introduced. If path used in type position resolves to a#[primitive_type]
item, the definition of a primitive type with the same name is used instead of this item.A path cannot resolve to a primitive type in any other way. Several different
#[primitive_type]
items can be resolved to one primitive type.Most of primitive types are bound to modules (
core::u8
,core::str
etc.) for backward compatibility.All the primitive type items are added to the prelude.
Pros:
This makes primitive types appear to be less special and more similar to lang items - they are defined in
libcore
(and alsolibcollections
,librustc_unicode
andlibstd
), shadowed by other items (including modules) and need to be imported before use (but prelude does it for you).Cons:
It doesn't makes name resolution simpler internally, primitive types are still a hardcoded limited set of
Def::PrimTy
s known to the compiler.It puts the burden of defining/importing primitive types on
#[no_core]
and#[no_implicit_prelude]
code. The alternative PR presents them as the second small prelude which is hardcoded and has lower priority, so the primitive types are always available.[breaking-change]
Needs crater before proceeding.
cc #32131 (comment)
cc @jseyfried
r? @eddyb