Skip to content

Commit d2691ac

Browse files
authored
Merge pull request #20105 from Veykril/push-qtmwnuqvsruw
Parse new const trait syntax
2 parents 332434a + 5924b38 commit d2691ac

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

crates/parser/src/grammar/generic_params.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn lifetime_bounds(p: &mut Parser<'_>) {
122122
}
123123

124124
// test type_param_bounds
125-
// struct S<T: 'a + ?Sized + (Copy) + ~const Drop>;
125+
// struct S<T: 'a + ?Sized + (Copy) + [const] Drop>;
126126
pub(super) fn bounds(p: &mut Parser<'_>) {
127127
p.expect(T![:]);
128128
bounds_without_colon(p);
@@ -187,6 +187,11 @@ fn type_bound(p: &mut Parser<'_>) -> bool {
187187
p.bump_any();
188188
p.expect(T![const]);
189189
}
190+
T!['['] => {
191+
p.bump_any();
192+
p.expect(T![const]);
193+
p.expect(T![']']);
194+
}
190195
// test const_trait_bound
191196
// const fn foo(_: impl const Trait) {}
192197
T![const] => {

crates/parser/test_data/parser/inline/ok/type_param_bounds.rast

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ SOURCE_FILE
4040
PLUS "+"
4141
WHITESPACE " "
4242
TYPE_BOUND
43-
TILDE "~"
43+
L_BRACK "["
4444
CONST_KW "const"
45+
R_BRACK "]"
4546
WHITESPACE " "
4647
PATH_TYPE
4748
PATH
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
struct S<T: 'a + ?Sized + (Copy) + ~const Drop>;
1+
struct S<T: 'a + ?Sized + (Copy) + [const] Drop>;

crates/syntax/rust.ungram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ TypeBoundList =
669669

670670
TypeBound =
671671
Lifetime
672-
| ('~' 'const' | 'const')? 'async'? '?'? Type
672+
| ('~' 'const' | '[' 'const' ']' | 'const')? 'async'? '?'? Type
673673
| 'use' UseBoundGenericArgs
674674

675675
UseBoundGenericArgs =

crates/syntax/src/ast/generated/nodes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,10 @@ impl TypeBound {
17661766
support::child(&self.syntax)
17671767
}
17681768
#[inline]
1769+
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1770+
#[inline]
1771+
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1772+
#[inline]
17691773
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
17701774
#[inline]
17711775
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }

crates/test-utils/src/minicore.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ pub mod ops {
686686
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
687687
impl<A: Tuple, F: ?Sized> const Fn<A> for &F
688688
where
689-
F: ~const Fn<A>,
689+
F: [const] Fn<A>,
690690
{
691691
extern "rust-call" fn call(&self, args: A) -> F::Output {
692692
(**self).call(args)
@@ -697,7 +697,7 @@ pub mod ops {
697697
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
698698
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F
699699
where
700-
F: ~const Fn<A>,
700+
F: [const] Fn<A>,
701701
{
702702
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
703703
(**self).call(args)
@@ -708,7 +708,7 @@ pub mod ops {
708708
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
709709
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F
710710
where
711-
F: ~const Fn<A>,
711+
F: [const] Fn<A>,
712712
{
713713
type Output = F::Output;
714714

@@ -721,7 +721,7 @@ pub mod ops {
721721
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
722722
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
723723
where
724-
F: ~const FnMut<A>,
724+
F: [const] FnMut<A>,
725725
{
726726
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
727727
(*self).call_mut(args)
@@ -732,7 +732,7 @@ pub mod ops {
732732
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
733733
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
734734
where
735-
F: ~const FnMut<A>,
735+
F: [const] FnMut<A>,
736736
{
737737
type Output = F::Output;
738738
extern "rust-call" fn call_once(self, args: A) -> F::Output {

0 commit comments

Comments
 (0)