From d1eceefeb8b683da3f64b89446f04f01803962e1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Aug 2018 17:42:43 +0300 Subject: dyn type --- crates/libsyntax2/src/grammar.ron | 2 ++ crates/libsyntax2/src/grammar/types.rs | 13 ++++++++++++- crates/libsyntax2/src/syntax_kinds/generated.rs | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2/src') diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index ee231931e..c07ed4203 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -55,6 +55,7 @@ Grammar( "enum", "trait", "impl", + "dyn", "true", "false", "as", @@ -134,6 +135,7 @@ Grammar( "FN_POINTER_TYPE", "FOR_TYPE", "IMPL_TRAIT_TYPE", + "DYN_TRAIT_TYPE", "REF_PAT", "BIND_PAT", diff --git a/crates/libsyntax2/src/grammar/types.rs b/crates/libsyntax2/src/grammar/types.rs index 0d8c6bfba..5ba3fcca0 100644 --- a/crates/libsyntax2/src/grammar/types.rs +++ b/crates/libsyntax2/src/grammar/types.rs @@ -11,9 +11,10 @@ pub(super) fn type_(p: &mut Parser) { FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), FOR_KW => for_type(p), IMPL_KW => impl_trait_type(p), + DYN_KW => dyn_trait_type(p), _ if paths::is_path_start(p) => path_type(p), _ => { - p.error("expected type"); + p.err_and_bump("expected type"); } } } @@ -194,6 +195,16 @@ fn impl_trait_type(p: &mut Parser) { m.complete(p, IMPL_TRAIT_TYPE); } +// test dyn_trait_type +// type A = dyn Iterator> + 'a; +fn dyn_trait_type(p: &mut Parser) { + assert!(p.at(DYN_KW)); + let m = p.start(); + p.bump(); + type_params::bounds_without_colon(p); + m.complete(p, DYN_TRAIT_TYPE); +} + // test path_type // type A = Foo; // type B = ::Foo; diff --git a/crates/libsyntax2/src/syntax_kinds/generated.rs b/crates/libsyntax2/src/syntax_kinds/generated.rs index c45a4800c..f5f8fe1ef 100644 --- a/crates/libsyntax2/src/syntax_kinds/generated.rs +++ b/crates/libsyntax2/src/syntax_kinds/generated.rs @@ -62,6 +62,7 @@ pub enum SyntaxKind { ENUM_KW, TRAIT_KW, IMPL_KW, + DYN_KW, TRUE_KW, FALSE_KW, AS_KW, @@ -133,6 +134,7 @@ pub enum SyntaxKind { FN_POINTER_TYPE, FOR_TYPE, IMPL_TRAIT_TYPE, + DYN_TRAIT_TYPE, REF_PAT, BIND_PAT, PLACEHOLDER_PAT, @@ -210,6 +212,7 @@ impl SyntaxKind { | ENUM_KW | TRAIT_KW | IMPL_KW + | DYN_KW | TRUE_KW | FALSE_KW | AS_KW @@ -297,6 +300,7 @@ impl SyntaxKind { ENUM_KW => &SyntaxInfo { name: "ENUM_KW" }, TRAIT_KW => &SyntaxInfo { name: "TRAIT_KW" }, IMPL_KW => &SyntaxInfo { name: "IMPL_KW" }, + DYN_KW => &SyntaxInfo { name: "DYN_KW" }, TRUE_KW => &SyntaxInfo { name: "TRUE_KW" }, FALSE_KW => &SyntaxInfo { name: "FALSE_KW" }, AS_KW => &SyntaxInfo { name: "AS_KW" }, @@ -368,6 +372,7 @@ impl SyntaxKind { FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" }, + DYN_TRAIT_TYPE => &SyntaxInfo { name: "DYN_TRAIT_TYPE" }, REF_PAT => &SyntaxInfo { name: "REF_PAT" }, BIND_PAT => &SyntaxInfo { name: "BIND_PAT" }, PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, @@ -445,6 +450,7 @@ impl SyntaxKind { "enum" => ENUM_KW, "trait" => TRAIT_KW, "impl" => IMPL_KW, + "dyn" => DYN_KW, "true" => TRUE_KW, "false" => FALSE_KW, "as" => AS_KW, -- cgit v1.2.3