-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Add very basic "comptime" fn implementation #148820
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
base: main
Are you sure you want to change the base?
Changes from all commits
4767557
2f1e4a3
ac6ebf6
49a0f35
885b01e
ab2f389
b5cae36
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 |
|---|---|---|
|
|
@@ -2377,10 +2377,12 @@ pub enum ConstContext { | |
| /// - Array length expressions | ||
| /// - Enum discriminants | ||
| /// - Const generics | ||
| /// | ||
| /// For the most part, other contexts are treated just like a regular `const`, so they are | ||
| /// lumped into the same category. | ||
| Const { inline: bool }, | ||
| Const { | ||
| /// For backwards compatibility `const` items allow | ||
| /// calls to `const fn` to get promoted. | ||
| /// We forbid that in comptime fns and inline consts. | ||
| allow_const_fn_promotion: bool, | ||
| }, | ||
| } | ||
|
|
||
| impl ConstContext { | ||
|
|
@@ -4544,17 +4546,22 @@ impl fmt::Display for Safety { | |
| } | ||
|
|
||
| #[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, StableHash)] | ||
| #[derive(Default)] | ||
| pub enum Constness { | ||
|
Member
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. Personally speaking I would rename the variants like so: pub enum Constness {
Always, // `#[rustc_comptime]`
Maybe, // `const`
Never,
}to mirror If it were up to me, I would even rename
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. I prefer this naming over the suggestion I made in https://github.com/rust-lang/rust/pull/148820/files#r2517464261 actually
Member
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. Apparently this wasn't addressed? I would personally prefer the naming to be
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. |
||
| #[default] | ||
| Const, | ||
| Const { always: bool }, | ||
| NotConst, | ||
| } | ||
|
|
||
| impl Default for Constness { | ||
| fn default() -> Self { | ||
| Self::Const { always: false } | ||
| } | ||
| } | ||
|
Comment on lines
+4554
to
+4558
Member
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. why do we even have a default impl?? This doesn't seem quite right
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. I think it was necessary for the deserialization. But I'll check and leave a doc comment. |
||
|
|
||
| impl fmt::Display for Constness { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| f.write_str(match *self { | ||
| Self::Const => "const", | ||
| Self::Const { always: true } => "comptime", | ||
| Self::Const { always: false } => "const", | ||
| Self::NotConst => "non-const", | ||
| }) | ||
| } | ||
|
|
@@ -4608,10 +4615,6 @@ impl FnHeader { | |
| matches!(self.asyncness, IsAsync::Async(_)) | ||
| } | ||
|
|
||
| pub fn is_const(&self) -> bool { | ||
| matches!(self.constness, Constness::Const) | ||
| } | ||
|
|
||
| pub fn is_unsafe(&self) -> bool { | ||
| self.safety().is_unsafe() | ||
| } | ||
|
|
||
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.
surprised this passes rustfmt
View changes since the review
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.
It probably just gave up