Skip to content

Commit 84bf024

Browse files
bors[bot]matklad
andauthored
Merge #5621
5621: Finalize TypeBound grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 847a50e + b250ae6 commit 84bf024

File tree

4 files changed

+35
-54
lines changed

4 files changed

+35
-54
lines changed

crates/ra_hir_def/src/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl GenericParams {
270270
bound: ast::TypeBound,
271271
type_ref: TypeRef,
272272
) {
273-
if bound.question_token().is_some() {
273+
if bound.question_mark_token().is_some() {
274274
// FIXME: remove this bound
275275
return;
276276
}

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,17 @@ impl DynTraitType {
639639
pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
640640
}
641641
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
642+
pub struct TypeBound {
643+
pub(crate) syntax: SyntaxNode,
644+
}
645+
impl TypeBound {
646+
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
647+
support::token(&self.syntax, T![lifetime])
648+
}
649+
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
650+
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
651+
}
652+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
642653
pub struct TupleExpr {
643654
pub(crate) syntax: SyntaxNode,
644655
}
@@ -1168,17 +1179,6 @@ impl MacroStmts {
11681179
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
11691180
}
11701181
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1171-
pub struct TypeBound {
1172-
pub(crate) syntax: SyntaxNode,
1173-
}
1174-
impl TypeBound {
1175-
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1176-
support::token(&self.syntax, T![lifetime])
1177-
}
1178-
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1179-
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1180-
}
1181-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11821182
pub struct WherePred {
11831183
pub(crate) syntax: SyntaxNode,
11841184
}
@@ -2045,6 +2045,17 @@ impl AstNode for DynTraitType {
20452045
}
20462046
fn syntax(&self) -> &SyntaxNode { &self.syntax }
20472047
}
2048+
impl AstNode for TypeBound {
2049+
fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND }
2050+
fn cast(syntax: SyntaxNode) -> Option<Self> {
2051+
if Self::can_cast(syntax.kind()) {
2052+
Some(Self { syntax })
2053+
} else {
2054+
None
2055+
}
2056+
}
2057+
fn syntax(&self) -> &SyntaxNode { &self.syntax }
2058+
}
20482059
impl AstNode for TupleExpr {
20492060
fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_EXPR }
20502061
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2661,17 +2672,6 @@ impl AstNode for MacroStmts {
26612672
}
26622673
fn syntax(&self) -> &SyntaxNode { &self.syntax }
26632674
}
2664-
impl AstNode for TypeBound {
2665-
fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND }
2666-
fn cast(syntax: SyntaxNode) -> Option<Self> {
2667-
if Self::can_cast(syntax.kind()) {
2668-
Some(Self { syntax })
2669-
} else {
2670-
None
2671-
}
2672-
}
2673-
fn syntax(&self) -> &SyntaxNode { &self.syntax }
2674-
}
26752675
impl AstNode for WherePred {
26762676
fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED }
26772677
fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3746,6 +3746,11 @@ impl std::fmt::Display for DynTraitType {
37463746
std::fmt::Display::fmt(self.syntax(), f)
37473747
}
37483748
}
3749+
impl std::fmt::Display for TypeBound {
3750+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3751+
std::fmt::Display::fmt(self.syntax(), f)
3752+
}
3753+
}
37493754
impl std::fmt::Display for TupleExpr {
37503755
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37513756
std::fmt::Display::fmt(self.syntax(), f)
@@ -4026,11 +4031,6 @@ impl std::fmt::Display for MacroStmts {
40264031
std::fmt::Display::fmt(self.syntax(), f)
40274032
}
40284033
}
4029-
impl std::fmt::Display for TypeBound {
4030-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4031-
std::fmt::Display::fmt(self.syntax(), f)
4032-
}
4033-
}
40344034
impl std::fmt::Display for WherePred {
40354035
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40364036
std::fmt::Display::fmt(self.syntax(), f)

crates/ra_syntax/src/ast/node_ext.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -362,26 +362,6 @@ impl ast::TypeBound {
362362
unreachable!()
363363
}
364364
}
365-
366-
pub fn const_question_token(&self) -> Option<SyntaxToken> {
367-
self.syntax()
368-
.children_with_tokens()
369-
.filter_map(|it| it.into_token())
370-
.take_while(|it| it.kind() != T![const])
371-
.find(|it| it.kind() == T![?])
372-
}
373-
374-
pub fn question_token(&self) -> Option<SyntaxToken> {
375-
if self.const_token().is_some() {
376-
self.syntax()
377-
.children_with_tokens()
378-
.filter_map(|it| it.into_token())
379-
.skip_while(|it| it.kind() != T![const])
380-
.find(|it| it.kind() == T![?])
381-
} else {
382-
support::token(&self.syntax, T![?])
383-
}
384-
}
385365
}
386366

387367
pub enum VisibilityKind {

xtask/src/codegen/rust.ungram

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ ImplTraitType =
242242
DynTraitType =
243243
'dyn' TypeBoundList
244244

245+
TypeBoundList =
246+
bounds:(TypeBound ('+' TypeBound)* '+'?)
247+
248+
TypeBound =
249+
'lifetime'
250+
| '?'? Type
251+
245252
TupleExpr =
246253
Attr* '(' Expr* ')'
247254

@@ -443,12 +450,6 @@ MacroStmts =
443450
statements:Stmt*
444451
Expr?
445452

446-
TypeBound =
447-
'lifetime' | 'const'? Type
448-
449-
TypeBoundList =
450-
bounds:TypeBound*
451-
452453
WherePred =
453454
('for' GenericParamList)? ('lifetime' | Type) ':' TypeBoundList
454455

0 commit comments

Comments
 (0)