Skip to content

Commit 0beec90

Browse files
Add test for tuple struct destructuring assignment where the path comes from a macro
1 parent 2d4d6b6 commit 0beec90

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

crates/hir-def/src/body/tests.rs

+34
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,37 @@ fn f(a: i32, b: u32) -> String {
370370
}"#]]
371371
.assert_eq(&body.pretty_print(&db, def, Edition::CURRENT))
372372
}
373+
374+
#[test]
375+
fn destructuring_assignment_tuple_macro() {
376+
// This is a funny one. `let m!()() = Bar()` is an error in rustc, because `m!()()` isn't a valid pattern,
377+
// but in destructuring assignment it is valid, because `m!()()` is a valid expression, and destructuring
378+
// assignments start their lives as expressions. So we have to do the same.
379+
380+
let (db, body, def) = lower(
381+
r#"
382+
struct Bar();
383+
384+
macro_rules! m {
385+
() => { Bar };
386+
}
387+
388+
fn foo() {
389+
m!()() = Bar();
390+
}
391+
"#,
392+
);
393+
394+
let (_, source_map) = db.body_with_source_map(def);
395+
assert_eq!(source_map.diagnostics(), &[]);
396+
397+
for (_, def_map) in body.blocks(&db) {
398+
assert_eq!(def_map.diagnostics(), &[]);
399+
}
400+
401+
expect![[r#"
402+
fn foo() -> () {
403+
Bar() = Bar();
404+
}"#]]
405+
.assert_eq(&body.pretty_print(&db, def, Edition::CURRENT))
406+
}

0 commit comments

Comments
 (0)