Repository navigation
Test functions should work when defined inside other functions #3532
Description
Activity
I would not be wholly opposed to permitting references to items inside functions this way. It's not like they do dynamic environment capture. But I suspect there's a namespace-theoretic reason why we can't (i.e. the reason for the type/module and value namespaces to be separate still exists?)
Alternatives to that seem to me like they'd be difficult to express in AST code without some even-more-odious magic (naming by defid?) and in any case, obvious workarounds exist and this bug is entirely backwards compatible if we ever make it work. I think this is probably far-future if anything.
I'm curious what you mean by reflection-based runners. Did you want to switch the test-running strategy to do that at some point? We don't really have a bug open for crate-structure reflection. Maybe we should!
Still unimplemented, still backwards compatible, still not pressing at all.
@graydon I would like to be able to load tests via reflection, yes, but at this point the model we've got is ok so I don't feel any pressing need.
visiting for triage, email from 2013 sep 30.
nominating for milestone "far future."
de-nominated
What is the use-case for this feature? I'm curious.
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.
This issue has been moved to the RFCs repo: rust-lang/rfcs#612
- added a commit that references this issue
on May 4, 2024
This doesn't work, but I frequently want to do it
The generated code for running test functions uses paths to the tests, and it's not possible to generate a path to
test1. The test runner already breaks resolution rules to run private tests, so maybe we can break yet more.We would want to consider though how this could work with reflection-based test runners - the way we currently break visibility rules to run tests is already bad news for reflection.