Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ad434fc

Browse files
committed
Auto merge of rust-lang#15157 - HKalbasi:tokio-test, r=HKalbasi
Fix runnable detection for `#[tokio::test]` fix rust-lang#15141 It is hacky, and it wouldn't work for e.g. this case: ```Rust use ::core::prelude; #[prelude::v1::test] fn foo() { } ``` But it works for the tokio case. We should use the name resolution here somehow, and after that we should probably also get rid of the ast based `test_related_attribute` function.
2 parents 38dd674 + 7901538 commit ad434fc

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

crates/hir-def/src/attr.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ impl Attrs {
273273
}
274274

275275
pub fn is_test(&self) -> bool {
276-
self.by_key("test").exists()
276+
self.iter().any(|x| {
277+
x.path()
278+
.segments()
279+
.iter()
280+
.rev()
281+
.zip(["core", "prelude", "v1", "test"].iter().rev())
282+
.all(|x| x.0.as_str() == Some(x.1))
283+
})
277284
}
278285

279286
pub fn is_ignore(&self) -> bool {

crates/ide/src/runnables.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ fn main() {}
589589
#[test]
590590
fn test_foo() {}
591591
592+
#[::core::prelude::v1::test]
593+
fn test_full_path() {}
594+
592595
#[test]
593596
#[ignore]
594597
fn test_foo() {}
@@ -600,7 +603,7 @@ mod not_a_root {
600603
fn main() {}
601604
}
602605
"#,
603-
&[TestMod, Bin, Test, Test, Bench],
606+
&[TestMod, Bin, Test, Test, Test, Bench],
604607
expect![[r#"
605608
[
606609
Runnable {
@@ -609,7 +612,7 @@ mod not_a_root {
609612
file_id: FileId(
610613
0,
611614
),
612-
full_range: 0..137,
615+
full_range: 0..190,
613616
name: "",
614617
kind: Module,
615618
},
@@ -659,8 +662,29 @@ mod not_a_root {
659662
file_id: FileId(
660663
0,
661664
),
662-
full_range: 41..75,
663-
focus_range: 62..70,
665+
full_range: 41..92,
666+
focus_range: 73..87,
667+
name: "test_full_path",
668+
kind: Function,
669+
},
670+
kind: Test {
671+
test_id: Path(
672+
"test_full_path",
673+
),
674+
attr: TestAttr {
675+
ignore: false,
676+
},
677+
},
678+
cfg: None,
679+
},
680+
Runnable {
681+
use_name_in_title: false,
682+
nav: NavigationTarget {
683+
file_id: FileId(
684+
0,
685+
),
686+
full_range: 94..128,
687+
focus_range: 115..123,
664688
name: "test_foo",
665689
kind: Function,
666690
},
@@ -680,8 +704,8 @@ mod not_a_root {
680704
file_id: FileId(
681705
0,
682706
),
683-
full_range: 77..99,
684-
focus_range: 89..94,
707+
full_range: 130..152,
708+
focus_range: 142..147,
685709
name: "bench",
686710
kind: Function,
687711
},

0 commit comments

Comments
 (0)