aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/Cargo.toml36
-rw-r--r--crates/ra_syntax/fuzz/.gitignore4
-rw-r--r--crates/ra_syntax/fuzz/Cargo.toml27
-rw-r--r--crates/ra_syntax/fuzz/fuzz_targets/parser.rs11
-rw-r--r--crates/ra_syntax/fuzz/fuzz_targets/reparse.rs11
-rw-r--r--crates/ra_syntax/src/algo.rs406
-rw-r--r--crates/ra_syntax/src/ast.rs331
-rw-r--r--crates/ra_syntax/src/ast/edit.rs642
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs418
-rw-r--r--crates/ra_syntax/src/ast/generated.rs41
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs4067
-rw-r--r--crates/ra_syntax/src/ast/generated/tokens.rs91
-rw-r--r--crates/ra_syntax/src/ast/make.rs392
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs485
-rw-r--r--crates/ra_syntax/src/ast/token_ext.rs538
-rw-r--r--crates/ra_syntax/src/ast/traits.rs142
-rw-r--r--crates/ra_syntax/src/fuzz.rs73
-rw-r--r--crates/ra_syntax/src/lib.rs388
-rw-r--r--crates/ra_syntax/src/parsing.rs59
-rw-r--r--crates/ra_syntax/src/parsing/lexer.rs244
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs455
-rw-r--r--crates/ra_syntax/src/parsing/text_token_source.rs84
-rw-r--r--crates/ra_syntax/src/parsing/text_tree_sink.rs183
-rw-r--r--crates/ra_syntax/src/ptr.rs105
-rw-r--r--crates/ra_syntax/src/syntax_error.rs44
-rw-r--r--crates/ra_syntax/src/syntax_node.rs77
-rw-r--r--crates/ra_syntax/src/tests.rs280
-rw-r--r--crates/ra_syntax/src/validation.rs303
-rw-r--r--crates/ra_syntax/src/validation/block.rs22
-rw-r--r--crates/ra_syntax/test_data/accidentally_quadratic3980
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0001_unclosed_char_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0001_unclosed_char_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0002_unclosed_char_with_ferris.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0002_unclosed_char_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0003_unclosed_char_with_ascii_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0003_unclosed_char_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0004_unclosed_char_with_unicode_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0004_unclosed_char_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0005_unclosed_char_with_space.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0005_unclosed_char_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0006_unclosed_char_with_slash.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0006_unclosed_char_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0007_unclosed_char_with_slash_n.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0007_unclosed_char_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0008_unclosed_char_with_slash_single_quote.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0008_unclosed_char_with_slash_single_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0009_unclosed_byte_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0009_unclosed_byte_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0010_unclosed_byte_with_ferris.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0010_unclosed_byte_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0011_unclosed_byte_with_ascii_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0011_unclosed_byte_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0012_unclosed_byte_with_unicode_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0012_unclosed_byte_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0013_unclosed_byte_with_space.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0013_unclosed_byte_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0014_unclosed_byte_with_slash.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0014_unclosed_byte_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0015_unclosed_byte_with_slash_n.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0015_unclosed_byte_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0016_unclosed_byte_with_slash_single_quote.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0016_unclosed_byte_with_slash_single_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0017_unclosed_string_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0017_unclosed_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0018_unclosed_string_with_ferris.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0018_unclosed_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0019_unclosed_string_with_ascii_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0019_unclosed_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0020_unclosed_string_with_unicode_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0020_unclosed_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0021_unclosed_string_with_space.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0021_unclosed_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0022_unclosed_string_with_slash.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0022_unclosed_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0023_unclosed_string_with_slash_n.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0023_unclosed_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0024_unclosed_string_with_slash_double_quote.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0024_unclosed_string_with_slash_double_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0025_unclosed_byte_string_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0025_unclosed_byte_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0026_unclosed_byte_string_with_ferris.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0026_unclosed_byte_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0027_unclosed_byte_string_with_ascii_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0027_unclosed_byte_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0028_unclosed_byte_string_with_unicode_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0028_unclosed_byte_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0029_unclosed_byte_string_with_space.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0029_unclosed_byte_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0030_unclosed_byte_string_with_slash.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0030_unclosed_byte_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0031_unclosed_byte_string_with_slash_n.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0031_unclosed_byte_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0032_unclosed_byte_string_with_slash_double_quote.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0032_unclosed_byte_string_with_slash_double_quote.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0033_unclosed_raw_string_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0033_unclosed_raw_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0034_unclosed_raw_string_with_ferris.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0034_unclosed_raw_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0035_unclosed_raw_string_with_ascii_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0035_unclosed_raw_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0036_unclosed_raw_string_with_unicode_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0036_unclosed_raw_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0037_unclosed_raw_string_with_space.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0037_unclosed_raw_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0038_unclosed_raw_string_with_slash.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0038_unclosed_raw_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0039_unclosed_raw_string_with_slash_n.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0039_unclosed_raw_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0040_unclosed_raw_byte_string_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0040_unclosed_raw_byte_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0041_unclosed_raw_byte_string_with_ferris.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0041_unclosed_raw_byte_string_with_ferris.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0042_unclosed_raw_byte_string_with_ascii_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0042_unclosed_raw_byte_string_with_ascii_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0043_unclosed_raw_byte_string_with_unicode_escape.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0043_unclosed_raw_byte_string_with_unicode_escape.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0044_unclosed_raw_byte_string_with_space.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0044_unclosed_raw_byte_string_with_space.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0045_unclosed_raw_byte_string_with_slash.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0045_unclosed_raw_byte_string_with_slash.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0046_unclosed_raw_byte_string_with_slash_n.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0046_unclosed_raw_byte_string_with_slash_n.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0047_unstarted_raw_string_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0047_unstarted_raw_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0048_unstarted_raw_byte_string_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0048_unstarted_raw_byte_string_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0049_unstarted_raw_string_with_ascii.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0049_unstarted_raw_string_with_ascii.txt10
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0050_unstarted_raw_byte_string_with_ascii.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0050_unstarted_raw_byte_string_with_ascii.txt10
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0051_unclosed_block_comment_at_eof.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0051_unclosed_block_comment_at_eof.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0052_unclosed_block_comment_with_content.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0052_unclosed_block_comment_with_content.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0053_unclosed_nested_block_comment_entirely.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0053_unclosed_nested_block_comment_entirely.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0054_unclosed_nested_block_comment_partially.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0054_unclosed_nested_block_comment_partially.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0055_empty_int.rs17
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0055_empty_int.txt39
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0056_empty_exponent.rs22
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0056_empty_exponent.txt62
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0057_lifetime_strarts_with_a_number.rs2
-rw-r--r--crates/ra_syntax/test_data/lexer/err/0057_lifetime_strarts_with_a_number.txt6
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0001_hello.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0001_hello.txt3
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0002_whitespace.rs4
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0002_whitespace.txt12
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0003_ident.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0003_ident.txt14
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0004_numbers.rs9
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0004_numbers.txt57
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0005_symbols.rs6
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0005_symbols.txt77
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0006_chars.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0006_chars.txt16
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0007_lifetimes.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0007_lifetimes.txt8
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0008_byte_strings.rs3
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0008_byte_strings.txt22
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0009_strings.rs2
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0009_strings.txt8
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0010_single_line_comments.rs12
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0010_single_line_comments.txt22
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0011_keywords.rs3
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt64
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0012_block_comment.rs3
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0012_block_comment.txt6
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0013_raw_strings.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0013_raw_strings.txt2
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0014_raw_ident.rs1
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0014_raw_ident.txt2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0000_struct_field_missing_comma.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/err/0000_struct_field_missing_comma.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0001_item_recovery_in_file.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/err/0001_item_recovery_in_file.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.rast39
-rw-r--r--crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0003_C++_semicolon.rast39
-rw-r--r--crates/ra_syntax/test_data/parser/err/0003_C++_semicolon.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rast59
-rw-r--r--crates/ra_syntax/test_data/parser/err/0005_attribute_recover.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0006_named_field_recovery.rast74
-rw-r--r--crates/ra_syntax/test_data/parser/err/0006_named_field_recovery.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rast32
-rw-r--r--crates/ra_syntax/test_data/parser/err/0007_stray_curly_in_file.rs9
-rw-r--r--crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rast77
-rw-r--r--crates/ra_syntax/test_data/parser/err/0008_item_block_recovery.rs13
-rw-r--r--crates/ra_syntax/test_data/parser/err/0009_broken_struct_type_parameter.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/err/0009_broken_struct_type_parameter.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/err/0010_unsafe_lambda_block.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0011_extern_struct.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/err/0011_extern_struct.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/err/0012_broken_lambda.rast387
-rw-r--r--crates/ra_syntax/test_data/parser/err/0013_invalid_type.rast89
-rw-r--r--crates/ra_syntax/test_data/parser/err/0013_invalid_type.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rast31
-rw-r--r--crates/ra_syntax/test_data/parser/err/0014_where_no_bounds.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/err/0015_curly_in_params.rast24
-rw-r--r--crates/ra_syntax/test_data/parser/err/0015_curly_in_params.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0016_missing_semi.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/err/0016_missing_semi.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/err/0017_incomplete_binexpr.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rast131
-rw-r--r--crates/ra_syntax/test_data/parser/err/0018_incomplete_fn.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/err/0019_let_recover.rast103
-rw-r--r--crates/ra_syntax/test_data/parser/err/0019_let_recover.rs12
-rw-r--r--crates/ra_syntax/test_data/parser/err/0020_fn_recover.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/err/0020_fn_recover.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0021_incomplete_param.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/err/0021_incomplete_param.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0022_bad_exprs.rast180
-rw-r--r--crates/ra_syntax/test_data/parser/err/0022_bad_exprs.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0023_mismatched_paren.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/err/0023_mismatched_paren.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast319
-rw-r--r--crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/err/0025_nope.rast202
-rw-r--r--crates/ra_syntax/test_data/parser/err/0025_nope.rs31
-rw-r--r--crates/ra_syntax/test_data/parser/err/0026_imp_recovery.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/err/0026_imp_recovery.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0027_incomplere_where_for.rast27
-rw-r--r--crates/ra_syntax/test_data/parser/err/0027_incomplere_where_for.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0029_field_completion.rast35
-rw-r--r--crates/ra_syntax/test_data/parser/err/0029_field_completion.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0031_block_inner_attrs.rast121
-rw-r--r--crates/ra_syntax/test_data/parser/err/0031_block_inner_attrs.rs15
-rw-r--r--crates/ra_syntax/test_data/parser/err/0032_match_arms_inner_attrs.rast203
-rw-r--r--crates/ra_syntax/test_data/parser/err/0032_match_arms_inner_attrs.rs20
-rw-r--r--crates/ra_syntax/test_data/parser/err/0033_match_arms_outer_attrs.rast66
-rw-r--r--crates/ra_syntax/test_data/parser/err/0033_match_arms_outer_attrs.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/err/0034_bad_box_pattern.rast95
-rw-r--r--crates/ra_syntax/test_data/parser/err/0034_bad_box_pattern.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0035_use_recover.rast53
-rw-r--r--crates/ra_syntax/test_data/parser/err/0035_use_recover.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0036_partial_use.rast51
-rw-r--r--crates/ra_syntax/test_data/parser/err/0036_partial_use.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast97
-rw-r--r--crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rast29
-rw-r--r--crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0039_lambda_recovery.rast82
-rw-r--r--crates/ra_syntax/test_data/parser/err/0039_lambda_recovery.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast91
-rw-r--r--crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0041_illegal_super_keyword_location.rast70
-rw-r--r--crates/ra_syntax/test_data/parser/err/0041_illegal_super_keyword_location.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/err/0042_illegal_self_keyword_location.rast27
-rw-r--r--crates/ra_syntax/test_data/parser/err/0042_illegal_self_keyword_location.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/err/0043_default_const.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/err/0043_default_const.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/err/0044_unexpected_for_type.rast240
-rw-r--r--crates/ra_syntax/test_data/parser/err/0044_unexpected_for_type.rs9
-rw-r--r--crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rast71
-rw-r--r--crates/ra_syntax/test_data/parser/err/0163_weird_blocks.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/expr/err/0000_truncated_add.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/expr/err/0000_truncated_add.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/expr/ok/0000_add.rast8
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/expr/ok/0000_add.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/item/err/0000_extra_keyword.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/item/ok/0000_fn.rast12
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/item/ok/0000_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/err/0000_reserved_word.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/err/0000_reserved_word.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/err/0001_expression.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/err/0001_expression.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/ok/0000_single_ident.rast4
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/ok/0000_single_ident.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/ok/0001_multipart.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/path/ok/0001_multipart.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/pattern/err/0000_reserved_word.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/pattern/err/0001_missing_paren.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/pattern/ok/0000_enum.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/pattern/ok/0000_enum.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/type/err/0000_missing_close.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/type/err/0000_missing_close.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/type/ok/0000_result.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/fragments/type/ok/0000_result.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fuzz-failures/0000.rs199
-rw-r--r--crates/ra_syntax/test_data/parser/fuzz-failures/0001.rs106
-rw-r--r--crates/ra_syntax/test_data/parser/fuzz-failures/0002.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fuzz-failures/0003.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/fuzz-failures/0004.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0001_array_type_missing_semi.rast27
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0001_array_type_missing_semi.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0002_misplaced_label_err.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0002_misplaced_label_err.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0003_pointer_type_no_mutability.rast17
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0003_pointer_type_no_mutability.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0004_impl_type.rast79
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0004_impl_type.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0005_fn_pointer_type_missing_fn.rast23
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0005_fn_pointer_type_missing_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0006_unsafe_block_in_mod.rast35
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0006_unsafe_block_in_mod.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0007_async_without_semicolon.rast31
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0007_async_without_semicolon.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0008_pub_expr.rast25
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0008_pub_expr.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0009_attr_on_expr_not_allowed.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0009_attr_on_expr_not_allowed.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_bad_tuple_index_expr.rast52
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_bad_tuple_index_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast45
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_default_fn_type.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_record_literal_before_ellipsis_recovery.rast48
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0014_record_literal_before_ellipsis_recovery.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast71
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rast136
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0002_use_tree_list.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0003_where_pred_for.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0003_where_pred_for.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0004_value_parameters_no_patterns.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0004_value_parameters_no_patterns.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0005_function_type_params.rast37
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0005_function_type_params.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0006_self_param.rast116
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0006_self_param.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0007_type_param_bounds.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0007_type_param_bounds.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0008_path_part.rast96
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0008_path_part.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0009_loop_expr.rast24
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0009_loop_expr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0010_extern_block.rast9
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0010_extern_block.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0011_field_expr.rast59
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0011_field_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0012_type_item_where_clause.rast33
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0012_type_item_where_clause.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0013_pointer_type_mut.rast35
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0013_pointer_type_mut.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0014_never_type.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0014_never_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0015_continue_expr.rast35
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0015_continue_expr.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0016_unsafe_trait.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0017_array_type.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0017_array_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0018_arb_self_types.rast72
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0018_arb_self_types.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0019_unary_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0020_use_star.rast59
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0020_use_star.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast78
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0022_crate_visibility.rast53
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0022_crate_visibility.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0023_placeholder_type.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0023_placeholder_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0024_slice_pat.rast41
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0024_slice_pat.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0025_slice_type.rast17
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0025_slice_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0026_tuple_pat_fields.rast104
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0026_tuple_pat_fields.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0027_ref_pat.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0027_ref_pat.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0028_impl_trait_type.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0028_impl_trait_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0029_cast_expr.rast89
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0029_cast_expr.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0030_cond.rast202
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0030_cond.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0031_while_expr.rast84
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0031_while_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0032_fn_pointer_type.rast98
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0032_fn_pointer_type.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0033_reference_type;.rast50
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0033_reference_type;.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0034_break_expr.rast53
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0034_break_expr.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0036_unsafe_extern_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0037_qual_paths.rast78
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0037_qual_paths.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0038_full_range_expr.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0038_full_range_expr.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rast55
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0039_type_arg.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0040_crate_keyword_vis.rast62
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0040_crate_keyword_vis.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0041_trait_item.rast125
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0041_trait_item.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0042_call_expr.rast147
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0042_call_expr.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0043_use_alias.rast138
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0043_use_alias.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0044_block_items.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0044_block_items.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0045_param_list_opt_patterns.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0045_param_list_opt_patterns.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0046_singleton_tuple_type.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0046_singleton_tuple_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0047_unsafe_default_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0048_path_type_with_bounds.rast81
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0048_path_type_with_bounds.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0050_fn_decl.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0050_fn_decl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0051_unit_type.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0051_unit_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0052_path_type.rast70
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0052_path_type.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0053_path_expr.rast95
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0053_path_expr.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0054_record_field_attrs.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0054_record_field_attrs.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0055_literal_pattern.rast76
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0055_literal_pattern.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0056_where_clause.rast110
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0056_where_clause.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0057_const_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0058_range_pat.rast82
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0058_range_pat.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0059_match_arms_commas.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0059_match_arms_commas.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0060_extern_crate.rast10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0060_extern_crate.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0061_record_lit.rast124
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0061_record_lit.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0062_mod_contents.rast66
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0062_mod_contents.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0063_impl_def_neg.rast23
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0063_impl_def_neg.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0064_if_expr.rast121
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0064_if_expr.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0065_dyn_trait_type.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0065_dyn_trait_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rast151
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0066_match_arm.rs9
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0067_crate_path.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0067_crate_path.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rast46
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rast37
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0070_stmt_bin_expr_ambiguity.rast50
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0070_stmt_bin_expr_ambiguity.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0071_match_expr.rast93
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0071_match_expr.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0072_return_expr.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0072_return_expr.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0073_type_item_type_params.rast20
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0073_type_item_type_params.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0074_stmt_postfix_expr_ambiguity.rast59
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0074_stmt_postfix_expr_ambiguity.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0075_block.rast86
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0075_block.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0076_function_where_clause.rast39
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0076_function_where_clause.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0077_try_expr.rast25
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0077_try_expr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0078_type_item.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0078_type_item.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0079_impl_def.rast14
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0079_impl_def.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0080_postfix_range.rast95
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0080_postfix_range.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rast112
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rast138
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0082_ref_expr.rs10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0083_struct_items.rast87
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0083_struct_items.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0084_paren_type.rast19
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0084_paren_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0085_expr_literals.rast135
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0085_expr_literals.rs12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0086_function_ret_type.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0086_function_ret_type.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0087_unsafe_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0088_break_ambiguity.rast65
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0088_break_ambiguity.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rast17
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0089_extern_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0090_type_param_default.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0090_type_param_default.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rast13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0091_auto_trait.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0092_fn_pointer_type_with_ret.rast23
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0092_fn_pointer_type_with_ret.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0093_index_expr.rast33
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0093_index_expr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0094_unsafe_auto_trait.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0095_placeholder_pat.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0095_placeholder_pat.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0096_no_semi_after_block.rast123
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0096_no_semi_after_block.rs13
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0097_default_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0098_const_unsafe_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0099_param_list.rast99
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0099_param_list.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0100_for_expr.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0100_for_expr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0101_unsafe_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0102_record_field_pat_list.rast132
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0102_record_field_pat_list.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0103_array_expr.rast54
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0103_array_expr.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0104_path_fn_trait_args.rast41
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0104_path_fn_trait_args.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0106_lambda_expr.rast135
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0106_lambda_expr.rs9
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0107_method_call_expr.rast62
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0107_method_call_expr.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0108_tuple_expr.rast38
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0108_tuple_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0109_label.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0109_label.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0110_use_path.rast38
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0110_use_path.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0111_tuple_pat.rast89
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0111_tuple_pat.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0112_bind_pat.rast127
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0112_bind_pat.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0113_nocontentexpr.rast55
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0113_nocontentexpr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0114_tuple_struct_where.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast41
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0117_macro_call_type.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0117_macro_call_type.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_match_guard.rast47
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0118_match_guard.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0120_match_arms_inner_attribute.rast80
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0120_match_arms_inner_attribute.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0121_match_arms_outer_attributes.rast145
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0121_match_arms_outer_attributes.rs12
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast65
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0123_param_list_vararg.rast50
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0123_param_list_vararg.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0124_async_fn.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_crate_keyword_path.rast31
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_crate_keyword_path.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_record_literal_field_with_attr.rast47
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0125_record_literal_field_with_attr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0126_attr_on_expr_stmt.rast97
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0126_attr_on_expr_stmt.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0127_attr_on_last_expr_in_block.rast57
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0127_attr_on_last_expr_in_block.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rast35
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.rast36
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_let_stmt.rast126
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_let_stmt.rs9
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_try_block_expr.rast31
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0130_try_block_expr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0131_existential_type.rast31
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0131_existential_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_box_expr.rast89
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_box_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rast55
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0132_default_fn_type.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0134_nocontentexpr_after_item.rast62
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0134_nocontentexpr_after_item.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0137_await_expr.rast69
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0137_await_expr.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_associated_type_bounds.rast55
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_associated_type_bounds.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rast25
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_self_param_outer_attr.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0139_param_outer_arg.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0139_param_outer_arg.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0143_box_pat.rast110
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0143_box_pat.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0144_dot_dot_pat.rast455
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0144_dot_dot_pat.rs25
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rast75
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0145_record_field_pat.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rast23
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0147_macro_def.rast45
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0147_macro_def.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0148_pub_macro_def.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0148_pub_macro_def.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rast47
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_impl_type_params.rast38
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0150_impl_type_params.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rast128
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0152_arg_with_attr.rast36
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0152_arg_with_attr.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0154_fn_pointer_param_ident_path.rast58
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0154_fn_pointer_param_ident_path.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0155_closure_params.rast69
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0155_closure_params.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_fn_def_param.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_fn_def_param.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_or_pattern.rast111
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0156_or_pattern.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rast30
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rast36
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_lambda_ret_block.rast43
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_lambda_ret_block.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rast34
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0159_try_macro_fallback.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rast27
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0160_try_macro_rules.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0161_labeled_block.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0161_labeled_block.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0162_unsafe_block.rast23
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0162_unsafe_block.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast40
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rast18
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_impl.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rast38
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0000_empty.rast1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0000_empty.rs0
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0001_struct_item.rast39
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0001_struct_item.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0002_struct_item_field.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0002_struct_item_field.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0004_file_shebang.rast2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0004_file_shebang.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0005_fn_item.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0005_fn_item.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0006_inner_attributes.rast184
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0006_inner_attributes.rs10
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0007_extern_crate.rast39
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0007_extern_crate.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0008_mod_item.rast92
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0008_mod_item.rs17
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0009_use_item.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0009_use_item.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0010_use_path_segments.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0010_use_path_segments.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0011_outer_attribute.rast57
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0011_outer_attribute.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0012_visibility.rast102
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0012_visibility.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0013_use_path_self_super.rast33
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0013_use_path_self_super.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0014_use_tree.rast95
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0014_use_tree.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0015_use_tree.rast65
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0015_use_tree.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0016_struct_flavors.rast93
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0016_struct_flavors.rs10
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0017_attr_trailing_comma.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0017_attr_trailing_comma.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0018_struct_type_params.rast257
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0018_struct_type_params.rs17
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0019_enums.rast155
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0019_enums.rs25
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0020_type_param_bounds.rast268
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0020_type_param_bounds.rs10
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rast56
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0021_extern_fn.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0022_empty_extern_block.rast21
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0022_empty_extern_block.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0023_static_items.rast41
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0023_static_items.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0024_const_item.rast59
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0024_const_item.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0025_extern_fn_in_block.rast31
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0025_extern_fn_in_block.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0026_const_fn_in_block.rast30
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0026_const_fn_in_block.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0027_unsafe_fn_in_block.rast41
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0027_unsafe_fn_in_block.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0028_operator_binding_power.rast185
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0028_operator_binding_power.rs14
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0029_range_forms.rast151
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0029_range_forms.rs11
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_string_suffixes.rast63
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_string_suffixes.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_traits.rast61
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0030_traits.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0031_extern.rast973
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0031_extern.rs29
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0032_where_for.rast90
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0032_where_for.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0033_label_break.rast215
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0033_label_break.rs28
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0034_crate_path_in_call.rast41
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0034_crate_path_in_call.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast2291
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rs154
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0036_fully_qualified.rast92
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0036_fully_qualified.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0037_mod.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0037_mod.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0038_where_pred_type.rast42
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0038_where_pred_type.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0039_raw_fn_item.rast15
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0039_raw_fn_item.rs2
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0040_raw_struct_item_field.rast22
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0040_raw_struct_item_field.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0041_raw_keywords.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0041_raw_keywords.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0042_ufcs_call_list.rast123
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0042_ufcs_call_list.rs15
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0043_complex_assignment.rast109
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0043_complex_assignment.rs8
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0044_let_attrs.rast75
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0044_let_attrs.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0045_block_inner_attrs.rast177
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0045_block_inner_attrs.rs20
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0046_extern_inner_attributes.rast28
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0046_extern_inner_attributes.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0047_minus_in_inner_pattern.rast320
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0047_minus_in_inner_pattern.rs27
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0048_compound_assignment.rast200
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0048_compound_assignment.rs17
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0049_async_block.rast35
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0049_async_block.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0050_async_block_as_argument.rast90
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0050_async_block_as_argument.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0051_parameter_attrs.rast508
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0051_parameter_attrs.rs21
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rast78
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0053_outer_attribute_on_macro_rules.rast39
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0053_outer_attribute_on_macro_rules.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0054_qual_path_in_type_arg.rast123
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0054_qual_path_in_type_arg.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0055_dot_dot_dot.rast49
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0055_dot_dot_dot.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0056_neq_in_type.rast64
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0056_neq_in_type.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0057_loop_in_call.rast56
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0057_loop_in_call.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0058_unary_expr_precedence.rast96
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0058_unary_expr_precedence.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0059_loops_in_parens.rast97
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0059_loops_in_parens.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0060_as_range.rast55
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0060_as_range.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rast26
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0062_macro_2.0.rast175
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0062_macro_2.0.rs15
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_trait_fn_patterns.rast194
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_trait_fn_patterns.rs7
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_variadic_fun.rast133
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0063_variadic_fun.rs5
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0064_impl_fn_params.rast162
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0064_impl_fn_params.rs6
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rast16
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_comment_newline.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_plus_after_fn_trait_bound.rast60
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0065_plus_after_fn_trait_bound.rs1
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0066_default_const.rast44
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0066_default_const.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0067_where_for_pred.rast392
-rw-r--r--crates/ra_syntax/test_data/parser/ok/0067_where_for_pred.rs30
-rw-r--r--crates/ra_syntax/test_data/reparse/fuzz-failures/0000.rs6
-rw-r--r--crates/ra_syntax/test_data/reparse/fuzz-failures/0001.rs4
-rw-r--r--crates/ra_syntax/test_data/reparse/fuzz-failures/0002.rs4
-rw-r--r--crates/ra_syntax/test_data/reparse/fuzz-failures/0003.rsbin8 -> 0 bytes
-rw-r--r--crates/ra_syntax/test_data/reparse/fuzz-failures/0004.rs4
-rw-r--r--crates/ra_syntax/test_data/reparse/fuzz-failures/0005.rs7
794 files changed, 0 insertions, 40207 deletions
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml
deleted file mode 100644
index fc4d7aa04..000000000
--- a/crates/ra_syntax/Cargo.toml
+++ /dev/null
@@ -1,36 +0,0 @@
1[package]
2edition = "2018"
3name = "ra_syntax"
4version = "0.1.0"
5authors = ["rust-analyzer developers"]
6license = "MIT OR Apache-2.0"
7description = "Comment and whitespace preserving parser for the Rust language"
8repository = "https://github.com/rust-analyzer/rust-analyzer"
9
10[lib]
11doctest = false
12
13[dependencies]
14itertools = "0.9.0"
15rowan = "0.10.0"
16rustc_lexer = { version = "671.0.0", package = "rustc-ap-rustc_lexer" }
17rustc-hash = "1.1.0"
18arrayvec = "0.5.1"
19once_cell = "1.3.1"
20
21stdx = { path = "../stdx" }
22
23ra_text_edit = { path = "../ra_text_edit" }
24ra_parser = { path = "../ra_parser" }
25
26# This crate transitively depends on `smol_str` via `rowan`.
27# ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here
28# to reduce number of compilations
29smol_str = { version = "0.1.15", features = ["serde"] }
30serde = { version = "1.0.106", features = ["derive"] }
31
32[dev-dependencies]
33test_utils = { path = "../test_utils" }
34expect = { path = "../expect" }
35walkdir = "2.3.1"
36rayon = "1"
diff --git a/crates/ra_syntax/fuzz/.gitignore b/crates/ra_syntax/fuzz/.gitignore
deleted file mode 100644
index f734abd49..000000000
--- a/crates/ra_syntax/fuzz/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
1Cargo.lock
2target
3corpus
4artifacts
diff --git a/crates/ra_syntax/fuzz/Cargo.toml b/crates/ra_syntax/fuzz/Cargo.toml
deleted file mode 100644
index 613ad2857..000000000
--- a/crates/ra_syntax/fuzz/Cargo.toml
+++ /dev/null
@@ -1,27 +0,0 @@
1
2[package]
3name = "ra_syntax-fuzz"
4version = "0.0.1"
5authors = ["rust-analyzer developers"]
6publish = false
7edition = "2018"
8
9[package.metadata]
10cargo-fuzz = true
11
12[dependencies]
13ra_syntax = { path = ".." }
14ra_text_edit = { path = "../../ra_text_edit" }
15libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
16
17# Prevent this from interfering with workspaces
18[workspace]
19members = ["."]
20
21[[bin]]
22name = "parser"
23path = "fuzz_targets/parser.rs"
24
25[[bin]]
26name = "reparse"
27path = "fuzz_targets/reparse.rs"
diff --git a/crates/ra_syntax/fuzz/fuzz_targets/parser.rs b/crates/ra_syntax/fuzz/fuzz_targets/parser.rs
deleted file mode 100644
index 7bc4ef30d..000000000
--- a/crates/ra_syntax/fuzz/fuzz_targets/parser.rs
+++ /dev/null
@@ -1,11 +0,0 @@
1//! FIXME: write short doc here
2
3#![no_main]
4use libfuzzer_sys::fuzz_target;
5use ra_syntax::fuzz::check_parser;
6
7fuzz_target!(|data: &[u8]| {
8 if let Ok(text) = std::str::from_utf8(data) {
9 check_parser(text)
10 }
11});
diff --git a/crates/ra_syntax/fuzz/fuzz_targets/reparse.rs b/crates/ra_syntax/fuzz/fuzz_targets/reparse.rs
deleted file mode 100644
index 16598f5f1..000000000
--- a/crates/ra_syntax/fuzz/fuzz_targets/reparse.rs
+++ /dev/null
@@ -1,11 +0,0 @@
1//! FIXME: write short doc here
2
3#![no_main]
4use libfuzzer_sys::fuzz_target;
5use ra_syntax::fuzz::CheckReparse;
6
7fuzz_target!(|data: &[u8]| {
8 if let Some(check) = CheckReparse::from_data(data) {
9 check.run();
10 }
11});
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs
deleted file mode 100644
index 26b3c813a..000000000
--- a/crates/ra_syntax/src/algo.rs
+++ /dev/null
@@ -1,406 +0,0 @@
1//! FIXME: write short doc here
2
3use std::{
4 fmt,
5 ops::{self, RangeInclusive},
6};
7
8use itertools::Itertools;
9use ra_text_edit::TextEditBuilder;
10use rustc_hash::FxHashMap;
11
12use crate::{
13 AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr,
14 SyntaxToken, TextRange, TextSize,
15};
16
17/// Returns ancestors of the node at the offset, sorted by length. This should
18/// do the right thing at an edge, e.g. when searching for expressions at `{
19/// <|>foo }` we will get the name reference instead of the whole block, which
20/// we would get if we just did `find_token_at_offset(...).flat_map(|t|
21/// t.parent().ancestors())`.
22pub fn ancestors_at_offset(
23 node: &SyntaxNode,
24 offset: TextSize,
25) -> impl Iterator<Item = SyntaxNode> {
26 node.token_at_offset(offset)
27 .map(|token| token.parent().ancestors())
28 .kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len())
29}
30
31/// Finds a node of specific Ast type at offset. Note that this is slightly
32/// imprecise: if the cursor is strictly between two nodes of the desired type,
33/// as in
34///
35/// ```no-run
36/// struct Foo {}|struct Bar;
37/// ```
38///
39/// then the shorter node will be silently preferred.
40pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextSize) -> Option<N> {
41 ancestors_at_offset(syntax, offset).find_map(N::cast)
42}
43
44pub fn find_node_at_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> {
45 find_covering_element(syntax, range).ancestors().find_map(N::cast)
46}
47
48/// Skip to next non `trivia` token
49pub fn skip_trivia_token(mut token: SyntaxToken, direction: Direction) -> Option<SyntaxToken> {
50 while token.kind().is_trivia() {
51 token = match direction {
52 Direction::Next => token.next_token()?,
53 Direction::Prev => token.prev_token()?,
54 }
55 }
56 Some(token)
57}
58
59/// Finds the first sibling in the given direction which is not `trivia`
60pub fn non_trivia_sibling(element: SyntaxElement, direction: Direction) -> Option<SyntaxElement> {
61 return match element {
62 NodeOrToken::Node(node) => node.siblings_with_tokens(direction).skip(1).find(not_trivia),
63 NodeOrToken::Token(token) => token.siblings_with_tokens(direction).skip(1).find(not_trivia),
64 };
65
66 fn not_trivia(element: &SyntaxElement) -> bool {
67 match element {
68 NodeOrToken::Node(_) => true,
69 NodeOrToken::Token(token) => !token.kind().is_trivia(),
70 }
71 }
72}
73
74pub fn find_covering_element(root: &SyntaxNode, range: TextRange) -> SyntaxElement {
75 root.covering_element(range)
76}
77
78pub fn least_common_ancestor(u: &SyntaxNode, v: &SyntaxNode) -> Option<SyntaxNode> {
79 if u == v {
80 return Some(u.clone());
81 }
82
83 let u_depth = u.ancestors().count();
84 let v_depth = v.ancestors().count();
85 let keep = u_depth.min(v_depth);
86
87 let u_candidates = u.ancestors().skip(u_depth - keep);
88 let v_canidates = v.ancestors().skip(v_depth - keep);
89 let (res, _) = u_candidates.zip(v_canidates).find(|(x, y)| x == y)?;
90 Some(res)
91}
92
93pub fn neighbor<T: AstNode>(me: &T, direction: Direction) -> Option<T> {
94 me.syntax().siblings(direction).skip(1).find_map(T::cast)
95}
96
97pub fn has_errors(node: &SyntaxNode) -> bool {
98 node.children().any(|it| it.kind() == SyntaxKind::ERROR)
99}
100
101#[derive(Debug, PartialEq, Eq, Clone, Copy)]
102pub enum InsertPosition<T> {
103 First,
104 Last,
105 Before(T),
106 After(T),
107}
108
109pub struct TreeDiff {
110 replacements: FxHashMap<SyntaxElement, SyntaxElement>,
111}
112
113impl TreeDiff {
114 pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
115 for (from, to) in self.replacements.iter() {
116 builder.replace(from.text_range(), to.to_string())
117 }
118 }
119
120 pub fn is_empty(&self) -> bool {
121 self.replacements.is_empty()
122 }
123}
124
125/// Finds minimal the diff, which, applied to `from`, will result in `to`.
126///
127/// Specifically, returns a map whose keys are descendants of `from` and values
128/// are descendants of `to`, such that `replace_descendants(from, map) == to`.
129///
130/// A trivial solution is a singleton map `{ from: to }`, but this function
131/// tries to find a more fine-grained diff.
132pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
133 let mut buf = FxHashMap::default();
134 // FIXME: this is both horrible inefficient and gives larger than
135 // necessary diff. I bet there's a cool algorithm to diff trees properly.
136 go(&mut buf, from.clone().into(), to.clone().into());
137 return TreeDiff { replacements: buf };
138
139 fn go(
140 buf: &mut FxHashMap<SyntaxElement, SyntaxElement>,
141 lhs: SyntaxElement,
142 rhs: SyntaxElement,
143 ) {
144 if lhs.kind() == rhs.kind()
145 && lhs.text_range().len() == rhs.text_range().len()
146 && match (&lhs, &rhs) {
147 (NodeOrToken::Node(lhs), NodeOrToken::Node(rhs)) => {
148 lhs.green() == rhs.green() || lhs.text() == rhs.text()
149 }
150 (NodeOrToken::Token(lhs), NodeOrToken::Token(rhs)) => lhs.text() == rhs.text(),
151 _ => false,
152 }
153 {
154 return;
155 }
156 if let (Some(lhs), Some(rhs)) = (lhs.as_node(), rhs.as_node()) {
157 if lhs.children_with_tokens().count() == rhs.children_with_tokens().count() {
158 for (lhs, rhs) in lhs.children_with_tokens().zip(rhs.children_with_tokens()) {
159 go(buf, lhs, rhs)
160 }
161 return;
162 }
163 }
164 buf.insert(lhs, rhs);
165 }
166}
167
168/// Adds specified children (tokens or nodes) to the current node at the
169/// specific position.
170///
171/// This is a type-unsafe low-level editing API, if you need to use it,
172/// prefer to create a type-safe abstraction on top of it instead.
173pub fn insert_children(
174 parent: &SyntaxNode,
175 position: InsertPosition<SyntaxElement>,
176 to_insert: impl IntoIterator<Item = SyntaxElement>,
177) -> SyntaxNode {
178 let mut to_insert = to_insert.into_iter();
179 _insert_children(parent, position, &mut to_insert)
180}
181
182fn _insert_children(
183 parent: &SyntaxNode,
184 position: InsertPosition<SyntaxElement>,
185 to_insert: &mut dyn Iterator<Item = SyntaxElement>,
186) -> SyntaxNode {
187 let mut delta = TextSize::default();
188 let to_insert = to_insert.map(|element| {
189 delta += element.text_range().len();
190 to_green_element(element)
191 });
192
193 let mut old_children = parent.green().children().map(|it| match it {
194 NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()),
195 NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()),
196 });
197
198 let new_children = match &position {
199 InsertPosition::First => to_insert.chain(old_children).collect::<Vec<_>>(),
200 InsertPosition::Last => old_children.chain(to_insert).collect::<Vec<_>>(),
201 InsertPosition::Before(anchor) | InsertPosition::After(anchor) => {
202 let take_anchor = if let InsertPosition::After(_) = position { 1 } else { 0 };
203 let split_at = position_of_child(parent, anchor.clone()) + take_anchor;
204 let before = old_children.by_ref().take(split_at).collect::<Vec<_>>();
205 before.into_iter().chain(to_insert).chain(old_children).collect::<Vec<_>>()
206 }
207 };
208
209 with_children(parent, new_children)
210}
211
212/// Replaces all nodes in `to_delete` with nodes from `to_insert`
213///
214/// This is a type-unsafe low-level editing API, if you need to use it,
215/// prefer to create a type-safe abstraction on top of it instead.
216pub fn replace_children(
217 parent: &SyntaxNode,
218 to_delete: RangeInclusive<SyntaxElement>,
219 to_insert: impl IntoIterator<Item = SyntaxElement>,
220) -> SyntaxNode {
221 let mut to_insert = to_insert.into_iter();
222 _replace_children(parent, to_delete, &mut to_insert)
223}
224
225fn _replace_children(
226 parent: &SyntaxNode,
227 to_delete: RangeInclusive<SyntaxElement>,
228 to_insert: &mut dyn Iterator<Item = SyntaxElement>,
229) -> SyntaxNode {
230 let start = position_of_child(parent, to_delete.start().clone());
231 let end = position_of_child(parent, to_delete.end().clone());
232 let mut old_children = parent.green().children().map(|it| match it {
233 NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()),
234 NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()),
235 });
236
237 let before = old_children.by_ref().take(start).collect::<Vec<_>>();
238 let new_children = before
239 .into_iter()
240 .chain(to_insert.map(to_green_element))
241 .chain(old_children.skip(end + 1 - start))
242 .collect::<Vec<_>>();
243 with_children(parent, new_children)
244}
245
246#[derive(Default)]
247pub struct SyntaxRewriter<'a> {
248 f: Option<Box<dyn Fn(&SyntaxElement) -> Option<SyntaxElement> + 'a>>,
249 //FIXME: add debug_assertions that all elements are in fact from the same file.
250 replacements: FxHashMap<SyntaxElement, Replacement>,
251}
252
253impl fmt::Debug for SyntaxRewriter<'_> {
254 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
255 f.debug_struct("SyntaxRewriter").field("replacements", &self.replacements).finish()
256 }
257}
258
259impl<'a> SyntaxRewriter<'a> {
260 pub fn from_fn(f: impl Fn(&SyntaxElement) -> Option<SyntaxElement> + 'a) -> SyntaxRewriter<'a> {
261 SyntaxRewriter { f: Some(Box::new(f)), replacements: FxHashMap::default() }
262 }
263 pub fn delete<T: Clone + Into<SyntaxElement>>(&mut self, what: &T) {
264 let what = what.clone().into();
265 let replacement = Replacement::Delete;
266 self.replacements.insert(what, replacement);
267 }
268 pub fn replace<T: Clone + Into<SyntaxElement>>(&mut self, what: &T, with: &T) {
269 let what = what.clone().into();
270 let replacement = Replacement::Single(with.clone().into());
271 self.replacements.insert(what, replacement);
272 }
273 pub fn replace_with_many<T: Clone + Into<SyntaxElement>>(
274 &mut self,
275 what: &T,
276 with: Vec<SyntaxElement>,
277 ) {
278 let what = what.clone().into();
279 let replacement = Replacement::Many(with);
280 self.replacements.insert(what, replacement);
281 }
282 pub fn replace_ast<T: AstNode>(&mut self, what: &T, with: &T) {
283 self.replace(what.syntax(), with.syntax())
284 }
285
286 pub fn rewrite(&self, node: &SyntaxNode) -> SyntaxNode {
287 if self.f.is_none() && self.replacements.is_empty() {
288 return node.clone();
289 }
290 self.rewrite_children(node)
291 }
292
293 pub fn rewrite_ast<N: AstNode>(self, node: &N) -> N {
294 N::cast(self.rewrite(node.syntax())).unwrap()
295 }
296
297 /// Returns a node that encompasses all replacements to be done by this rewriter.
298 ///
299 /// Passing the returned node to `rewrite` will apply all replacements queued up in `self`.
300 ///
301 /// Returns `None` when there are no replacements.
302 pub fn rewrite_root(&self) -> Option<SyntaxNode> {
303 assert!(self.f.is_none());
304 self.replacements
305 .keys()
306 .map(|element| match element {
307 SyntaxElement::Node(it) => it.clone(),
308 SyntaxElement::Token(it) => it.parent(),
309 })
310 // If we only have one replacement, we must return its parent node, since `rewrite` does
311 // not replace the node passed to it.
312 .map(|it| it.parent().unwrap_or(it))
313 .fold1(|a, b| least_common_ancestor(&a, &b).unwrap())
314 }
315
316 fn replacement(&self, element: &SyntaxElement) -> Option<Replacement> {
317 if let Some(f) = &self.f {
318 assert!(self.replacements.is_empty());
319 return f(element).map(Replacement::Single);
320 }
321 self.replacements.get(element).cloned()
322 }
323
324 fn rewrite_children(&self, node: &SyntaxNode) -> SyntaxNode {
325 // FIXME: this could be made much faster.
326 let mut new_children = Vec::new();
327 for child in node.children_with_tokens() {
328 self.rewrite_self(&mut new_children, &child);
329 }
330 with_children(node, new_children)
331 }
332
333 fn rewrite_self(
334 &self,
335 acc: &mut Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
336 element: &SyntaxElement,
337 ) {
338 if let Some(replacement) = self.replacement(&element) {
339 match replacement {
340 Replacement::Single(NodeOrToken::Node(it)) => {
341 acc.push(NodeOrToken::Node(it.green().clone()))
342 }
343 Replacement::Single(NodeOrToken::Token(it)) => {
344 acc.push(NodeOrToken::Token(it.green().clone()))
345 }
346 Replacement::Many(replacements) => {
347 acc.extend(replacements.iter().map(|it| match it {
348 NodeOrToken::Node(it) => NodeOrToken::Node(it.green().clone()),
349 NodeOrToken::Token(it) => NodeOrToken::Token(it.green().clone()),
350 }))
351 }
352 Replacement::Delete => (),
353 };
354 return;
355 }
356 let res = match element {
357 NodeOrToken::Token(it) => NodeOrToken::Token(it.green().clone()),
358 NodeOrToken::Node(it) => NodeOrToken::Node(self.rewrite_children(it).green().clone()),
359 };
360 acc.push(res)
361 }
362}
363
364impl ops::AddAssign for SyntaxRewriter<'_> {
365 fn add_assign(&mut self, rhs: SyntaxRewriter) {
366 assert!(rhs.f.is_none());
367 self.replacements.extend(rhs.replacements)
368 }
369}
370
371#[derive(Clone, Debug)]
372enum Replacement {
373 Delete,
374 Single(SyntaxElement),
375 Many(Vec<SyntaxElement>),
376}
377
378fn with_children(
379 parent: &SyntaxNode,
380 new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
381) -> SyntaxNode {
382 let len = new_children.iter().map(|it| it.text_len()).sum::<TextSize>();
383 let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children);
384 let new_root_node = parent.replace_with(new_node);
385 let new_root_node = SyntaxNode::new_root(new_root_node);
386
387 // FIXME: use a more elegant way to re-fetch the node (#1185), make
388 // `range` private afterwards
389 let mut ptr = SyntaxNodePtr::new(parent);
390 ptr.range = TextRange::at(ptr.range.start(), len);
391 ptr.to_node(&new_root_node)
392}
393
394fn position_of_child(parent: &SyntaxNode, child: SyntaxElement) -> usize {
395 parent
396 .children_with_tokens()
397 .position(|it| it == child)
398 .expect("element is not a child of current element")
399}
400
401fn to_green_element(element: SyntaxElement) -> NodeOrToken<rowan::GreenNode, rowan::GreenToken> {
402 match element {
403 NodeOrToken::Node(it) => it.green().clone().into(),
404 NodeOrToken::Token(it) => it.green().clone().into(),
405 }
406}
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
deleted file mode 100644
index d536bb1e7..000000000
--- a/crates/ra_syntax/src/ast.rs
+++ /dev/null
@@ -1,331 +0,0 @@
1//! Abstract Syntax Tree, layered on top of untyped `SyntaxNode`s
2
3mod generated;
4mod traits;
5mod token_ext;
6mod node_ext;
7mod expr_ext;
8pub mod edit;
9pub mod make;
10
11use std::marker::PhantomData;
12
13use crate::{
14 syntax_node::{SyntaxNode, SyntaxNodeChildren, SyntaxToken},
15 SmolStr, SyntaxKind,
16};
17
18pub use self::{
19 expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
20 generated::*,
21 node_ext::{
22 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents,
23 StructKind, TypeBoundKind, VisibilityKind,
24 },
25 token_ext::*,
26 traits::*,
27};
28
29/// The main trait to go from untyped `SyntaxNode` to a typed ast. The
30/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
31/// the same representation: a pointer to the tree root and a pointer to the
32/// node itself.
33pub trait AstNode {
34 fn can_cast(kind: SyntaxKind) -> bool
35 where
36 Self: Sized;
37
38 fn cast(syntax: SyntaxNode) -> Option<Self>
39 where
40 Self: Sized;
41
42 fn syntax(&self) -> &SyntaxNode;
43}
44
45/// Like `AstNode`, but wraps tokens rather than interior nodes.
46pub trait AstToken {
47 fn can_cast(token: SyntaxKind) -> bool
48 where
49 Self: Sized;
50
51 fn cast(syntax: SyntaxToken) -> Option<Self>
52 where
53 Self: Sized;
54
55 fn syntax(&self) -> &SyntaxToken;
56
57 fn text(&self) -> &SmolStr {
58 self.syntax().text()
59 }
60}
61
62/// An iterator over `SyntaxNode` children of a particular AST type.
63#[derive(Debug, Clone)]
64pub struct AstChildren<N> {
65 inner: SyntaxNodeChildren,
66 ph: PhantomData<N>,
67}
68
69impl<N> AstChildren<N> {
70 fn new(parent: &SyntaxNode) -> Self {
71 AstChildren { inner: parent.children(), ph: PhantomData }
72 }
73}
74
75impl<N: AstNode> Iterator for AstChildren<N> {
76 type Item = N;
77 fn next(&mut self) -> Option<N> {
78 self.inner.find_map(N::cast)
79 }
80}
81
82mod support {
83 use super::{AstChildren, AstNode, SyntaxKind, SyntaxNode, SyntaxToken};
84
85 pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> {
86 parent.children().find_map(N::cast)
87 }
88
89 pub(super) fn children<N: AstNode>(parent: &SyntaxNode) -> AstChildren<N> {
90 AstChildren::new(parent)
91 }
92
93 pub(super) fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken> {
94 parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind)
95 }
96}
97
98#[test]
99fn assert_ast_is_object_safe() {
100 fn _f(_: &dyn AstNode, _: &dyn NameOwner) {}
101}
102
103#[test]
104fn test_doc_comment_none() {
105 let file = SourceFile::parse(
106 r#"
107 // non-doc
108 mod foo {}
109 "#,
110 )
111 .ok()
112 .unwrap();
113 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
114 assert!(module.doc_comment_text().is_none());
115}
116
117#[test]
118fn test_doc_comment_of_items() {
119 let file = SourceFile::parse(
120 r#"
121 //! doc
122 // non-doc
123 mod foo {}
124 "#,
125 )
126 .ok()
127 .unwrap();
128 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
129 assert_eq!("doc", module.doc_comment_text().unwrap());
130}
131
132#[test]
133fn test_doc_comment_of_statics() {
134 let file = SourceFile::parse(
135 r#"
136 /// Number of levels
137 static LEVELS: i32 = 0;
138 "#,
139 )
140 .ok()
141 .unwrap();
142 let st = file.syntax().descendants().find_map(Static::cast).unwrap();
143 assert_eq!("Number of levels", st.doc_comment_text().unwrap());
144}
145
146#[test]
147fn test_doc_comment_preserves_indents() {
148 let file = SourceFile::parse(
149 r#"
150 /// doc1
151 /// ```
152 /// fn foo() {
153 /// // ...
154 /// }
155 /// ```
156 mod foo {}
157 "#,
158 )
159 .ok()
160 .unwrap();
161 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
162 assert_eq!("doc1\n```\nfn foo() {\n // ...\n}\n```", module.doc_comment_text().unwrap());
163}
164
165#[test]
166fn test_doc_comment_preserves_newlines() {
167 let file = SourceFile::parse(
168 r#"
169 /// this
170 /// is
171 /// mod
172 /// foo
173 mod foo {}
174 "#,
175 )
176 .ok()
177 .unwrap();
178 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
179 assert_eq!("this\nis\nmod\nfoo", module.doc_comment_text().unwrap());
180}
181
182#[test]
183fn test_doc_comment_single_line_block_strips_suffix() {
184 let file = SourceFile::parse(
185 r#"
186 /** this is mod foo*/
187 mod foo {}
188 "#,
189 )
190 .ok()
191 .unwrap();
192 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
193 assert_eq!("this is mod foo", module.doc_comment_text().unwrap());
194}
195
196#[test]
197fn test_doc_comment_single_line_block_strips_suffix_whitespace() {
198 let file = SourceFile::parse(
199 r#"
200 /** this is mod foo */
201 mod foo {}
202 "#,
203 )
204 .ok()
205 .unwrap();
206 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
207 assert_eq!("this is mod foo ", module.doc_comment_text().unwrap());
208}
209
210#[test]
211fn test_doc_comment_multi_line_block_strips_suffix() {
212 let file = SourceFile::parse(
213 r#"
214 /**
215 this
216 is
217 mod foo
218 */
219 mod foo {}
220 "#,
221 )
222 .ok()
223 .unwrap();
224 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
225 assert_eq!(
226 " this\n is\n mod foo\n ",
227 module.doc_comment_text().unwrap()
228 );
229}
230
231#[test]
232fn test_comments_preserve_trailing_whitespace() {
233 let file = SourceFile::parse(
234 "\n/// Representation of a Realm. \n/// In the specification these are called Realm Records.\nstruct Realm {}",
235 )
236 .ok()
237 .unwrap();
238 let def = file.syntax().descendants().find_map(Struct::cast).unwrap();
239 assert_eq!(
240 "Representation of a Realm. \nIn the specification these are called Realm Records.",
241 def.doc_comment_text().unwrap()
242 );
243}
244
245#[test]
246fn test_four_slash_line_comment() {
247 let file = SourceFile::parse(
248 r#"
249 //// too many slashes to be a doc comment
250 /// doc comment
251 mod foo {}
252 "#,
253 )
254 .ok()
255 .unwrap();
256 let module = file.syntax().descendants().find_map(Module::cast).unwrap();
257 assert_eq!("doc comment", module.doc_comment_text().unwrap());
258}
259
260#[test]
261fn test_where_predicates() {
262 fn assert_bound(text: &str, bound: Option<TypeBound>) {
263 assert_eq!(text, bound.unwrap().syntax().text().to_string());
264 }
265
266 let file = SourceFile::parse(
267 r#"
268fn foo()
269where
270 T: Clone + Copy + Debug + 'static,
271 'a: 'b + 'c,
272 Iterator::Item: 'a + Debug,
273 Iterator::Item: Debug + 'a,
274 <T as Iterator>::Item: Debug + 'a,
275 for<'a> F: Fn(&'a str)
276{}
277 "#,
278 )
279 .ok()
280 .unwrap();
281 let where_clause = file.syntax().descendants().find_map(WhereClause::cast).unwrap();
282
283 let mut predicates = where_clause.predicates();
284
285 let pred = predicates.next().unwrap();
286 let mut bounds = pred.type_bound_list().unwrap().bounds();
287
288 assert!(pred.for_token().is_none());
289 assert!(pred.generic_param_list().is_none());
290 assert_eq!("T", pred.ty().unwrap().syntax().text().to_string());
291 assert_bound("Clone", bounds.next());
292 assert_bound("Copy", bounds.next());
293 assert_bound("Debug", bounds.next());
294 assert_bound("'static", bounds.next());
295
296 let pred = predicates.next().unwrap();
297 let mut bounds = pred.type_bound_list().unwrap().bounds();
298
299 assert_eq!("'a", pred.lifetime_token().unwrap().text());
300
301 assert_bound("'b", bounds.next());
302 assert_bound("'c", bounds.next());
303
304 let pred = predicates.next().unwrap();
305 let mut bounds = pred.type_bound_list().unwrap().bounds();
306
307 assert_eq!("Iterator::Item", pred.ty().unwrap().syntax().text().to_string());
308 assert_bound("'a", bounds.next());
309
310 let pred = predicates.next().unwrap();
311 let mut bounds = pred.type_bound_list().unwrap().bounds();
312
313 assert_eq!("Iterator::Item", pred.ty().unwrap().syntax().text().to_string());
314 assert_bound("Debug", bounds.next());
315 assert_bound("'a", bounds.next());
316
317 let pred = predicates.next().unwrap();
318 let mut bounds = pred.type_bound_list().unwrap().bounds();
319
320 assert_eq!("<T as Iterator>::Item", pred.ty().unwrap().syntax().text().to_string());
321 assert_bound("Debug", bounds.next());
322 assert_bound("'a", bounds.next());
323
324 let pred = predicates.next().unwrap();
325 let mut bounds = pred.type_bound_list().unwrap().bounds();
326
327 assert!(pred.for_token().is_some());
328 assert_eq!("<'a>", pred.generic_param_list().unwrap().syntax().text().to_string());
329 assert_eq!("F", pred.ty().unwrap().syntax().text().to_string());
330 assert_bound("Fn(&'a str)", bounds.next());
331}
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
deleted file mode 100644
index 5ed123f91..000000000
--- a/crates/ra_syntax/src/ast/edit.rs
+++ /dev/null
@@ -1,642 +0,0 @@
1//! This module contains functions for editing syntax trees. As the trees are
2//! immutable, all function here return a fresh copy of the tree, instead of
3//! doing an in-place modification.
4use std::{
5 fmt, iter,
6 ops::{self, RangeInclusive},
7};
8
9use arrayvec::ArrayVec;
10
11use crate::{
12 algo::{self, neighbor, SyntaxRewriter},
13 ast::{
14 self,
15 make::{self, tokens},
16 AstNode, TypeBoundsOwner,
17 },
18 AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, SyntaxKind,
19 SyntaxKind::{ATTR, COMMENT, WHITESPACE},
20 SyntaxNode, SyntaxToken, T,
21};
22
23impl ast::BinExpr {
24 #[must_use]
25 pub fn replace_op(&self, op: SyntaxKind) -> Option<ast::BinExpr> {
26 let op_node: SyntaxElement = self.op_details()?.0.into();
27 let to_insert: Option<SyntaxElement> = Some(make::token(op).into());
28 Some(self.replace_children(single_node(op_node), to_insert))
29 }
30}
31
32impl ast::Fn {
33 #[must_use]
34 pub fn with_body(&self, body: ast::BlockExpr) -> ast::Fn {
35 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
36 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() {
37 old_body.syntax().clone().into()
38 } else if let Some(semi) = self.semicolon_token() {
39 to_insert.push(make::tokens::single_space().into());
40 semi.into()
41 } else {
42 to_insert.push(make::tokens::single_space().into());
43 to_insert.push(body.syntax().clone().into());
44 return self.insert_children(InsertPosition::Last, to_insert);
45 };
46 to_insert.push(body.syntax().clone().into());
47 self.replace_children(single_node(old_body_or_semi), to_insert)
48 }
49}
50
51fn make_multiline<N>(node: N) -> N
52where
53 N: AstNode + Clone,
54{
55 let l_curly = match node.syntax().children_with_tokens().find(|it| it.kind() == T!['{']) {
56 Some(it) => it,
57 None => return node,
58 };
59 let sibling = match l_curly.next_sibling_or_token() {
60 Some(it) => it,
61 None => return node,
62 };
63 let existing_ws = match sibling.as_token() {
64 None => None,
65 Some(tok) if tok.kind() != WHITESPACE => None,
66 Some(ws) => {
67 if ws.text().contains('\n') {
68 return node;
69 }
70 Some(ws.clone())
71 }
72 };
73
74 let indent = leading_indent(node.syntax()).unwrap_or_default();
75 let ws = tokens::WsBuilder::new(&format!("\n{}", indent));
76 let to_insert = iter::once(ws.ws().into());
77 match existing_ws {
78 None => node.insert_children(InsertPosition::After(l_curly), to_insert),
79 Some(ws) => node.replace_children(single_node(ws), to_insert),
80 }
81}
82
83impl ast::AssocItemList {
84 #[must_use]
85 pub fn append_items(
86 &self,
87 items: impl IntoIterator<Item = ast::AssocItem>,
88 ) -> ast::AssocItemList {
89 let mut res = self.clone();
90 if !self.syntax().text().contains_char('\n') {
91 res = make_multiline(res);
92 }
93 items.into_iter().for_each(|it| res = res.append_item(it));
94 res
95 }
96
97 #[must_use]
98 pub fn append_item(&self, item: ast::AssocItem) -> ast::AssocItemList {
99 let (indent, position) = match self.assoc_items().last() {
100 Some(it) => (
101 leading_indent(it.syntax()).unwrap_or_default().to_string(),
102 InsertPosition::After(it.syntax().clone().into()),
103 ),
104 None => match self.l_curly_token() {
105 Some(it) => (
106 " ".to_string() + &leading_indent(self.syntax()).unwrap_or_default(),
107 InsertPosition::After(it.into()),
108 ),
109 None => return self.clone(),
110 },
111 };
112 let ws = tokens::WsBuilder::new(&format!("\n{}", indent));
113 let to_insert: ArrayVec<[SyntaxElement; 2]> =
114 [ws.ws().into(), item.syntax().clone().into()].into();
115 self.insert_children(position, to_insert)
116 }
117}
118
119impl ast::RecordExprFieldList {
120 #[must_use]
121 pub fn append_field(&self, field: &ast::RecordExprField) -> ast::RecordExprFieldList {
122 self.insert_field(InsertPosition::Last, field)
123 }
124
125 #[must_use]
126 pub fn insert_field(
127 &self,
128 position: InsertPosition<&'_ ast::RecordExprField>,
129 field: &ast::RecordExprField,
130 ) -> ast::RecordExprFieldList {
131 let is_multiline = self.syntax().text().contains_char('\n');
132 let ws;
133 let space = if is_multiline {
134 ws = tokens::WsBuilder::new(&format!(
135 "\n{} ",
136 leading_indent(self.syntax()).unwrap_or_default()
137 ));
138 ws.ws()
139 } else {
140 tokens::single_space()
141 };
142
143 let mut to_insert: ArrayVec<[SyntaxElement; 4]> = ArrayVec::new();
144 to_insert.push(space.into());
145 to_insert.push(field.syntax().clone().into());
146 to_insert.push(make::token(T![,]).into());
147
148 macro_rules! after_l_curly {
149 () => {{
150 let anchor = match self.l_curly_token() {
151 Some(it) => it.into(),
152 None => return self.clone(),
153 };
154 InsertPosition::After(anchor)
155 }};
156 }
157
158 macro_rules! after_field {
159 ($anchor:expr) => {
160 if let Some(comma) = $anchor
161 .syntax()
162 .siblings_with_tokens(Direction::Next)
163 .find(|it| it.kind() == T![,])
164 {
165 InsertPosition::After(comma)
166 } else {
167 to_insert.insert(0, make::token(T![,]).into());
168 InsertPosition::After($anchor.syntax().clone().into())
169 }
170 };
171 };
172
173 let position = match position {
174 InsertPosition::First => after_l_curly!(),
175 InsertPosition::Last => {
176 if !is_multiline {
177 // don't insert comma before curly
178 to_insert.pop();
179 }
180 match self.fields().last() {
181 Some(it) => after_field!(it),
182 None => after_l_curly!(),
183 }
184 }
185 InsertPosition::Before(anchor) => {
186 InsertPosition::Before(anchor.syntax().clone().into())
187 }
188 InsertPosition::After(anchor) => after_field!(anchor),
189 };
190
191 self.insert_children(position, to_insert)
192 }
193}
194
195impl ast::TypeAlias {
196 #[must_use]
197 pub fn remove_bounds(&self) -> ast::TypeAlias {
198 let colon = match self.colon_token() {
199 Some(it) => it,
200 None => return self.clone(),
201 };
202 let end = match self.type_bound_list() {
203 Some(it) => it.syntax().clone().into(),
204 None => colon.clone().into(),
205 };
206 self.replace_children(colon.into()..=end, iter::empty())
207 }
208}
209
210impl ast::TypeParam {
211 #[must_use]
212 pub fn remove_bounds(&self) -> ast::TypeParam {
213 let colon = match self.colon_token() {
214 Some(it) => it,
215 None => return self.clone(),
216 };
217 let end = match self.type_bound_list() {
218 Some(it) => it.syntax().clone().into(),
219 None => colon.clone().into(),
220 };
221 self.replace_children(colon.into()..=end, iter::empty())
222 }
223}
224
225impl ast::Path {
226 #[must_use]
227 pub fn with_segment(&self, segment: ast::PathSegment) -> ast::Path {
228 if let Some(old) = self.segment() {
229 return self.replace_children(
230 single_node(old.syntax().clone()),
231 iter::once(segment.syntax().clone().into()),
232 );
233 }
234 self.clone()
235 }
236}
237
238impl ast::PathSegment {
239 #[must_use]
240 pub fn with_type_args(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
241 self._with_type_args(type_args, false)
242 }
243
244 #[must_use]
245 pub fn with_turbo_fish(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
246 self._with_type_args(type_args, true)
247 }
248
249 fn _with_type_args(&self, type_args: ast::GenericArgList, turbo: bool) -> ast::PathSegment {
250 if let Some(old) = self.generic_arg_list() {
251 return self.replace_children(
252 single_node(old.syntax().clone()),
253 iter::once(type_args.syntax().clone().into()),
254 );
255 }
256 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
257 if turbo {
258 to_insert.push(make::token(T![::]).into());
259 }
260 to_insert.push(type_args.syntax().clone().into());
261 self.insert_children(InsertPosition::Last, to_insert)
262 }
263}
264
265impl ast::Use {
266 #[must_use]
267 pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use {
268 if let Some(old) = self.use_tree() {
269 return self.replace_descendant(old, use_tree);
270 }
271 self.clone()
272 }
273
274 pub fn remove(&self) -> SyntaxRewriter<'static> {
275 let mut res = SyntaxRewriter::default();
276 res.delete(self.syntax());
277 let next_ws = self
278 .syntax()
279 .next_sibling_or_token()
280 .and_then(|it| it.into_token())
281 .and_then(ast::Whitespace::cast);
282 if let Some(next_ws) = next_ws {
283 let ws_text = next_ws.syntax().text();
284 if ws_text.starts_with('\n') {
285 let rest = &ws_text[1..];
286 if rest.is_empty() {
287 res.delete(next_ws.syntax())
288 } else {
289 res.replace(next_ws.syntax(), &make::tokens::whitespace(rest));
290 }
291 }
292 }
293 res
294 }
295}
296
297impl ast::UseTree {
298 #[must_use]
299 pub fn with_path(&self, path: ast::Path) -> ast::UseTree {
300 if let Some(old) = self.path() {
301 return self.replace_descendant(old, path);
302 }
303 self.clone()
304 }
305
306 #[must_use]
307 pub fn with_use_tree_list(&self, use_tree_list: ast::UseTreeList) -> ast::UseTree {
308 if let Some(old) = self.use_tree_list() {
309 return self.replace_descendant(old, use_tree_list);
310 }
311 self.clone()
312 }
313
314 #[must_use]
315 pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree {
316 let suffix = match split_path_prefix(&prefix) {
317 Some(it) => it,
318 None => return self.clone(),
319 };
320 let use_tree = make::use_tree(
321 suffix,
322 self.use_tree_list(),
323 self.rename(),
324 self.star_token().is_some(),
325 );
326 let nested = make::use_tree_list(iter::once(use_tree));
327 return make::use_tree(prefix.clone(), Some(nested), None, false);
328
329 fn split_path_prefix(prefix: &ast::Path) -> Option<ast::Path> {
330 let parent = prefix.parent_path()?;
331 let segment = parent.segment()?;
332 if algo::has_errors(segment.syntax()) {
333 return None;
334 }
335 let mut res = make::path_unqualified(segment);
336 for p in iter::successors(parent.parent_path(), |it| it.parent_path()) {
337 res = make::path_qualified(res, p.segment()?);
338 }
339 Some(res)
340 }
341 }
342
343 pub fn remove(&self) -> SyntaxRewriter<'static> {
344 let mut res = SyntaxRewriter::default();
345 res.delete(self.syntax());
346 for &dir in [Direction::Next, Direction::Prev].iter() {
347 if let Some(nb) = neighbor(self, dir) {
348 self.syntax()
349 .siblings_with_tokens(dir)
350 .skip(1)
351 .take_while(|it| it.as_node() != Some(nb.syntax()))
352 .for_each(|el| res.delete(&el));
353 return res;
354 }
355 }
356 res
357 }
358}
359
360impl ast::MatchArmList {
361 #[must_use]
362 pub fn append_arms(&self, items: impl IntoIterator<Item = ast::MatchArm>) -> ast::MatchArmList {
363 let mut res = self.clone();
364 res = res.strip_if_only_whitespace();
365 if !res.syntax().text().contains_char('\n') {
366 res = make_multiline(res);
367 }
368 items.into_iter().for_each(|it| res = res.append_arm(it));
369 res
370 }
371
372 fn strip_if_only_whitespace(&self) -> ast::MatchArmList {
373 let mut iter = self.syntax().children_with_tokens().skip_while(|it| it.kind() != T!['{']);
374 iter.next(); // Eat the curly
375 let mut inner = iter.take_while(|it| it.kind() != T!['}']);
376 if !inner.clone().all(|it| it.kind() == WHITESPACE) {
377 return self.clone();
378 }
379 let start = match inner.next() {
380 Some(s) => s,
381 None => return self.clone(),
382 };
383 let end = match inner.last() {
384 Some(s) => s,
385 None => start.clone(),
386 };
387 self.replace_children(start..=end, &mut iter::empty())
388 }
389
390 #[must_use]
391 pub fn remove_placeholder(&self) -> ast::MatchArmList {
392 let placeholder =
393 self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::WildcardPat(_))));
394 if let Some(placeholder) = placeholder {
395 self.remove_arm(&placeholder)
396 } else {
397 self.clone()
398 }
399 }
400
401 #[must_use]
402 fn remove_arm(&self, arm: &ast::MatchArm) -> ast::MatchArmList {
403 let start = arm.syntax().clone();
404 let end = if let Some(comma) = start
405 .siblings_with_tokens(Direction::Next)
406 .skip(1)
407 .skip_while(|it| it.kind().is_trivia())
408 .next()
409 .filter(|it| it.kind() == T![,])
410 {
411 comma
412 } else {
413 start.clone().into()
414 };
415 self.replace_children(start.into()..=end, None)
416 }
417
418 #[must_use]
419 pub fn append_arm(&self, item: ast::MatchArm) -> ast::MatchArmList {
420 let r_curly = match self.syntax().children_with_tokens().find(|it| it.kind() == T!['}']) {
421 Some(t) => t,
422 None => return self.clone(),
423 };
424 let position = InsertPosition::Before(r_curly.into());
425 let arm_ws = tokens::WsBuilder::new(" ");
426 let match_indent = &leading_indent(self.syntax()).unwrap_or_default();
427 let match_ws = tokens::WsBuilder::new(&format!("\n{}", match_indent));
428 let to_insert: ArrayVec<[SyntaxElement; 3]> =
429 [arm_ws.ws().into(), item.syntax().clone().into(), match_ws.ws().into()].into();
430 self.insert_children(position, to_insert)
431 }
432}
433
434#[must_use]
435pub fn remove_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N {
436 N::cast(remove_attrs_and_docs_inner(node.syntax().clone())).unwrap()
437}
438
439fn remove_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode {
440 while let Some(start) =
441 node.children_with_tokens().find(|it| it.kind() == ATTR || it.kind() == COMMENT)
442 {
443 let end = match &start.next_sibling_or_token() {
444 Some(el) if el.kind() == WHITESPACE => el.clone(),
445 Some(_) | None => start.clone(),
446 };
447 node = algo::replace_children(&node, start..=end, &mut iter::empty());
448 }
449 node
450}
451
452#[derive(Debug, Clone, Copy)]
453pub struct IndentLevel(pub u8);
454
455impl From<u8> for IndentLevel {
456 fn from(level: u8) -> IndentLevel {
457 IndentLevel(level)
458 }
459}
460
461impl fmt::Display for IndentLevel {
462 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
463 let spaces = " ";
464 let buf;
465 let len = self.0 as usize * 4;
466 let indent = if len <= spaces.len() {
467 &spaces[..len]
468 } else {
469 buf = iter::repeat(' ').take(len).collect::<String>();
470 &buf
471 };
472 fmt::Display::fmt(indent, f)
473 }
474}
475
476impl ops::Add<u8> for IndentLevel {
477 type Output = IndentLevel;
478 fn add(self, rhs: u8) -> IndentLevel {
479 IndentLevel(self.0 + rhs)
480 }
481}
482
483impl IndentLevel {
484 pub fn from_node(node: &SyntaxNode) -> IndentLevel {
485 let first_token = match node.first_token() {
486 Some(it) => it,
487 None => return IndentLevel(0),
488 };
489 for ws in prev_tokens(first_token).filter_map(ast::Whitespace::cast) {
490 let text = ws.syntax().text();
491 if let Some(pos) = text.rfind('\n') {
492 let level = text[pos + 1..].chars().count() / 4;
493 return IndentLevel(level as u8);
494 }
495 }
496 IndentLevel(0)
497 }
498
499 /// XXX: this intentionally doesn't change the indent of the very first token.
500 /// Ie, in something like
501 /// ```
502 /// fn foo() {
503 /// 92
504 /// }
505 /// ```
506 /// if you indent the block, the `{` token would stay put.
507 fn increase_indent(self, node: SyntaxNode) -> SyntaxNode {
508 let mut rewriter = SyntaxRewriter::default();
509 node.descendants_with_tokens()
510 .filter_map(|el| el.into_token())
511 .filter_map(ast::Whitespace::cast)
512 .filter(|ws| {
513 let text = ws.syntax().text();
514 text.contains('\n')
515 })
516 .for_each(|ws| {
517 let new_ws = make::tokens::whitespace(&format!("{}{}", ws.syntax(), self,));
518 rewriter.replace(ws.syntax(), &new_ws)
519 });
520 rewriter.rewrite(&node)
521 }
522
523 fn decrease_indent(self, node: SyntaxNode) -> SyntaxNode {
524 let mut rewriter = SyntaxRewriter::default();
525 node.descendants_with_tokens()
526 .filter_map(|el| el.into_token())
527 .filter_map(ast::Whitespace::cast)
528 .filter(|ws| {
529 let text = ws.syntax().text();
530 text.contains('\n')
531 })
532 .for_each(|ws| {
533 let new_ws = make::tokens::whitespace(
534 &ws.syntax().text().replace(&format!("\n{}", self), "\n"),
535 );
536 rewriter.replace(ws.syntax(), &new_ws)
537 });
538 rewriter.rewrite(&node)
539 }
540}
541
542// FIXME: replace usages with IndentLevel above
543fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> {
544 for token in prev_tokens(node.first_token()?) {
545 if let Some(ws) = ast::Whitespace::cast(token.clone()) {
546 let ws_text = ws.text();
547 if let Some(pos) = ws_text.rfind('\n') {
548 return Some(ws_text[pos + 1..].into());
549 }
550 }
551 if token.text().contains('\n') {
552 break;
553 }
554 }
555 None
556}
557
558fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
559 iter::successors(Some(token), |token| token.prev_token())
560}
561
562pub trait AstNodeEdit: AstNode + Clone + Sized {
563 #[must_use]
564 fn insert_children(
565 &self,
566 position: InsertPosition<SyntaxElement>,
567 to_insert: impl IntoIterator<Item = SyntaxElement>,
568 ) -> Self {
569 let new_syntax = algo::insert_children(self.syntax(), position, to_insert);
570 Self::cast(new_syntax).unwrap()
571 }
572
573 #[must_use]
574 fn replace_children(
575 &self,
576 to_replace: RangeInclusive<SyntaxElement>,
577 to_insert: impl IntoIterator<Item = SyntaxElement>,
578 ) -> Self {
579 let new_syntax = algo::replace_children(self.syntax(), to_replace, to_insert);
580 Self::cast(new_syntax).unwrap()
581 }
582
583 #[must_use]
584 fn replace_descendant<D: AstNode>(&self, old: D, new: D) -> Self {
585 self.replace_descendants(iter::once((old, new)))
586 }
587
588 #[must_use]
589 fn replace_descendants<D: AstNode>(
590 &self,
591 replacement_map: impl IntoIterator<Item = (D, D)>,
592 ) -> Self {
593 let mut rewriter = SyntaxRewriter::default();
594 for (from, to) in replacement_map {
595 rewriter.replace(from.syntax(), to.syntax())
596 }
597 rewriter.rewrite_ast(self)
598 }
599 #[must_use]
600 fn indent(&self, level: IndentLevel) -> Self {
601 Self::cast(level.increase_indent(self.syntax().clone())).unwrap()
602 }
603 #[must_use]
604 fn dedent(&self, level: IndentLevel) -> Self {
605 Self::cast(level.decrease_indent(self.syntax().clone())).unwrap()
606 }
607 #[must_use]
608 fn reset_indent(&self) -> Self {
609 let level = IndentLevel::from_node(self.syntax());
610 self.dedent(level)
611 }
612}
613
614impl<N: AstNode + Clone> AstNodeEdit for N {}
615
616fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElement> {
617 let element = element.into();
618 element.clone()..=element
619}
620
621#[test]
622fn test_increase_indent() {
623 let arm_list = {
624 let arm = make::match_arm(iter::once(make::wildcard_pat().into()), make::expr_unit());
625 make::match_arm_list(vec![arm.clone(), arm])
626 };
627 assert_eq!(
628 arm_list.syntax().to_string(),
629 "{
630 _ => (),
631 _ => (),
632}"
633 );
634 let indented = arm_list.indent(IndentLevel(2));
635 assert_eq!(
636 indented.syntax().to_string(),
637 "{
638 _ => (),
639 _ => (),
640 }"
641 );
642}
diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs
deleted file mode 100644
index f5ba87223..000000000
--- a/crates/ra_syntax/src/ast/expr_ext.rs
+++ /dev/null
@@ -1,418 +0,0 @@
1//! Various extension methods to ast Expr Nodes, which are hard to code-generate.
2
3use crate::{
4 ast::{self, support, AstChildren, AstNode},
5 SmolStr,
6 SyntaxKind::*,
7 SyntaxToken, T,
8};
9
10impl ast::AttrsOwner for ast::Expr {}
11
12impl ast::Expr {
13 pub fn is_block_like(&self) -> bool {
14 match self {
15 ast::Expr::IfExpr(_)
16 | ast::Expr::LoopExpr(_)
17 | ast::Expr::ForExpr(_)
18 | ast::Expr::WhileExpr(_)
19 | ast::Expr::BlockExpr(_)
20 | ast::Expr::MatchExpr(_)
21 | ast::Expr::EffectExpr(_) => true,
22 _ => false,
23 }
24 }
25}
26
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum ElseBranch {
29 Block(ast::BlockExpr),
30 IfExpr(ast::IfExpr),
31}
32
33impl ast::IfExpr {
34 pub fn then_branch(&self) -> Option<ast::BlockExpr> {
35 self.blocks().next()
36 }
37 pub fn else_branch(&self) -> Option<ElseBranch> {
38 let res = match self.blocks().nth(1) {
39 Some(block) => ElseBranch::Block(block),
40 None => {
41 let elif: ast::IfExpr = support::child(self.syntax())?;
42 ElseBranch::IfExpr(elif)
43 }
44 };
45 Some(res)
46 }
47
48 pub fn blocks(&self) -> AstChildren<ast::BlockExpr> {
49 support::children(self.syntax())
50 }
51}
52
53#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
54pub enum PrefixOp {
55 /// The `*` operator for dereferencing
56 Deref,
57 /// The `!` operator for logical inversion
58 Not,
59 /// The `-` operator for negation
60 Neg,
61}
62
63impl ast::PrefixExpr {
64 pub fn op_kind(&self) -> Option<PrefixOp> {
65 match self.op_token()?.kind() {
66 T![*] => Some(PrefixOp::Deref),
67 T![!] => Some(PrefixOp::Not),
68 T![-] => Some(PrefixOp::Neg),
69 _ => None,
70 }
71 }
72
73 pub fn op_token(&self) -> Option<SyntaxToken> {
74 self.syntax().first_child_or_token()?.into_token()
75 }
76}
77
78#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
79pub enum BinOp {
80 /// The `||` operator for boolean OR
81 BooleanOr,
82 /// The `&&` operator for boolean AND
83 BooleanAnd,
84 /// The `==` operator for equality testing
85 EqualityTest,
86 /// The `!=` operator for equality testing
87 NegatedEqualityTest,
88 /// The `<=` operator for lesser-equal testing
89 LesserEqualTest,
90 /// The `>=` operator for greater-equal testing
91 GreaterEqualTest,
92 /// The `<` operator for comparison
93 LesserTest,
94 /// The `>` operator for comparison
95 GreaterTest,
96 /// The `+` operator for addition
97 Addition,
98 /// The `*` operator for multiplication
99 Multiplication,
100 /// The `-` operator for subtraction
101 Subtraction,
102 /// The `/` operator for division
103 Division,
104 /// The `%` operator for remainder after division
105 Remainder,
106 /// The `<<` operator for left shift
107 LeftShift,
108 /// The `>>` operator for right shift
109 RightShift,
110 /// The `^` operator for bitwise XOR
111 BitwiseXor,
112 /// The `|` operator for bitwise OR
113 BitwiseOr,
114 /// The `&` operator for bitwise AND
115 BitwiseAnd,
116 /// The `=` operator for assignment
117 Assignment,
118 /// The `+=` operator for assignment after addition
119 AddAssign,
120 /// The `/=` operator for assignment after division
121 DivAssign,
122 /// The `*=` operator for assignment after multiplication
123 MulAssign,
124 /// The `%=` operator for assignment after remainders
125 RemAssign,
126 /// The `>>=` operator for assignment after shifting right
127 ShrAssign,
128 /// The `<<=` operator for assignment after shifting left
129 ShlAssign,
130 /// The `-=` operator for assignment after subtraction
131 SubAssign,
132 /// The `|=` operator for assignment after bitwise OR
133 BitOrAssign,
134 /// The `&=` operator for assignment after bitwise AND
135 BitAndAssign,
136 /// The `^=` operator for assignment after bitwise XOR
137 BitXorAssign,
138}
139
140impl BinOp {
141 pub fn is_assignment(self) -> bool {
142 match self {
143 BinOp::Assignment
144 | BinOp::AddAssign
145 | BinOp::DivAssign
146 | BinOp::MulAssign
147 | BinOp::RemAssign
148 | BinOp::ShrAssign
149 | BinOp::ShlAssign
150 | BinOp::SubAssign
151 | BinOp::BitOrAssign
152 | BinOp::BitAndAssign
153 | BinOp::BitXorAssign => true,
154 _ => false,
155 }
156 }
157}
158
159impl ast::BinExpr {
160 pub fn op_details(&self) -> Option<(SyntaxToken, BinOp)> {
161 self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| {
162 let bin_op = match c.kind() {
163 T![||] => BinOp::BooleanOr,
164 T![&&] => BinOp::BooleanAnd,
165 T![==] => BinOp::EqualityTest,
166 T![!=] => BinOp::NegatedEqualityTest,
167 T![<=] => BinOp::LesserEqualTest,
168 T![>=] => BinOp::GreaterEqualTest,
169 T![<] => BinOp::LesserTest,
170 T![>] => BinOp::GreaterTest,
171 T![+] => BinOp::Addition,
172 T![*] => BinOp::Multiplication,
173 T![-] => BinOp::Subtraction,
174 T![/] => BinOp::Division,
175 T![%] => BinOp::Remainder,
176 T![<<] => BinOp::LeftShift,
177 T![>>] => BinOp::RightShift,
178 T![^] => BinOp::BitwiseXor,
179 T![|] => BinOp::BitwiseOr,
180 T![&] => BinOp::BitwiseAnd,
181 T![=] => BinOp::Assignment,
182 T![+=] => BinOp::AddAssign,
183 T![/=] => BinOp::DivAssign,
184 T![*=] => BinOp::MulAssign,
185 T![%=] => BinOp::RemAssign,
186 T![>>=] => BinOp::ShrAssign,
187 T![<<=] => BinOp::ShlAssign,
188 T![-=] => BinOp::SubAssign,
189 T![|=] => BinOp::BitOrAssign,
190 T![&=] => BinOp::BitAndAssign,
191 T![^=] => BinOp::BitXorAssign,
192 _ => return None,
193 };
194 Some((c, bin_op))
195 })
196 }
197
198 pub fn op_kind(&self) -> Option<BinOp> {
199 self.op_details().map(|t| t.1)
200 }
201
202 pub fn op_token(&self) -> Option<SyntaxToken> {
203 self.op_details().map(|t| t.0)
204 }
205
206 pub fn lhs(&self) -> Option<ast::Expr> {
207 support::children(self.syntax()).next()
208 }
209
210 pub fn rhs(&self) -> Option<ast::Expr> {
211 support::children(self.syntax()).nth(1)
212 }
213
214 pub fn sub_exprs(&self) -> (Option<ast::Expr>, Option<ast::Expr>) {
215 let mut children = support::children(self.syntax());
216 let first = children.next();
217 let second = children.next();
218 (first, second)
219 }
220}
221
222#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
223pub enum RangeOp {
224 /// `..`
225 Exclusive,
226 /// `..=`
227 Inclusive,
228}
229
230impl ast::RangeExpr {
231 fn op_details(&self) -> Option<(usize, SyntaxToken, RangeOp)> {
232 self.syntax().children_with_tokens().enumerate().find_map(|(ix, child)| {
233 let token = child.into_token()?;
234 let bin_op = match token.kind() {
235 T![..] => RangeOp::Exclusive,
236 T![..=] => RangeOp::Inclusive,
237 _ => return None,
238 };
239 Some((ix, token, bin_op))
240 })
241 }
242
243 pub fn op_kind(&self) -> Option<RangeOp> {
244 self.op_details().map(|t| t.2)
245 }
246
247 pub fn op_token(&self) -> Option<SyntaxToken> {
248 self.op_details().map(|t| t.1)
249 }
250
251 pub fn start(&self) -> Option<ast::Expr> {
252 let op_ix = self.op_details()?.0;
253 self.syntax()
254 .children_with_tokens()
255 .take(op_ix)
256 .find_map(|it| ast::Expr::cast(it.into_node()?))
257 }
258
259 pub fn end(&self) -> Option<ast::Expr> {
260 let op_ix = self.op_details()?.0;
261 self.syntax()
262 .children_with_tokens()
263 .skip(op_ix + 1)
264 .find_map(|it| ast::Expr::cast(it.into_node()?))
265 }
266}
267
268impl ast::IndexExpr {
269 pub fn base(&self) -> Option<ast::Expr> {
270 support::children(self.syntax()).next()
271 }
272 pub fn index(&self) -> Option<ast::Expr> {
273 support::children(self.syntax()).nth(1)
274 }
275}
276
277pub enum ArrayExprKind {
278 Repeat { initializer: Option<ast::Expr>, repeat: Option<ast::Expr> },
279 ElementList(AstChildren<ast::Expr>),
280}
281
282impl ast::ArrayExpr {
283 pub fn kind(&self) -> ArrayExprKind {
284 if self.is_repeat() {
285 ArrayExprKind::Repeat {
286 initializer: support::children(self.syntax()).next(),
287 repeat: support::children(self.syntax()).nth(1),
288 }
289 } else {
290 ArrayExprKind::ElementList(support::children(self.syntax()))
291 }
292 }
293
294 fn is_repeat(&self) -> bool {
295 self.syntax().children_with_tokens().any(|it| it.kind() == T![;])
296 }
297}
298
299#[derive(Clone, Debug, PartialEq, Eq, Hash)]
300pub enum LiteralKind {
301 String,
302 ByteString,
303 Char,
304 Byte,
305 IntNumber { suffix: Option<SmolStr> },
306 FloatNumber { suffix: Option<SmolStr> },
307 Bool(bool),
308}
309
310impl ast::Literal {
311 pub fn token(&self) -> SyntaxToken {
312 self.syntax()
313 .children_with_tokens()
314 .find(|e| e.kind() != ATTR && !e.kind().is_trivia())
315 .and_then(|e| e.into_token())
316 .unwrap()
317 }
318
319 fn find_suffix(text: &str, possible_suffixes: &[&str]) -> Option<SmolStr> {
320 possible_suffixes
321 .iter()
322 .find(|&suffix| text.ends_with(suffix))
323 .map(|&suffix| SmolStr::new(suffix))
324 }
325
326 pub fn kind(&self) -> LiteralKind {
327 const INT_SUFFIXES: [&str; 12] = [
328 "u64", "u32", "u16", "u8", "usize", "isize", "i64", "i32", "i16", "i8", "u128", "i128",
329 ];
330 const FLOAT_SUFFIXES: [&str; 2] = ["f32", "f64"];
331
332 let token = self.token();
333
334 match token.kind() {
335 INT_NUMBER => {
336 // FYI: there was a bug here previously, thus the if statement below is necessary.
337 // The lexer treats e.g. `1f64` as an integer literal. See
338 // https://github.com/rust-analyzer/rust-analyzer/issues/1592
339 // and the comments on the linked PR.
340
341 let text = token.text();
342 if let suffix @ Some(_) = Self::find_suffix(&text, &FLOAT_SUFFIXES) {
343 LiteralKind::FloatNumber { suffix }
344 } else {
345 LiteralKind::IntNumber { suffix: Self::find_suffix(&text, &INT_SUFFIXES) }
346 }
347 }
348 FLOAT_NUMBER => {
349 let text = token.text();
350 LiteralKind::FloatNumber { suffix: Self::find_suffix(&text, &FLOAT_SUFFIXES) }
351 }
352 STRING | RAW_STRING => LiteralKind::String,
353 T![true] => LiteralKind::Bool(true),
354 T![false] => LiteralKind::Bool(false),
355 BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString,
356 CHAR => LiteralKind::Char,
357 BYTE => LiteralKind::Byte,
358 _ => unreachable!(),
359 }
360 }
361}
362
363#[derive(Debug, Clone, PartialEq, Eq)]
364pub enum Effect {
365 Async(SyntaxToken),
366 Unsafe(SyntaxToken),
367 Try(SyntaxToken),
368 // Very much not an effect, but we stuff it into this node anyway
369 Label(ast::Label),
370}
371
372impl ast::EffectExpr {
373 pub fn effect(&self) -> Effect {
374 if let Some(token) = self.async_token() {
375 return Effect::Async(token);
376 }
377 if let Some(token) = self.unsafe_token() {
378 return Effect::Unsafe(token);
379 }
380 if let Some(token) = self.try_token() {
381 return Effect::Try(token);
382 }
383 if let Some(label) = self.label() {
384 return Effect::Label(label);
385 }
386 unreachable!("ast::EffectExpr without Effect")
387 }
388}
389
390impl ast::BlockExpr {
391 /// false if the block is an intrinsic part of the syntax and can't be
392 /// replaced with arbitrary expression.
393 ///
394 /// ```not_rust
395 /// fn foo() { not_stand_alone }
396 /// const FOO: () = { stand_alone };
397 /// ```
398 pub fn is_standalone(&self) -> bool {
399 let parent = match self.syntax().parent() {
400 Some(it) => it,
401 None => return true,
402 };
403 !matches!(parent.kind(), FN | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR)
404 }
405}
406
407#[test]
408fn test_literal_with_attr() {
409 let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#);
410 let lit = parse.tree().syntax().descendants().find_map(ast::Literal::cast).unwrap();
411 assert_eq!(lit.token().text(), r#""Hello""#);
412}
413
414impl ast::RecordExprField {
415 pub fn parent_record_lit(&self) -> ast::RecordExpr {
416 self.syntax().ancestors().find_map(ast::RecordExpr::cast).unwrap()
417 }
418}
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
deleted file mode 100644
index 4a6f41ee7..000000000
--- a/crates/ra_syntax/src/ast/generated.rs
+++ /dev/null
@@ -1,41 +0,0 @@
1//! This file is actually hand-written, but the submodules are indeed generated.
2#[rustfmt::skip]
3mod nodes;
4#[rustfmt::skip]
5mod tokens;
6
7use crate::{
8 AstNode,
9 SyntaxKind::{self, *},
10 SyntaxNode,
11};
12
13pub use {nodes::*, tokens::*};
14
15// Stmt is the only nested enum, so it's easier to just hand-write it
16impl AstNode for Stmt {
17 fn can_cast(kind: SyntaxKind) -> bool {
18 match kind {
19 LET_STMT | EXPR_STMT => true,
20 _ => Item::can_cast(kind),
21 }
22 }
23 fn cast(syntax: SyntaxNode) -> Option<Self> {
24 let res = match syntax.kind() {
25 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
26 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
27 _ => {
28 let item = Item::cast(syntax)?;
29 Stmt::Item(item)
30 }
31 };
32 Some(res)
33 }
34 fn syntax(&self) -> &SyntaxNode {
35 match self {
36 Stmt::LetStmt(it) => &it.syntax,
37 Stmt::ExprStmt(it) => &it.syntax,
38 Stmt::Item(it) => it.syntax(),
39 }
40 }
41}
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
deleted file mode 100644
index 3d49309d1..000000000
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ /dev/null
@@ -1,4067 +0,0 @@
1//! Generated file, do not edit by hand, see `xtask/src/codegen`
2
3use crate::{
4 ast::{self, support, AstChildren, AstNode},
5 SyntaxKind::{self, *},
6 SyntaxNode, SyntaxToken, T,
7};
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct Name {
10 pub(crate) syntax: SyntaxNode,
11}
12impl Name {
13 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
14}
15#[derive(Debug, Clone, PartialEq, Eq, Hash)]
16pub struct NameRef {
17 pub(crate) syntax: SyntaxNode,
18}
19impl NameRef {
20 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
21}
22#[derive(Debug, Clone, PartialEq, Eq, Hash)]
23pub struct Path {
24 pub(crate) syntax: SyntaxNode,
25}
26impl Path {
27 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
28 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
29 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
30}
31#[derive(Debug, Clone, PartialEq, Eq, Hash)]
32pub struct PathSegment {
33 pub(crate) syntax: SyntaxNode,
34}
35impl PathSegment {
36 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
37 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
38 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
39 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
40 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
41 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
42 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
43 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
44 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
45 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
46 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
47 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
48}
49#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub struct GenericArgList {
51 pub(crate) syntax: SyntaxNode,
52}
53impl GenericArgList {
54 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
55 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
56 pub fn generic_args(&self) -> AstChildren<GenericArg> { support::children(&self.syntax) }
57 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
58}
59#[derive(Debug, Clone, PartialEq, Eq, Hash)]
60pub struct ParamList {
61 pub(crate) syntax: SyntaxNode,
62}
63impl ParamList {
64 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
65 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
66 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
67 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
68 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
69}
70#[derive(Debug, Clone, PartialEq, Eq, Hash)]
71pub struct RetType {
72 pub(crate) syntax: SyntaxNode,
73}
74impl RetType {
75 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) }
76 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
77}
78#[derive(Debug, Clone, PartialEq, Eq, Hash)]
79pub struct PathType {
80 pub(crate) syntax: SyntaxNode,
81}
82impl PathType {
83 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
84}
85#[derive(Debug, Clone, PartialEq, Eq, Hash)]
86pub struct TypeArg {
87 pub(crate) syntax: SyntaxNode,
88}
89impl TypeArg {
90 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
91}
92#[derive(Debug, Clone, PartialEq, Eq, Hash)]
93pub struct AssocTypeArg {
94 pub(crate) syntax: SyntaxNode,
95}
96impl ast::TypeBoundsOwner for AssocTypeArg {}
97impl AssocTypeArg {
98 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
99 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
100 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
101}
102#[derive(Debug, Clone, PartialEq, Eq, Hash)]
103pub struct LifetimeArg {
104 pub(crate) syntax: SyntaxNode,
105}
106impl LifetimeArg {
107 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
108 support::token(&self.syntax, T![lifetime])
109 }
110}
111#[derive(Debug, Clone, PartialEq, Eq, Hash)]
112pub struct ConstArg {
113 pub(crate) syntax: SyntaxNode,
114}
115impl ConstArg {
116 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
117}
118#[derive(Debug, Clone, PartialEq, Eq, Hash)]
119pub struct TypeBoundList {
120 pub(crate) syntax: SyntaxNode,
121}
122impl TypeBoundList {
123 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
124}
125#[derive(Debug, Clone, PartialEq, Eq, Hash)]
126pub struct MacroCall {
127 pub(crate) syntax: SyntaxNode,
128}
129impl ast::AttrsOwner for MacroCall {}
130impl ast::NameOwner for MacroCall {}
131impl MacroCall {
132 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
133 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
134 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
135 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
136}
137#[derive(Debug, Clone, PartialEq, Eq, Hash)]
138pub struct Attr {
139 pub(crate) syntax: SyntaxNode,
140}
141impl Attr {
142 pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
143 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
144 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
145 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
146 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
147 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
148 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
149 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
150}
151#[derive(Debug, Clone, PartialEq, Eq, Hash)]
152pub struct TokenTree {
153 pub(crate) syntax: SyntaxNode,
154}
155impl TokenTree {
156 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
157 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
158 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
159 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
160 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
161 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
162}
163#[derive(Debug, Clone, PartialEq, Eq, Hash)]
164pub struct MacroItems {
165 pub(crate) syntax: SyntaxNode,
166}
167impl ast::ModuleItemOwner for MacroItems {}
168impl MacroItems {}
169#[derive(Debug, Clone, PartialEq, Eq, Hash)]
170pub struct MacroStmts {
171 pub(crate) syntax: SyntaxNode,
172}
173impl MacroStmts {
174 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
175 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
176}
177#[derive(Debug, Clone, PartialEq, Eq, Hash)]
178pub struct SourceFile {
179 pub(crate) syntax: SyntaxNode,
180}
181impl ast::AttrsOwner for SourceFile {}
182impl ast::ModuleItemOwner for SourceFile {}
183impl SourceFile {
184 pub fn shebang_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![shebang]) }
185}
186#[derive(Debug, Clone, PartialEq, Eq, Hash)]
187pub struct Const {
188 pub(crate) syntax: SyntaxNode,
189}
190impl ast::AttrsOwner for Const {}
191impl ast::NameOwner for Const {}
192impl ast::VisibilityOwner for Const {}
193impl Const {
194 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
195 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
196 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
197 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
198 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
199 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
200 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
201 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
202}
203#[derive(Debug, Clone, PartialEq, Eq, Hash)]
204pub struct Enum {
205 pub(crate) syntax: SyntaxNode,
206}
207impl ast::AttrsOwner for Enum {}
208impl ast::NameOwner for Enum {}
209impl ast::VisibilityOwner for Enum {}
210impl ast::GenericParamsOwner for Enum {}
211impl Enum {
212 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) }
213 pub fn variant_list(&self) -> Option<VariantList> { support::child(&self.syntax) }
214}
215#[derive(Debug, Clone, PartialEq, Eq, Hash)]
216pub struct ExternBlock {
217 pub(crate) syntax: SyntaxNode,
218}
219impl ast::AttrsOwner for ExternBlock {}
220impl ExternBlock {
221 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
222 pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) }
223}
224#[derive(Debug, Clone, PartialEq, Eq, Hash)]
225pub struct ExternCrate {
226 pub(crate) syntax: SyntaxNode,
227}
228impl ast::AttrsOwner for ExternCrate {}
229impl ast::VisibilityOwner for ExternCrate {}
230impl ExternCrate {
231 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
232 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
233 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
234 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
235 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
236 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
237}
238#[derive(Debug, Clone, PartialEq, Eq, Hash)]
239pub struct Fn {
240 pub(crate) syntax: SyntaxNode,
241}
242impl ast::AttrsOwner for Fn {}
243impl ast::NameOwner for Fn {}
244impl ast::VisibilityOwner for Fn {}
245impl ast::GenericParamsOwner for Fn {}
246impl Fn {
247 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
248 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
249 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
250 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
251 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
252 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
253 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
254 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
255 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
256 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
257}
258#[derive(Debug, Clone, PartialEq, Eq, Hash)]
259pub struct Impl {
260 pub(crate) syntax: SyntaxNode,
261}
262impl ast::AttrsOwner for Impl {}
263impl ast::VisibilityOwner for Impl {}
264impl ast::GenericParamsOwner for Impl {}
265impl Impl {
266 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
267 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
268 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
269 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
270 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
271 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
272 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
273}
274#[derive(Debug, Clone, PartialEq, Eq, Hash)]
275pub struct Module {
276 pub(crate) syntax: SyntaxNode,
277}
278impl ast::AttrsOwner for Module {}
279impl ast::NameOwner for Module {}
280impl ast::VisibilityOwner for Module {}
281impl Module {
282 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) }
283 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
284 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
285}
286#[derive(Debug, Clone, PartialEq, Eq, Hash)]
287pub struct Static {
288 pub(crate) syntax: SyntaxNode,
289}
290impl ast::AttrsOwner for Static {}
291impl ast::NameOwner for Static {}
292impl ast::VisibilityOwner for Static {}
293impl Static {
294 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
295 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
296 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
297 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
298 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
299 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
300 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
301}
302#[derive(Debug, Clone, PartialEq, Eq, Hash)]
303pub struct Struct {
304 pub(crate) syntax: SyntaxNode,
305}
306impl ast::AttrsOwner for Struct {}
307impl ast::NameOwner for Struct {}
308impl ast::VisibilityOwner for Struct {}
309impl ast::GenericParamsOwner for Struct {}
310impl Struct {
311 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) }
312 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
313 pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
314}
315#[derive(Debug, Clone, PartialEq, Eq, Hash)]
316pub struct Trait {
317 pub(crate) syntax: SyntaxNode,
318}
319impl ast::AttrsOwner for Trait {}
320impl ast::NameOwner for Trait {}
321impl ast::VisibilityOwner for Trait {}
322impl ast::GenericParamsOwner for Trait {}
323impl ast::TypeBoundsOwner for Trait {}
324impl Trait {
325 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
326 pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) }
327 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
328 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
329}
330#[derive(Debug, Clone, PartialEq, Eq, Hash)]
331pub struct TypeAlias {
332 pub(crate) syntax: SyntaxNode,
333}
334impl ast::AttrsOwner for TypeAlias {}
335impl ast::NameOwner for TypeAlias {}
336impl ast::VisibilityOwner for TypeAlias {}
337impl ast::GenericParamsOwner for TypeAlias {}
338impl ast::TypeBoundsOwner for TypeAlias {}
339impl TypeAlias {
340 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
341 pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) }
342 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
343 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
344 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
345}
346#[derive(Debug, Clone, PartialEq, Eq, Hash)]
347pub struct Union {
348 pub(crate) syntax: SyntaxNode,
349}
350impl ast::AttrsOwner for Union {}
351impl ast::NameOwner for Union {}
352impl ast::VisibilityOwner for Union {}
353impl ast::GenericParamsOwner for Union {}
354impl Union {
355 pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) }
356 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) }
357}
358#[derive(Debug, Clone, PartialEq, Eq, Hash)]
359pub struct Use {
360 pub(crate) syntax: SyntaxNode,
361}
362impl ast::AttrsOwner for Use {}
363impl ast::VisibilityOwner for Use {}
364impl Use {
365 pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) }
366 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) }
367 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
368}
369#[derive(Debug, Clone, PartialEq, Eq, Hash)]
370pub struct Visibility {
371 pub(crate) syntax: SyntaxNode,
372}
373impl Visibility {
374 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
375 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
376 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
377 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
378 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
379 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
380 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
381 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
382}
383#[derive(Debug, Clone, PartialEq, Eq, Hash)]
384pub struct ItemList {
385 pub(crate) syntax: SyntaxNode,
386}
387impl ast::AttrsOwner for ItemList {}
388impl ast::ModuleItemOwner for ItemList {}
389impl ItemList {
390 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
391 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
392}
393#[derive(Debug, Clone, PartialEq, Eq, Hash)]
394pub struct Rename {
395 pub(crate) syntax: SyntaxNode,
396}
397impl ast::NameOwner for Rename {}
398impl Rename {
399 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
400 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
401}
402#[derive(Debug, Clone, PartialEq, Eq, Hash)]
403pub struct UseTree {
404 pub(crate) syntax: SyntaxNode,
405}
406impl UseTree {
407 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
408 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
409 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
410 pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) }
411 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
412}
413#[derive(Debug, Clone, PartialEq, Eq, Hash)]
414pub struct UseTreeList {
415 pub(crate) syntax: SyntaxNode,
416}
417impl UseTreeList {
418 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
419 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) }
420 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
421}
422#[derive(Debug, Clone, PartialEq, Eq, Hash)]
423pub struct Abi {
424 pub(crate) syntax: SyntaxNode,
425}
426impl Abi {
427 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
428}
429#[derive(Debug, Clone, PartialEq, Eq, Hash)]
430pub struct GenericParamList {
431 pub(crate) syntax: SyntaxNode,
432}
433impl GenericParamList {
434 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
435 pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&self.syntax) }
436 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
437}
438#[derive(Debug, Clone, PartialEq, Eq, Hash)]
439pub struct WhereClause {
440 pub(crate) syntax: SyntaxNode,
441}
442impl WhereClause {
443 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) }
444 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
445}
446#[derive(Debug, Clone, PartialEq, Eq, Hash)]
447pub struct BlockExpr {
448 pub(crate) syntax: SyntaxNode,
449}
450impl ast::AttrsOwner for BlockExpr {}
451impl BlockExpr {
452 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
453 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
454 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
455 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
456}
457#[derive(Debug, Clone, PartialEq, Eq, Hash)]
458pub struct SelfParam {
459 pub(crate) syntax: SyntaxNode,
460}
461impl ast::AttrsOwner for SelfParam {}
462impl SelfParam {
463 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
464 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
465 support::token(&self.syntax, T![lifetime])
466 }
467 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
468 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
469 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
470 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
471}
472#[derive(Debug, Clone, PartialEq, Eq, Hash)]
473pub struct Param {
474 pub(crate) syntax: SyntaxNode,
475}
476impl ast::AttrsOwner for Param {}
477impl Param {
478 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
479 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
480 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
481 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
482}
483#[derive(Debug, Clone, PartialEq, Eq, Hash)]
484pub struct RecordFieldList {
485 pub(crate) syntax: SyntaxNode,
486}
487impl RecordFieldList {
488 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
489 pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) }
490 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
491}
492#[derive(Debug, Clone, PartialEq, Eq, Hash)]
493pub struct TupleFieldList {
494 pub(crate) syntax: SyntaxNode,
495}
496impl TupleFieldList {
497 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
498 pub fn fields(&self) -> AstChildren<TupleField> { support::children(&self.syntax) }
499 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
500}
501#[derive(Debug, Clone, PartialEq, Eq, Hash)]
502pub struct RecordField {
503 pub(crate) syntax: SyntaxNode,
504}
505impl ast::AttrsOwner for RecordField {}
506impl ast::NameOwner for RecordField {}
507impl ast::VisibilityOwner for RecordField {}
508impl RecordField {
509 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
510 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
511}
512#[derive(Debug, Clone, PartialEq, Eq, Hash)]
513pub struct TupleField {
514 pub(crate) syntax: SyntaxNode,
515}
516impl ast::AttrsOwner for TupleField {}
517impl ast::VisibilityOwner for TupleField {}
518impl TupleField {
519 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
520}
521#[derive(Debug, Clone, PartialEq, Eq, Hash)]
522pub struct VariantList {
523 pub(crate) syntax: SyntaxNode,
524}
525impl VariantList {
526 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
527 pub fn variants(&self) -> AstChildren<Variant> { support::children(&self.syntax) }
528 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
529}
530#[derive(Debug, Clone, PartialEq, Eq, Hash)]
531pub struct Variant {
532 pub(crate) syntax: SyntaxNode,
533}
534impl ast::AttrsOwner for Variant {}
535impl ast::NameOwner for Variant {}
536impl ast::VisibilityOwner for Variant {}
537impl Variant {
538 pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
539 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
540 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
541}
542#[derive(Debug, Clone, PartialEq, Eq, Hash)]
543pub struct AssocItemList {
544 pub(crate) syntax: SyntaxNode,
545}
546impl ast::AttrsOwner for AssocItemList {}
547impl AssocItemList {
548 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
549 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
550 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
551}
552#[derive(Debug, Clone, PartialEq, Eq, Hash)]
553pub struct ExternItemList {
554 pub(crate) syntax: SyntaxNode,
555}
556impl ast::AttrsOwner for ExternItemList {}
557impl ExternItemList {
558 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
559 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
560 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
561}
562#[derive(Debug, Clone, PartialEq, Eq, Hash)]
563pub struct ConstParam {
564 pub(crate) syntax: SyntaxNode,
565}
566impl ast::AttrsOwner for ConstParam {}
567impl ast::NameOwner for ConstParam {}
568impl ConstParam {
569 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
570 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
571 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
572 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
573 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
574}
575#[derive(Debug, Clone, PartialEq, Eq, Hash)]
576pub struct LifetimeParam {
577 pub(crate) syntax: SyntaxNode,
578}
579impl ast::AttrsOwner for LifetimeParam {}
580impl ast::TypeBoundsOwner for LifetimeParam {}
581impl LifetimeParam {
582 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
583 support::token(&self.syntax, T![lifetime])
584 }
585}
586#[derive(Debug, Clone, PartialEq, Eq, Hash)]
587pub struct TypeParam {
588 pub(crate) syntax: SyntaxNode,
589}
590impl ast::AttrsOwner for TypeParam {}
591impl ast::NameOwner for TypeParam {}
592impl ast::TypeBoundsOwner for TypeParam {}
593impl TypeParam {
594 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
595 pub fn default_type(&self) -> Option<Type> { support::child(&self.syntax) }
596}
597#[derive(Debug, Clone, PartialEq, Eq, Hash)]
598pub struct WherePred {
599 pub(crate) syntax: SyntaxNode,
600}
601impl ast::TypeBoundsOwner for WherePred {}
602impl WherePred {
603 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
604 pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
605 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
606 support::token(&self.syntax, T![lifetime])
607 }
608 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
609}
610#[derive(Debug, Clone, PartialEq, Eq, Hash)]
611pub struct Literal {
612 pub(crate) syntax: SyntaxNode,
613}
614impl ast::AttrsOwner for Literal {}
615impl Literal {}
616#[derive(Debug, Clone, PartialEq, Eq, Hash)]
617pub struct ExprStmt {
618 pub(crate) syntax: SyntaxNode,
619}
620impl ast::AttrsOwner for ExprStmt {}
621impl ExprStmt {
622 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
623 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
624}
625#[derive(Debug, Clone, PartialEq, Eq, Hash)]
626pub struct LetStmt {
627 pub(crate) syntax: SyntaxNode,
628}
629impl ast::AttrsOwner for LetStmt {}
630impl LetStmt {
631 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
632 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
633 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
634 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
635 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
636 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
637 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
638}
639#[derive(Debug, Clone, PartialEq, Eq, Hash)]
640pub struct ArrayExpr {
641 pub(crate) syntax: SyntaxNode,
642}
643impl ast::AttrsOwner for ArrayExpr {}
644impl ArrayExpr {
645 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
646 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
647 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
648 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
649 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
650}
651#[derive(Debug, Clone, PartialEq, Eq, Hash)]
652pub struct AwaitExpr {
653 pub(crate) syntax: SyntaxNode,
654}
655impl ast::AttrsOwner for AwaitExpr {}
656impl AwaitExpr {
657 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
658 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
659 pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) }
660}
661#[derive(Debug, Clone, PartialEq, Eq, Hash)]
662pub struct BinExpr {
663 pub(crate) syntax: SyntaxNode,
664}
665impl ast::AttrsOwner for BinExpr {}
666impl BinExpr {}
667#[derive(Debug, Clone, PartialEq, Eq, Hash)]
668pub struct BoxExpr {
669 pub(crate) syntax: SyntaxNode,
670}
671impl ast::AttrsOwner for BoxExpr {}
672impl BoxExpr {
673 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
674 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
675}
676#[derive(Debug, Clone, PartialEq, Eq, Hash)]
677pub struct BreakExpr {
678 pub(crate) syntax: SyntaxNode,
679}
680impl ast::AttrsOwner for BreakExpr {}
681impl BreakExpr {
682 pub fn break_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![break]) }
683 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
684 support::token(&self.syntax, T![lifetime])
685 }
686 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
687}
688#[derive(Debug, Clone, PartialEq, Eq, Hash)]
689pub struct CallExpr {
690 pub(crate) syntax: SyntaxNode,
691}
692impl ast::AttrsOwner for CallExpr {}
693impl ast::ArgListOwner for CallExpr {}
694impl CallExpr {
695 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
696}
697#[derive(Debug, Clone, PartialEq, Eq, Hash)]
698pub struct CastExpr {
699 pub(crate) syntax: SyntaxNode,
700}
701impl ast::AttrsOwner for CastExpr {}
702impl CastExpr {
703 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
704 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
705 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
706}
707#[derive(Debug, Clone, PartialEq, Eq, Hash)]
708pub struct ClosureExpr {
709 pub(crate) syntax: SyntaxNode,
710}
711impl ast::AttrsOwner for ClosureExpr {}
712impl ClosureExpr {
713 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
714 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
715 pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
716 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
717 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
718 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
719}
720#[derive(Debug, Clone, PartialEq, Eq, Hash)]
721pub struct ContinueExpr {
722 pub(crate) syntax: SyntaxNode,
723}
724impl ast::AttrsOwner for ContinueExpr {}
725impl ContinueExpr {
726 pub fn continue_token(&self) -> Option<SyntaxToken> {
727 support::token(&self.syntax, T![continue])
728 }
729 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
730 support::token(&self.syntax, T![lifetime])
731 }
732}
733#[derive(Debug, Clone, PartialEq, Eq, Hash)]
734pub struct EffectExpr {
735 pub(crate) syntax: SyntaxNode,
736}
737impl ast::AttrsOwner for EffectExpr {}
738impl EffectExpr {
739 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
740 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
741 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
742 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
743 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
744}
745#[derive(Debug, Clone, PartialEq, Eq, Hash)]
746pub struct FieldExpr {
747 pub(crate) syntax: SyntaxNode,
748}
749impl ast::AttrsOwner for FieldExpr {}
750impl FieldExpr {
751 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
752 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
753 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
754}
755#[derive(Debug, Clone, PartialEq, Eq, Hash)]
756pub struct ForExpr {
757 pub(crate) syntax: SyntaxNode,
758}
759impl ast::AttrsOwner for ForExpr {}
760impl ast::LoopBodyOwner for ForExpr {}
761impl ForExpr {
762 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
763 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
764 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
765 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) }
766}
767#[derive(Debug, Clone, PartialEq, Eq, Hash)]
768pub struct IfExpr {
769 pub(crate) syntax: SyntaxNode,
770}
771impl ast::AttrsOwner for IfExpr {}
772impl IfExpr {
773 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
774 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
775 pub fn else_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![else]) }
776}
777#[derive(Debug, Clone, PartialEq, Eq, Hash)]
778pub struct IndexExpr {
779 pub(crate) syntax: SyntaxNode,
780}
781impl ast::AttrsOwner for IndexExpr {}
782impl IndexExpr {
783 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
784 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
785}
786#[derive(Debug, Clone, PartialEq, Eq, Hash)]
787pub struct LoopExpr {
788 pub(crate) syntax: SyntaxNode,
789}
790impl ast::AttrsOwner for LoopExpr {}
791impl ast::LoopBodyOwner for LoopExpr {}
792impl LoopExpr {
793 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) }
794}
795#[derive(Debug, Clone, PartialEq, Eq, Hash)]
796pub struct MatchExpr {
797 pub(crate) syntax: SyntaxNode,
798}
799impl ast::AttrsOwner for MatchExpr {}
800impl MatchExpr {
801 pub fn match_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![match]) }
802 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
803 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) }
804}
805#[derive(Debug, Clone, PartialEq, Eq, Hash)]
806pub struct MethodCallExpr {
807 pub(crate) syntax: SyntaxNode,
808}
809impl ast::AttrsOwner for MethodCallExpr {}
810impl ast::ArgListOwner for MethodCallExpr {}
811impl MethodCallExpr {
812 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
813 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
814 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
815 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
816}
817#[derive(Debug, Clone, PartialEq, Eq, Hash)]
818pub struct ParenExpr {
819 pub(crate) syntax: SyntaxNode,
820}
821impl ast::AttrsOwner for ParenExpr {}
822impl ParenExpr {
823 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
824 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
825 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
826}
827#[derive(Debug, Clone, PartialEq, Eq, Hash)]
828pub struct PathExpr {
829 pub(crate) syntax: SyntaxNode,
830}
831impl ast::AttrsOwner for PathExpr {}
832impl PathExpr {
833 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
834}
835#[derive(Debug, Clone, PartialEq, Eq, Hash)]
836pub struct PrefixExpr {
837 pub(crate) syntax: SyntaxNode,
838}
839impl ast::AttrsOwner for PrefixExpr {}
840impl PrefixExpr {
841 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
842}
843#[derive(Debug, Clone, PartialEq, Eq, Hash)]
844pub struct RangeExpr {
845 pub(crate) syntax: SyntaxNode,
846}
847impl ast::AttrsOwner for RangeExpr {}
848impl RangeExpr {}
849#[derive(Debug, Clone, PartialEq, Eq, Hash)]
850pub struct RecordExpr {
851 pub(crate) syntax: SyntaxNode,
852}
853impl RecordExpr {
854 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
855 pub fn record_expr_field_list(&self) -> Option<RecordExprFieldList> {
856 support::child(&self.syntax)
857 }
858}
859#[derive(Debug, Clone, PartialEq, Eq, Hash)]
860pub struct RefExpr {
861 pub(crate) syntax: SyntaxNode,
862}
863impl ast::AttrsOwner for RefExpr {}
864impl RefExpr {
865 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
866 pub fn raw_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![raw]) }
867 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
868 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
869 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
870}
871#[derive(Debug, Clone, PartialEq, Eq, Hash)]
872pub struct ReturnExpr {
873 pub(crate) syntax: SyntaxNode,
874}
875impl ast::AttrsOwner for ReturnExpr {}
876impl ReturnExpr {
877 pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) }
878 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
879}
880#[derive(Debug, Clone, PartialEq, Eq, Hash)]
881pub struct TryExpr {
882 pub(crate) syntax: SyntaxNode,
883}
884impl ast::AttrsOwner for TryExpr {}
885impl TryExpr {
886 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
887 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
888}
889#[derive(Debug, Clone, PartialEq, Eq, Hash)]
890pub struct TupleExpr {
891 pub(crate) syntax: SyntaxNode,
892}
893impl ast::AttrsOwner for TupleExpr {}
894impl TupleExpr {
895 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
896 pub fn fields(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
897 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
898}
899#[derive(Debug, Clone, PartialEq, Eq, Hash)]
900pub struct WhileExpr {
901 pub(crate) syntax: SyntaxNode,
902}
903impl ast::AttrsOwner for WhileExpr {}
904impl ast::LoopBodyOwner for WhileExpr {}
905impl WhileExpr {
906 pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) }
907 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
908}
909#[derive(Debug, Clone, PartialEq, Eq, Hash)]
910pub struct Label {
911 pub(crate) syntax: SyntaxNode,
912}
913impl Label {
914 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
915 support::token(&self.syntax, T![lifetime])
916 }
917}
918#[derive(Debug, Clone, PartialEq, Eq, Hash)]
919pub struct RecordExprFieldList {
920 pub(crate) syntax: SyntaxNode,
921}
922impl ast::AttrsOwner for RecordExprFieldList {}
923impl RecordExprFieldList {
924 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
925 pub fn fields(&self) -> AstChildren<RecordExprField> { support::children(&self.syntax) }
926 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
927 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) }
928 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
929}
930#[derive(Debug, Clone, PartialEq, Eq, Hash)]
931pub struct RecordExprField {
932 pub(crate) syntax: SyntaxNode,
933}
934impl ast::AttrsOwner for RecordExprField {}
935impl RecordExprField {
936 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
937 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
938 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
939}
940#[derive(Debug, Clone, PartialEq, Eq, Hash)]
941pub struct ArgList {
942 pub(crate) syntax: SyntaxNode,
943}
944impl ArgList {
945 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
946 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
947 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
948}
949#[derive(Debug, Clone, PartialEq, Eq, Hash)]
950pub struct Condition {
951 pub(crate) syntax: SyntaxNode,
952}
953impl Condition {
954 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
955 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
956 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
957 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
958}
959#[derive(Debug, Clone, PartialEq, Eq, Hash)]
960pub struct MatchArmList {
961 pub(crate) syntax: SyntaxNode,
962}
963impl ast::AttrsOwner for MatchArmList {}
964impl MatchArmList {
965 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
966 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) }
967 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
968}
969#[derive(Debug, Clone, PartialEq, Eq, Hash)]
970pub struct MatchArm {
971 pub(crate) syntax: SyntaxNode,
972}
973impl ast::AttrsOwner for MatchArm {}
974impl MatchArm {
975 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
976 pub fn guard(&self) -> Option<MatchGuard> { support::child(&self.syntax) }
977 pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) }
978 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
979 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
980}
981#[derive(Debug, Clone, PartialEq, Eq, Hash)]
982pub struct MatchGuard {
983 pub(crate) syntax: SyntaxNode,
984}
985impl MatchGuard {
986 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
987 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
988}
989#[derive(Debug, Clone, PartialEq, Eq, Hash)]
990pub struct ArrayType {
991 pub(crate) syntax: SyntaxNode,
992}
993impl ArrayType {
994 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
995 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
996 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
997 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
998 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
999}
1000#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1001pub struct DynTraitType {
1002 pub(crate) syntax: SyntaxNode,
1003}
1004impl DynTraitType {
1005 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) }
1006 pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
1007}
1008#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1009pub struct FnPtrType {
1010 pub(crate) syntax: SyntaxNode,
1011}
1012impl FnPtrType {
1013 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1014 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
1015 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
1016 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
1017 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
1018 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
1019 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
1020}
1021#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1022pub struct ForType {
1023 pub(crate) syntax: SyntaxNode,
1024}
1025impl ForType {
1026 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
1027 pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
1028 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1029}
1030#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1031pub struct ImplTraitType {
1032 pub(crate) syntax: SyntaxNode,
1033}
1034impl ImplTraitType {
1035 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
1036 pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
1037}
1038#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1039pub struct InferType {
1040 pub(crate) syntax: SyntaxNode,
1041}
1042impl InferType {
1043 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
1044}
1045#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1046pub struct NeverType {
1047 pub(crate) syntax: SyntaxNode,
1048}
1049impl NeverType {
1050 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
1051}
1052#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1053pub struct ParenType {
1054 pub(crate) syntax: SyntaxNode,
1055}
1056impl ParenType {
1057 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1058 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1059 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1060}
1061#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1062pub struct PtrType {
1063 pub(crate) syntax: SyntaxNode,
1064}
1065impl PtrType {
1066 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
1067 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1068 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1069 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1070}
1071#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1072pub struct RefType {
1073 pub(crate) syntax: SyntaxNode,
1074}
1075impl RefType {
1076 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
1077 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1078 support::token(&self.syntax, T![lifetime])
1079 }
1080 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1081 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1082}
1083#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1084pub struct SliceType {
1085 pub(crate) syntax: SyntaxNode,
1086}
1087impl SliceType {
1088 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1089 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1090 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1091}
1092#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1093pub struct TupleType {
1094 pub(crate) syntax: SyntaxNode,
1095}
1096impl TupleType {
1097 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1098 pub fn fields(&self) -> AstChildren<Type> { support::children(&self.syntax) }
1099 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1100}
1101#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1102pub struct TypeBound {
1103 pub(crate) syntax: SyntaxNode,
1104}
1105impl TypeBound {
1106 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1107 support::token(&self.syntax, T![lifetime])
1108 }
1109 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
1110 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1111}
1112#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1113pub struct IdentPat {
1114 pub(crate) syntax: SyntaxNode,
1115}
1116impl ast::AttrsOwner for IdentPat {}
1117impl ast::NameOwner for IdentPat {}
1118impl IdentPat {
1119 pub fn ref_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ref]) }
1120 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1121 pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) }
1122 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1123}
1124#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1125pub struct BoxPat {
1126 pub(crate) syntax: SyntaxNode,
1127}
1128impl BoxPat {
1129 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
1130 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1131}
1132#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1133pub struct RestPat {
1134 pub(crate) syntax: SyntaxNode,
1135}
1136impl RestPat {
1137 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
1138}
1139#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1140pub struct LiteralPat {
1141 pub(crate) syntax: SyntaxNode,
1142}
1143impl LiteralPat {
1144 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
1145}
1146#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1147pub struct MacroPat {
1148 pub(crate) syntax: SyntaxNode,
1149}
1150impl MacroPat {
1151 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) }
1152}
1153#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1154pub struct OrPat {
1155 pub(crate) syntax: SyntaxNode,
1156}
1157impl OrPat {
1158 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1159}
1160#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1161pub struct ParenPat {
1162 pub(crate) syntax: SyntaxNode,
1163}
1164impl ParenPat {
1165 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1166 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1167 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1168}
1169#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1170pub struct PathPat {
1171 pub(crate) syntax: SyntaxNode,
1172}
1173impl PathPat {
1174 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1175}
1176#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1177pub struct WildcardPat {
1178 pub(crate) syntax: SyntaxNode,
1179}
1180impl WildcardPat {
1181 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
1182}
1183#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1184pub struct RangePat {
1185 pub(crate) syntax: SyntaxNode,
1186}
1187impl RangePat {}
1188#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1189pub struct RecordPat {
1190 pub(crate) syntax: SyntaxNode,
1191}
1192impl RecordPat {
1193 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1194 pub fn record_pat_field_list(&self) -> Option<RecordPatFieldList> {
1195 support::child(&self.syntax)
1196 }
1197}
1198#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1199pub struct RefPat {
1200 pub(crate) syntax: SyntaxNode,
1201}
1202impl RefPat {
1203 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
1204 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1205 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1206}
1207#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1208pub struct SlicePat {
1209 pub(crate) syntax: SyntaxNode,
1210}
1211impl SlicePat {
1212 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1213 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1214 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1215}
1216#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1217pub struct TuplePat {
1218 pub(crate) syntax: SyntaxNode,
1219}
1220impl TuplePat {
1221 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1222 pub fn fields(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1223 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1224}
1225#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1226pub struct TupleStructPat {
1227 pub(crate) syntax: SyntaxNode,
1228}
1229impl TupleStructPat {
1230 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1231 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1232 pub fn fields(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1233 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1234}
1235#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1236pub struct RecordPatFieldList {
1237 pub(crate) syntax: SyntaxNode,
1238}
1239impl RecordPatFieldList {
1240 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1241 pub fn fields(&self) -> AstChildren<RecordPatField> { support::children(&self.syntax) }
1242 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
1243 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1244}
1245#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1246pub struct RecordPatField {
1247 pub(crate) syntax: SyntaxNode,
1248}
1249impl ast::AttrsOwner for RecordPatField {}
1250impl RecordPatField {
1251 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1252 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1253 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1254}
1255#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1256pub enum GenericArg {
1257 TypeArg(TypeArg),
1258 AssocTypeArg(AssocTypeArg),
1259 LifetimeArg(LifetimeArg),
1260 ConstArg(ConstArg),
1261}
1262#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1263pub enum Type {
1264 ArrayType(ArrayType),
1265 DynTraitType(DynTraitType),
1266 FnPtrType(FnPtrType),
1267 ForType(ForType),
1268 ImplTraitType(ImplTraitType),
1269 InferType(InferType),
1270 NeverType(NeverType),
1271 ParenType(ParenType),
1272 PathType(PathType),
1273 PtrType(PtrType),
1274 RefType(RefType),
1275 SliceType(SliceType),
1276 TupleType(TupleType),
1277}
1278#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1279pub enum Expr {
1280 ArrayExpr(ArrayExpr),
1281 AwaitExpr(AwaitExpr),
1282 BinExpr(BinExpr),
1283 BlockExpr(BlockExpr),
1284 BoxExpr(BoxExpr),
1285 BreakExpr(BreakExpr),
1286 CallExpr(CallExpr),
1287 CastExpr(CastExpr),
1288 ClosureExpr(ClosureExpr),
1289 ContinueExpr(ContinueExpr),
1290 EffectExpr(EffectExpr),
1291 FieldExpr(FieldExpr),
1292 ForExpr(ForExpr),
1293 IfExpr(IfExpr),
1294 IndexExpr(IndexExpr),
1295 Literal(Literal),
1296 LoopExpr(LoopExpr),
1297 MacroCall(MacroCall),
1298 MatchExpr(MatchExpr),
1299 MethodCallExpr(MethodCallExpr),
1300 ParenExpr(ParenExpr),
1301 PathExpr(PathExpr),
1302 PrefixExpr(PrefixExpr),
1303 RangeExpr(RangeExpr),
1304 RecordExpr(RecordExpr),
1305 RefExpr(RefExpr),
1306 ReturnExpr(ReturnExpr),
1307 TryExpr(TryExpr),
1308 TupleExpr(TupleExpr),
1309 WhileExpr(WhileExpr),
1310}
1311#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1312pub enum Item {
1313 Const(Const),
1314 Enum(Enum),
1315 ExternBlock(ExternBlock),
1316 ExternCrate(ExternCrate),
1317 Fn(Fn),
1318 Impl(Impl),
1319 MacroCall(MacroCall),
1320 Module(Module),
1321 Static(Static),
1322 Struct(Struct),
1323 Trait(Trait),
1324 TypeAlias(TypeAlias),
1325 Union(Union),
1326 Use(Use),
1327}
1328impl ast::AttrsOwner for Item {}
1329#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1330pub enum Stmt {
1331 ExprStmt(ExprStmt),
1332 Item(Item),
1333 LetStmt(LetStmt),
1334}
1335#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1336pub enum Pat {
1337 IdentPat(IdentPat),
1338 BoxPat(BoxPat),
1339 RestPat(RestPat),
1340 LiteralPat(LiteralPat),
1341 MacroPat(MacroPat),
1342 OrPat(OrPat),
1343 ParenPat(ParenPat),
1344 PathPat(PathPat),
1345 WildcardPat(WildcardPat),
1346 RangePat(RangePat),
1347 RecordPat(RecordPat),
1348 RefPat(RefPat),
1349 SlicePat(SlicePat),
1350 TuplePat(TuplePat),
1351 TupleStructPat(TupleStructPat),
1352}
1353#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1354pub enum FieldList {
1355 RecordFieldList(RecordFieldList),
1356 TupleFieldList(TupleFieldList),
1357}
1358#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1359pub enum AdtDef {
1360 Enum(Enum),
1361 Struct(Struct),
1362 Union(Union),
1363}
1364impl ast::AttrsOwner for AdtDef {}
1365impl ast::GenericParamsOwner for AdtDef {}
1366impl ast::NameOwner for AdtDef {}
1367impl ast::VisibilityOwner for AdtDef {}
1368#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1369pub enum AssocItem {
1370 Const(Const),
1371 Fn(Fn),
1372 MacroCall(MacroCall),
1373 TypeAlias(TypeAlias),
1374}
1375impl ast::AttrsOwner for AssocItem {}
1376impl ast::NameOwner for AssocItem {}
1377#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1378pub enum ExternItem {
1379 Fn(Fn),
1380 MacroCall(MacroCall),
1381 Static(Static),
1382}
1383impl ast::AttrsOwner for ExternItem {}
1384impl ast::NameOwner for ExternItem {}
1385#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1386pub enum GenericParam {
1387 ConstParam(ConstParam),
1388 LifetimeParam(LifetimeParam),
1389 TypeParam(TypeParam),
1390}
1391impl ast::AttrsOwner for GenericParam {}
1392impl AstNode for Name {
1393 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME }
1394 fn cast(syntax: SyntaxNode) -> Option<Self> {
1395 if Self::can_cast(syntax.kind()) {
1396 Some(Self { syntax })
1397 } else {
1398 None
1399 }
1400 }
1401 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1402}
1403impl AstNode for NameRef {
1404 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF }
1405 fn cast(syntax: SyntaxNode) -> Option<Self> {
1406 if Self::can_cast(syntax.kind()) {
1407 Some(Self { syntax })
1408 } else {
1409 None
1410 }
1411 }
1412 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1413}
1414impl AstNode for Path {
1415 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH }
1416 fn cast(syntax: SyntaxNode) -> Option<Self> {
1417 if Self::can_cast(syntax.kind()) {
1418 Some(Self { syntax })
1419 } else {
1420 None
1421 }
1422 }
1423 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1424}
1425impl AstNode for PathSegment {
1426 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
1427 fn cast(syntax: SyntaxNode) -> Option<Self> {
1428 if Self::can_cast(syntax.kind()) {
1429 Some(Self { syntax })
1430 } else {
1431 None
1432 }
1433 }
1434 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1435}
1436impl AstNode for GenericArgList {
1437 fn can_cast(kind: SyntaxKind) -> bool { kind == GENERIC_ARG_LIST }
1438 fn cast(syntax: SyntaxNode) -> Option<Self> {
1439 if Self::can_cast(syntax.kind()) {
1440 Some(Self { syntax })
1441 } else {
1442 None
1443 }
1444 }
1445 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1446}
1447impl AstNode for ParamList {
1448 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
1449 fn cast(syntax: SyntaxNode) -> Option<Self> {
1450 if Self::can_cast(syntax.kind()) {
1451 Some(Self { syntax })
1452 } else {
1453 None
1454 }
1455 }
1456 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1457}
1458impl AstNode for RetType {
1459 fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE }
1460 fn cast(syntax: SyntaxNode) -> Option<Self> {
1461 if Self::can_cast(syntax.kind()) {
1462 Some(Self { syntax })
1463 } else {
1464 None
1465 }
1466 }
1467 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1468}
1469impl AstNode for PathType {
1470 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_TYPE }
1471 fn cast(syntax: SyntaxNode) -> Option<Self> {
1472 if Self::can_cast(syntax.kind()) {
1473 Some(Self { syntax })
1474 } else {
1475 None
1476 }
1477 }
1478 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1479}
1480impl AstNode for TypeArg {
1481 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG }
1482 fn cast(syntax: SyntaxNode) -> Option<Self> {
1483 if Self::can_cast(syntax.kind()) {
1484 Some(Self { syntax })
1485 } else {
1486 None
1487 }
1488 }
1489 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1490}
1491impl AstNode for AssocTypeArg {
1492 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG }
1493 fn cast(syntax: SyntaxNode) -> Option<Self> {
1494 if Self::can_cast(syntax.kind()) {
1495 Some(Self { syntax })
1496 } else {
1497 None
1498 }
1499 }
1500 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1501}
1502impl AstNode for LifetimeArg {
1503 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG }
1504 fn cast(syntax: SyntaxNode) -> Option<Self> {
1505 if Self::can_cast(syntax.kind()) {
1506 Some(Self { syntax })
1507 } else {
1508 None
1509 }
1510 }
1511 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1512}
1513impl AstNode for ConstArg {
1514 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG }
1515 fn cast(syntax: SyntaxNode) -> Option<Self> {
1516 if Self::can_cast(syntax.kind()) {
1517 Some(Self { syntax })
1518 } else {
1519 None
1520 }
1521 }
1522 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1523}
1524impl AstNode for TypeBoundList {
1525 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
1526 fn cast(syntax: SyntaxNode) -> Option<Self> {
1527 if Self::can_cast(syntax.kind()) {
1528 Some(Self { syntax })
1529 } else {
1530 None
1531 }
1532 }
1533 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1534}
1535impl AstNode for MacroCall {
1536 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL }
1537 fn cast(syntax: SyntaxNode) -> Option<Self> {
1538 if Self::can_cast(syntax.kind()) {
1539 Some(Self { syntax })
1540 } else {
1541 None
1542 }
1543 }
1544 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1545}
1546impl AstNode for Attr {
1547 fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR }
1548 fn cast(syntax: SyntaxNode) -> Option<Self> {
1549 if Self::can_cast(syntax.kind()) {
1550 Some(Self { syntax })
1551 } else {
1552 None
1553 }
1554 }
1555 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1556}
1557impl AstNode for TokenTree {
1558 fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE }
1559 fn cast(syntax: SyntaxNode) -> Option<Self> {
1560 if Self::can_cast(syntax.kind()) {
1561 Some(Self { syntax })
1562 } else {
1563 None
1564 }
1565 }
1566 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1567}
1568impl AstNode for MacroItems {
1569 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS }
1570 fn cast(syntax: SyntaxNode) -> Option<Self> {
1571 if Self::can_cast(syntax.kind()) {
1572 Some(Self { syntax })
1573 } else {
1574 None
1575 }
1576 }
1577 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1578}
1579impl AstNode for MacroStmts {
1580 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS }
1581 fn cast(syntax: SyntaxNode) -> Option<Self> {
1582 if Self::can_cast(syntax.kind()) {
1583 Some(Self { syntax })
1584 } else {
1585 None
1586 }
1587 }
1588 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1589}
1590impl AstNode for SourceFile {
1591 fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE }
1592 fn cast(syntax: SyntaxNode) -> Option<Self> {
1593 if Self::can_cast(syntax.kind()) {
1594 Some(Self { syntax })
1595 } else {