Static rustc_lint_defs::builtin::UNNAMEABLE_TEST_ITEMS

source ·
Expand description

The unnameable_test_items lint detects #[test] functions that are not able to be run by the test harness because they are in a position where they are not nameable.


fn main() {
    fn foo() {
        // This test will not fail because it does not run.
        assert_eq!(1, 2);



In order for the test harness to run a test, the test function must be located in a position where it can be accessed from the crate root. This generally means it must be defined in a module, and not anywhere else such as inside another function. The compiler previously allowed this without an error, so a lint was added as an alert that a test is not being used. Whether or not this should be allowed has not yet been decided, see RFC 2471 and issue #36629.