mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
fix: Reimplement mapping out of test/bench attributes for runnables
This commit is contained in:
parent
73668334f0
commit
d2513deb62
2 changed files with 17 additions and 2 deletions
|
@ -236,7 +236,9 @@ fn find_related_tests(
|
|||
.filter_map(|token| token.ancestors().find_map(ast::Fn::cast))
|
||||
.map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f));
|
||||
|
||||
for InFile { value: ref fn_def, .. } in functions {
|
||||
for fn_def in functions {
|
||||
// #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
|
||||
let InFile { value: fn_def, .. } = &fn_def.map_out_of_test_attr(sema.db);
|
||||
if let Some(runnable) = as_test_runnable(sema, fn_def) {
|
||||
// direct test
|
||||
tests.insert(runnable);
|
||||
|
@ -292,7 +294,8 @@ fn parent_test_module(sema: &Semantics<RootDatabase>, fn_def: &ast::Fn) -> Optio
|
|||
}
|
||||
|
||||
pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) -> Option<Runnable> {
|
||||
let func = def.source(sema.db)?;
|
||||
// #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
|
||||
let func = def.source(sema.db)?.map_out_of_test_attr(sema.db);
|
||||
let name_string = def.name(sema.db).to_string();
|
||||
|
||||
let root = def.module(sema.db).krate().root_module(sema.db);
|
||||
|
@ -501,6 +504,8 @@ fn has_test_function_or_multiple_test_submodules(
|
|||
match item {
|
||||
hir::ModuleDef::Function(f) => {
|
||||
if let Some(it) = f.source(sema.db) {
|
||||
// #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
|
||||
let it = it.map_out_of_test_attr(sema.db);
|
||||
if test_related_attribute(&it.value).is_some() {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue