Skip to content

Commit 991b62a

Browse files
Merge #2790
2790: Add test for macro expansion in various expressions r=edwin0cheng a=flodiebold cc @edwin0cheng Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2 parents a9ba32e + dd6ec81 commit 991b62a

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

crates/ra_hir_expand/src/db.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ fn to_fragment_kind(db: &dyn AstDatabase, macro_call_id: MacroCallId) -> Fragmen
190190
TUPLE_EXPR => FragmentKind::Expr,
191191
PAREN_EXPR => FragmentKind::Expr,
192192

193-
// FIXME: Add tests for following cases in hir_ty
194193
FOR_EXPR => FragmentKind::Expr,
195194
PATH_EXPR => FragmentKind::Expr,
196195
LAMBDA_EXPR => FragmentKind::Expr,

crates/ra_hir_ty/src/tests/macros.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,87 @@ fn main() {
135135
);
136136
}
137137

138+
#[test]
139+
fn expr_macro_expanded_in_various_places() {
140+
assert_snapshot!(
141+
infer(r#"
142+
macro_rules! spam {
143+
() => (1isize);
144+
}
145+
146+
fn spam() {
147+
spam!();
148+
(spam!());
149+
spam!().spam(spam!());
150+
for _ in spam!() {}
151+
|| spam!();
152+
while spam!() {}
153+
break spam!();
154+
return spam!();
155+
match spam!() {
156+
_ if spam!() => spam!(),
157+
}
158+
spam!()(spam!());
159+
Spam { spam: spam!() };
160+
spam!()[spam!()];
161+
await spam!();
162+
spam!() as usize;
163+
&spam!();
164+
-spam!();
165+
spam!()..spam!();
166+
spam!() + spam!();
167+
}
168+
"#),
169+
@r###"
170+
![0; 6) '1isize': isize
171+
![0; 6) '1isize': isize
172+
![0; 6) '1isize': isize
173+
![0; 6) '1isize': isize
174+
![0; 6) '1isize': isize
175+
![0; 6) '1isize': isize
176+
![0; 6) '1isize': isize
177+
![0; 6) '1isize': isize
178+
![0; 6) '1isize': isize
179+
![0; 6) '1isize': isize
180+
![0; 6) '1isize': isize
181+
![0; 6) '1isize': isize
182+
![0; 6) '1isize': isize
183+
![0; 6) '1isize': isize
184+
![0; 6) '1isize': isize
185+
![0; 6) '1isize': isize
186+
![0; 6) '1isize': isize
187+
![0; 6) '1isize': isize
188+
![0; 6) '1isize': isize
189+
![0; 6) '1isize': isize
190+
![0; 6) '1isize': isize
191+
![0; 6) '1isize': isize
192+
![0; 6) '1isize': isize
193+
![0; 6) '1isize': isize
194+
![0; 6) '1isize': isize
195+
[54; 457) '{ ...!(); }': !
196+
[88; 109) 'spam!(...am!())': {unknown}
197+
[115; 134) 'for _ ...!() {}': ()
198+
[119; 120) '_': {unknown}
199+
[132; 134) '{}': ()
200+
[139; 149) '|| spam!()': || -> isize
201+
[155; 171) 'while ...!() {}': ()
202+
[169; 171) '{}': ()
203+
[176; 189) 'break spam!()': !
204+
[195; 209) 'return spam!()': !
205+
[215; 269) 'match ... }': isize
206+
[239; 240) '_': isize
207+
[274; 290) 'spam!(...am!())': {unknown}
208+
[296; 318) 'Spam {...m!() }': {unknown}
209+
[324; 340) 'spam!(...am!()]': {unknown}
210+
[365; 381) 'spam!(... usize': usize
211+
[387; 395) '&spam!()': &isize
212+
[401; 409) '-spam!()': isize
213+
[415; 431) 'spam!(...pam!()': {unknown}
214+
[437; 454) 'spam!(...pam!()': isize
215+
"###
216+
);
217+
}
218+
138219
#[test]
139220
fn infer_type_value_macro_having_same_name() {
140221
assert_snapshot!(

0 commit comments

Comments
 (0)