Merge pull request #20105 from Veykril/push-qtmwnuqvsruw

Parse new const trait syntax
This commit is contained in:
Lukas Wirth 2025-06-26 10:38:11 +00:00 committed by GitHub
commit d2691ac24b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 19 additions and 9 deletions

View File

@ -122,7 +122,7 @@ fn lifetime_bounds(p: &mut Parser<'_>) {
} }
// test type_param_bounds // test type_param_bounds
// struct S<T: 'a + ?Sized + (Copy) + ~const Drop>; // struct S<T: 'a + ?Sized + (Copy) + [const] Drop>;
pub(super) fn bounds(p: &mut Parser<'_>) { pub(super) fn bounds(p: &mut Parser<'_>) {
p.expect(T![:]); p.expect(T![:]);
bounds_without_colon(p); bounds_without_colon(p);
@ -187,6 +187,11 @@ fn type_bound(p: &mut Parser<'_>) -> bool {
p.bump_any(); p.bump_any();
p.expect(T![const]); p.expect(T![const]);
} }
T!['['] => {
p.bump_any();
p.expect(T![const]);
p.expect(T![']']);
}
// test const_trait_bound // test const_trait_bound
// const fn foo(_: impl const Trait) {} // const fn foo(_: impl const Trait) {}
T![const] => { T![const] => {

View File

@ -40,8 +40,9 @@ SOURCE_FILE
PLUS "+" PLUS "+"
WHITESPACE " " WHITESPACE " "
TYPE_BOUND TYPE_BOUND
TILDE "~" L_BRACK "["
CONST_KW "const" CONST_KW "const"
R_BRACK "]"
WHITESPACE " " WHITESPACE " "
PATH_TYPE PATH_TYPE
PATH PATH

View File

@ -1 +1 @@
struct S<T: 'a + ?Sized + (Copy) + ~const Drop>; struct S<T: 'a + ?Sized + (Copy) + [const] Drop>;

View File

@ -669,7 +669,7 @@ TypeBoundList =
TypeBound = TypeBound =
Lifetime Lifetime
| ('~' 'const' | 'const')? 'async'? '?'? Type | ('~' 'const' | '[' 'const' ']' | 'const')? 'async'? '?'? Type
| 'use' UseBoundGenericArgs | 'use' UseBoundGenericArgs
UseBoundGenericArgs = UseBoundGenericArgs =

View File

@ -1766,6 +1766,10 @@ impl TypeBound {
support::child(&self.syntax) support::child(&self.syntax)
} }
#[inline] #[inline]
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
#[inline]
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
#[inline]
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
#[inline] #[inline]
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }

View File

@ -686,7 +686,7 @@ pub mod ops {
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A: Tuple, F: ?Sized> const Fn<A> for &F impl<A: Tuple, F: ?Sized> const Fn<A> for &F
where where
F: ~const Fn<A>, F: [const] Fn<A>,
{ {
extern "rust-call" fn call(&self, args: A) -> F::Output { extern "rust-call" fn call(&self, args: A) -> F::Output {
(**self).call(args) (**self).call(args)
@ -697,7 +697,7 @@ pub mod ops {
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F impl<A: Tuple, F: ?Sized> const FnMut<A> for &F
where where
F: ~const Fn<A>, F: [const] Fn<A>,
{ {
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(**self).call(args) (**self).call(args)
@ -708,7 +708,7 @@ pub mod ops {
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F
where where
F: ~const Fn<A>, F: [const] Fn<A>,
{ {
type Output = F::Output; type Output = F::Output;
@ -721,7 +721,7 @@ pub mod ops {
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
where where
F: ~const FnMut<A>, F: [const] FnMut<A>,
{ {
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(*self).call_mut(args) (*self).call_mut(args)
@ -732,7 +732,7 @@ pub mod ops {
#[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")]
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
where where
F: ~const FnMut<A>, F: [const] FnMut<A>,
{ {
type Output = F::Output; type Output = F::Output;
extern "rust-call" fn call_once(self, args: A) -> F::Output { extern "rust-call" fn call_once(self, args: A) -> F::Output {