-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Use constant for detecting thin pointer formatting #157933
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| use crate::intrinsics::type_id; | ||
|
|
||
| /// Collapses all unit items from an iterator into one. | ||
| /// | ||
| /// This is more useful when combined with higher-level abstractions, like | ||
|
|
@@ -19,17 +21,10 @@ impl FromIterator<()> for () { | |
| } | ||
|
|
||
| pub(crate) trait IsUnit { | ||
| fn is_unit() -> bool; | ||
| const IS_UNIT: bool; | ||
| } | ||
|
|
||
| impl<T: ?Sized> IsUnit for T { | ||
| default fn is_unit() -> bool { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| impl IsUnit for () { | ||
| fn is_unit() -> bool { | ||
| true | ||
| } | ||
| // `type_id` erases lifetimes, but that's OK here because "is it ()" never depends on lifetimes | ||
| const IS_UNIT: bool = type_id::<Self>() == type_id::<()>(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this replaces use of specialization with use of non-
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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 also considered just detecting ZST metadata, since it shouldn't make a difference and
SizedTypeProperties::IS_ZSTalready exists, but detecting () specifically was requested in the PR that added this code: #135080 (comment)View changes since the review