aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar/items
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-04 14:06:00 +0000
committerAleksey Kladov <[email protected]>2018-02-04 14:06:07 +0000
commitc119e8fd8b0106bb2e031e76ac1be89bd10a0674 (patch)
tree3badb041e7a5551f54fe2b31868d99bb158eed10 /src/parser/grammar/items
parent85c42fba1291f1cc41fb7bfec63117895b394fc5 (diff)
G: unsafe fn
Diffstat (limited to 'src/parser/grammar/items')
-rw-r--r--src/parser/grammar/items/mod.rs92
1 files changed, 64 insertions, 28 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs
index 4afe2e418..588fca4c6 100644
--- a/src/parser/grammar/items/mod.rs
+++ b/src/parser/grammar/items/mod.rs
@@ -81,38 +81,74 @@ fn item(p: &mut Parser) {
81 CONST_ITEM 81 CONST_ITEM
82 } 82 }
83 }, 83 },
84 // test unsafe_trait 84 UNSAFE_KW => {
85 // unsafe trait T {}
86 UNSAFE_KW if la == TRAIT_KW => {
87 p.bump(); 85 p.bump();
88 traits::trait_item(p); 86 let la = p.nth(1);
89 TRAIT_ITEM 87 match p.current() {
90 } 88 // test unsafe_trait
89 // unsafe trait T {}
90 TRAIT_KW => {
91 traits::trait_item(p);
92 TRAIT_ITEM
93 }
91 94
92 // test unsafe_auto_trait 95 // test unsafe_auto_trait
93 // unsafe auto trait T {} 96 // unsafe auto trait T {}
94 UNSAFE_KW if p.at_kw(1, "auto") && p.nth(2) == TRAIT_KW => { 97 IDENT if p.at_kw("auto") && la == TRAIT_KW => {
95 p.bump(); 98 p.bump_remap(AUTO_KW);
96 p.bump_remap(AUTO_KW); 99 traits::trait_item(p);
97 traits::trait_item(p); 100 TRAIT_ITEM
98 TRAIT_ITEM 101 }
99 }
100 102
101 // test unsafe_impl 103 // test unsafe_impl
102 // unsafe impl Foo {} 104 // unsafe impl Foo {}
103 UNSAFE_KW if la == IMPL_KW => { 105 IMPL_KW => {
104 p.bump(); 106 traits::impl_item(p);
105 traits::impl_item(p); 107 IMPL_ITEM
106 IMPL_ITEM 108 }
107 }
108 109
109 // test unsafe_default_impl 110 // test unsafe_default_impl
110 // unsafe default impl Foo {} 111 // unsafe default impl Foo {}
111 UNSAFE_KW if p.at_kw(1, "default") && p.nth(2) == IMPL_KW => { 112 IDENT if p.at_kw("default") && la == IMPL_KW => {
112 p.bump(); 113 p.bump_remap(DEFAULT_KW);
113 p.bump_remap(DEFAULT_KW); 114 traits::impl_item(p);
114 traits::impl_item(p); 115 IMPL_ITEM
115 IMPL_ITEM 116 }
117
118 // test unsafe_extern_fn
119 // unsafe extern "C" fn foo() {}
120 EXTERN_KW => {
121 abi(p);
122 if !p.at(FN_KW) {
123 item.abandon(p);
124 p.error().message("expected function").emit();
125 return
126 }
127 fn_item(p);
128 FN_ITEM
129 }
130
131 // test unsafe_fn
132 // unsafe fn foo() {}
133 FN_KW => {
134 fn_item(p);
135 FN_ITEM
136 }
137
138 t => {
139 item.abandon(p);
140 let message = "expected `trait`, `impl` or `fn`";
141
142 // test unsafe_block_in_mod
143 // fn foo(){} unsafe { } fn bar(){}
144 if t == L_CURLY {
145 error_block(p, message);
146 } else {
147 p.error().message(message).emit();
148 }
149 return;
150 }
151 }
116 } 152 }
117 153
118 MOD_KW => { 154 MOD_KW => {