-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Parse the syntax described in RFC 2632 #67820
Conversation
980703b
to
c8f3965
Compare
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.
Some nits, r=me with them addressed
|
||
impl const T for S {} | ||
//~^ ERROR const trait impls are experimental | ||
//~| ERROR const trait impls are experimental |
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.
That's fine for now. It'll immediately go away when the feature gate has some logic, so...
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 switched to "not yet implemented" for the non-feature gated errors anyways. It made it easier to track see when I had forgotten a feature gate in the tests.
trait T {} | ||
|
||
// An inherent impl for a trait object of `?const T`. | ||
impl ?const T {} |
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.
Not sure if this should ever be accepted. Probably not without an epoch doing other const things. Please make this a hard error for now
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.
But I don't think it should be a hard error under #[cfg(FALSE)]
. Make sure to test syntax independently of semantics, and preferably in one file, as a // check-pass
test.
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 also like to see tests that includes impl Trait
in various positions (syntactically vs. semantically -- different tests).
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.
?const
is now forbidden in impl Trait
and trait objects.
trait Trait {} | ||
struct Foo<T: Trait>(T); | ||
|
||
const fn new_foo<T: ?const Trait>(t: T) -> Foo<T> { |
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 think the tests with and without the feature gate should have the same content so we are testing all the syntax in both situations
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 reorganized the tests a bit and am using the revisions
trick for now to guarantee this.
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.
Looks nice overall. Enjoying that this was easy to extend atop #67148. :)
Please make sure the feature gate labels on the PR + tracking issue are there before merging.
@@ -0,0 +1,7 @@ | |||
// compile-flags: -Z parse-only |
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.
Why is this flag necessary?
@@ -0,0 +1,9 @@ | |||
// parse-fail |
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.
Remove this. There's no such directive.
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.
And also this doesn't seem to be true of the test. The errors below are not parser errors.
trait T {} | ||
|
||
// An inherent impl for a trait object of `?const T`. | ||
impl ?const T {} |
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.
But I don't think it should be a hard error under #[cfg(FALSE)]
. Make sure to test syntax independently of semantics, and preferably in one file, as a // check-pass
test.
trait T {} | ||
|
||
// An inherent impl for a trait object of `?const T`. | ||
impl ?const T {} |
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 also like to see tests that includes impl Trait
in various positions (syntactically vs. semantically -- different tests).
c8f3965
to
ed8f27f
Compare
@Centril I added checks for |
59a60ed
to
e38e10f
Compare
struct S; | ||
impl T for S {} | ||
|
||
fn rpit() -> impl ?const T { S } |
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.
Seems like we came away with different interpretations of what Oliver said.
I think this would be perfectly well defined and semantically sane (same with dyn ?const Trait
).
After some more reflection, I think the semantic property one would want is that ?const
is legal if and only if we are in a const
-by-default context (const fn) or
const Trait for { ... }`). However, if you want to get this landed quicker, I'm fine with this for now (but leave the comment visible).
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.
@oli-obk ^
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.
While these would be fine in the future, having them be a hard error for now and giving them their own feature gates in the future seems the best way forward to me. The RFC specifically talked about a minimal version that does not include impl Trait
at all
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.
After porting these checks to AST validation, I also decided to error when they are found on trait bounds (e.g., trait T: ?const Super {}
). While this is not explicitly called out as a future extension by the RFC, it will not be useful until const
trait definitions have some meaning.
struct S; | ||
impl T for S {} | ||
|
||
fn rpit() -> impl ?const T { S } |
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.
While these would be fine in the future, having them be a hard error for now and giving them their own feature gates in the future seems the best way forward to me. The RFC specifically talked about a minimal version that does not include impl Trait
at all
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
f0d4f38
to
14c9ab8
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors r+ |
📌 Commit 19f74cb has been approved by |
Parse the syntax described in RFC 2632 This adds support for both `impl const Trait for Ty` and `?const Trait` bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-added `constness` field on `ast::TraitRef`, although this may change once the implementation is fleshed out. I was planning on using `delay_span_bug` when this syntax is encountered during lowering, but I can't write `should-ice` UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the `.stderr` files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled? @oli-obk I went with `const_trait_impl` and `const_trait_bound_opt_out` for the names of these features. Are these to your liking? cc rust-lang#67792 rust-lang#67794 r? @Centril
☔ The latest upstream changes (presumably #67770) made this pull request unmergeable. Please resolve the merge conflicts. |
Rollup of 10 pull requests Successful merges: - #67774 (Try statx for all linux-gnu target.) - #67781 (Move `is_min_const_fn` query to librustc_mir.) - #67798 (Remove wrong advice about spin locks from `spin_loop_hint` docs) - #67849 (Add a check for swapped words when we can't find an identifier) - #67875 (Distinguish between private items and hidden items in rustdoc) - #67887 (`Option::{expect,unwrap}` and `Result::{expect, expect_err, unwrap, unwrap_err}` have `#[track_caller]`) - #67955 (rustdoc: Remove more `#[doc(cfg(..))]` duplicates) - #67977 (Updates for VxWorks) - #67985 (Remove insignificant notes from CStr documentation) - #68003 (ci: fix wrong shared.sh import for publish_toolstate) Failed merges: - #67820 (Parse the syntax described in RFC 2632) - #67979 (Move `intravisit` => `rustc_hir` + misc cleanup) r? @ghost
Rollup of 10 pull requests Successful merges: - #67774 (Try statx for all linux-gnu target.) - #67781 (Move `is_min_const_fn` query to librustc_mir.) - #67798 (Remove wrong advice about spin locks from `spin_loop_hint` docs) - #67849 (Add a check for swapped words when we can't find an identifier) - #67875 (Distinguish between private items and hidden items in rustdoc) - #67887 (`Option::{expect,unwrap}` and `Result::{expect, expect_err, unwrap, unwrap_err}` have `#[track_caller]`) - #67955 (rustdoc: Remove more `#[doc(cfg(..))]` duplicates) - #67977 (Updates for VxWorks) - #67985 (Remove insignificant notes from CStr documentation) - #68003 (ci: fix wrong shared.sh import for publish_toolstate) Failed merges: - #67820 (Parse the syntax described in RFC 2632) - #67979 (Move `intravisit` => `rustc_hir` + misc cleanup) r? @ghost
This is used for both the `?const` syntax in bounds as well as the `impl const Trait` syntax. I also considered handling these separately by adding a variant of `TraitBoundModifier` and a field to `ItemKind::Impl`, but this approach was less intrusive.
The grammar also handles `?const ?Trait` even though this is semantically redundant.
This means the new syntax will always fail to compile, even when the feature gate is enabled. These checks will be removed in a later PR once the implementation is done.
19f74cb
to
fd1c003
Compare
@bors r=oli-obk |
📌 Commit fd1c003 has been approved by |
Parse the syntax described in RFC 2632 This adds support for both `impl const Trait for Ty` and `?const Trait` bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-added `constness` field on `ast::TraitRef`, although this may change once the implementation is fleshed out. I was planning on using `delay_span_bug` when this syntax is encountered during lowering, but I can't write `should-ice` UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the `.stderr` files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled? @oli-obk I went with `const_trait_impl` and `const_trait_bound_opt_out` for the names of these features. Are these to your liking? cc rust-lang#67792 rust-lang#67794 r? @Centril
Parse the syntax described in RFC 2632 This adds support for both `impl const Trait for Ty` and `?const Trait` bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-added `constness` field on `ast::TraitRef`, although this may change once the implementation is fleshed out. I was planning on using `delay_span_bug` when this syntax is encountered during lowering, but I can't write `should-ice` UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the `.stderr` files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled? @oli-obk I went with `const_trait_impl` and `const_trait_bound_opt_out` for the names of these features. Are these to your liking? cc rust-lang#67792 rust-lang#67794 r? @Centril
Rollup of 6 pull requests Successful merges: - #66463 (Point at opaque and closure type definitions in type errors) - #67501 (Reduce special treatment for zsts) - #67820 (Parse the syntax described in RFC 2632) - #67922 (rustc_ast_lowering: misc cleanup & rustc dep reductions) - #68071 (Extend support of `_` in type parameters) - #68073 (expect `fn` after `const unsafe` / `const extern`) Failed merges: r? @ghost
This adds support for both
impl const Trait for Ty
and?const Trait
bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-addedconstness
field onast::TraitRef
, although this may change once the implementation is fleshed out.I was planning on using
delay_span_bug
when this syntax is encountered during lowering, but I can't writeshould-ice
UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the.stderr
files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled?@oli-obk I went with
const_trait_impl
andconst_trait_bound_opt_out
for the names of these features. Are these to your liking?cc #67792 #67794
r? @Centril