Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/tests/body.rs')
-rw-r--r--crates/hir-def/src/expr_store/tests/body.rs133
1 files changed, 101 insertions, 32 deletions
diff --git a/crates/hir-def/src/expr_store/tests/body.rs b/crates/hir-def/src/expr_store/tests/body.rs
index c31428be28..504c310684 100644
--- a/crates/hir-def/src/expr_store/tests/body.rs
+++ b/crates/hir-def/src/expr_store/tests/body.rs
@@ -32,14 +32,14 @@ fn def_map_at(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
let (db, position) = TestDB::with_position(ra_fixture);
let module = db.module_at_position(position);
- module.def_map(&db).dump(&db)
+ salsa::plumbing::attach(&db, || module.def_map(&db).dump(&db))
}
fn check_block_scopes_at(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (db, position) = TestDB::with_position(ra_fixture);
let module = db.module_at_position(position);
- let actual = module.def_map(&db).dump_block_scopes(&db);
+ let actual = salsa::plumbing::attach(&db, || format!("{module:#?}"));
expect.assert_eq(&actual);
}
@@ -159,11 +159,11 @@ fn main() {
expect![[r#"
fn main() {
match builtin#lang(into_iter)(
- (0) ..(10) ,
+ 0..10,
) {
- mut <ra@gennew>11 => loop {
+ mut <ra@gennew>0 => loop {
match builtin#lang(next)(
- &mut <ra@gennew>11,
+ &mut <ra@gennew>0,
) {
builtin#lang(None) => break,
builtin#lang(Some)(ident) => {
@@ -261,10 +261,10 @@ fn main() {
}
#[test]
-fn desugar_builtin_format_args() {
+fn desugar_builtin_format_args_before_1_93_0() {
let (db, body, def) = lower(
r#"
-//- minicore: fmt
+//- minicore: fmt_before_1_93_0
fn main() {
let are = "are";
let count = 10;
@@ -278,16 +278,16 @@ fn main() {
let are = "are";
let count = 10;
{
- let args = (&"fancy", &(), &"!", &count, &are, );
- let args = [
+ let <ra@gennew>0 = (&"fancy", &(), &"!", &count, &are, );
+ let <ra@gennew>0 = [
builtin#lang(Argument::new_display)(
- args.3,
+ <ra@gennew>0.3,
), builtin#lang(Argument::new_display)(
- args.0,
+ <ra@gennew>0.0,
), builtin#lang(Argument::new_debug)(
- args.4,
+ <ra@gennew>0.4,
), builtin#lang(Argument::new_display)(
- args.2,
+ <ra@gennew>0.2,
),
];
unsafe {
@@ -295,7 +295,7 @@ fn main() {
&[
"\u{1b}hello ", " ", " friends, we ", " ", "",
],
- &args,
+ &<ra@gennew>0,
&[
builtin#lang(Placeholder::new)(
0usize,
@@ -344,6 +344,59 @@ fn main() {
}
#[test]
+fn desugar_builtin_format_args() {
+ let (db, body, def) = lower(
+ r#"
+//- minicore: fmt
+fn main() {
+ let are = "are";
+ let count = 10;
+ builtin#format_args("\u{1b}hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", orphan = (), last = "!");
+ builtin#format_args("hello world");
+ builtin#format_args("hello world", orphan = ());
+}
+"#,
+ );
+
+ expect![[r#"
+ fn main() {
+ let are = "are";
+ let count = 10;
+ {
+ let <ra@gennew>0 = (&"fancy", &(), &"!", &count, &are, );
+ let <ra@gennew>0 = [
+ builtin#lang(Argument::new_display)(
+ <ra@gennew>0.3,
+ ), builtin#lang(Argument::new_display)(
+ <ra@gennew>0.0,
+ ), builtin#lang(Argument::new_debug)(
+ <ra@gennew>0.4,
+ ), builtin#lang(Argument::new_display)(
+ <ra@gennew>0.2,
+ ),
+ ];
+ ();
+ unsafe {
+ builtin#lang(Arguments::new)(
+ "\x07\x1bhello \xc3 \x00\x00i\x02\x00\x01 \xc0\r friends, we \xc0\x01 \xc8\x01\x00\xc8\x03\x00\x00",
+ &<ra@gennew>0,
+ )
+ }
+ };
+ builtin#lang(Arguments::from_str)(
+ "hello world",
+ );
+ {
+ ();
+ builtin#lang(Arguments::from_str)(
+ "hello world",
+ )
+ };
+ }"#]]
+ .assert_eq(&body.pretty_print(&db, def, Edition::CURRENT))
+}
+
+#[test]
fn test_macro_hygiene() {
let (db, body, def) = lower(
r##"
@@ -382,27 +435,16 @@ impl SsrError {
fn main() {
_ = ra_test_fixture::error::SsrError::new(
{
- let args = [
+ let <ra@gennew>0 = (&node.text(), );
+ let <ra@gennew>0 = [
builtin#lang(Argument::new_display)(
- &node.text(),
+ <ra@gennew>0.0,
),
];
unsafe {
- builtin#lang(Arguments::new_v1_formatted)(
- &[
- "Failed to resolve path `", "`",
- ],
- &args,
- &[
- builtin#lang(Placeholder::new)(
- 0usize,
- ' ',
- builtin#lang(Alignment::Unknown),
- 0u32,
- builtin#lang(Count::Implied),
- builtin#lang(Count::Implied),
- ),
- ],
+ builtin#lang(Arguments::new)(
+ "\x18Failed to resolve path `\xc0\x01`\x00",
+ &<ra@gennew>0,
)
}
},
@@ -580,7 +622,7 @@ const fn f(x: i32) -> i32 {
let MatchArm { pat, .. } = mtch_arms[1];
match body[pat] {
- Pat::Range { start, end } => {
+ Pat::Range { start, end, range_type: _ } => {
let hir_start = &body[start.unwrap()];
let hir_end = &body[end.unwrap()];
@@ -590,3 +632,30 @@ const fn f(x: i32) -> i32 {
_ => {}
}
}
+
+#[test]
+fn print_hir_precedences() {
+ let (db, body, def) = lower(
+ r#"
+fn main() {
+ _ = &(1 - (2 - 3) + 4 * 5 * (6 + 7));
+ _ = 1 + 2 < 3 && true && 4 < 5 && (a || b || c) || d && e;
+ if let _ = 2 && true && let _ = 3 {}
+ break a && b || (return) || (return 2);
+ let r = &2;
+ let _ = &mut (*r as i32)
+}
+"#,
+ );
+
+ expect![[r#"
+ fn main() {
+ _ = &((1 - (2 - 3)) + (4 * 5) * (6 + 7));
+ _ = 1 + 2 < 3 && true && 4 < 5 && (a || b || c) || d && e;
+ if let _ = 2 && true && let _ = 3 {}
+ break a && b || (return) || (return 2);
+ let r = &2;
+ let _ = &mut (*r as i32);
+ }"#]]
+ .assert_eq(&body.pretty_print(&db, def, Edition::CURRENT))
+}