Skip to content

#[test] attributes in modules defined in functions are ignored #19694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kimundi opened this issue Dec 10, 2014 · 5 comments
Closed

#[test] attributes in modules defined in functions are ignored #19694

Kimundi opened this issue Dec 10, 2014 · 5 comments
Labels
A-syntaxext Area: Syntax extensions

Comments

@Kimundi
Copy link
Member

Kimundi commented Dec 10, 2014

pub fn foo() {
    mod bar {
        #[test]
        fn test2() {}
    }
}

#[test]
fn test1() {}
nested_test_bug.rs:4:9: 4:22 warning: function is never used: `test2`, #[warn(dead_code)] on by default
nested_test_bug.rs:4         fn test2() {}
                             ^~~~~~~~~~~~~
nested_test_bug.rs:3:9: 3:16 warning: unused attribute, #[warn(unused_attributes)] on by default
nested_test_bug.rs:3         #[test]
                             ^~~~~~~

I'm not sure if this is a bug or intended behavior, but if its the latter, the compiler messages should probably explain it somehow.

@lambda-fairy
Copy link
Contributor

The relevant code is in libsyntax/test.rs:

// We don't want to recurse into anything other than mods, since
// mods or tests inside of functions will break things
let res = match i.node {
    ast::ItemMod(..) => fold::noop_fold_item(i, self),
    _ => SmallVector::one(i),
};

I'm not sure what things it'll break, though. @sfackler do you know anything about this?

@sfackler
Copy link
Member

There's no way for anything outside of the function to access test2, which includes the thing running the tests.

@lambda-fairy
Copy link
Contributor

That makes sense.

Should test2 cause a compile error then? Annotating non-functions with #[test] yields an error already (error: only functions may be used as tests) so there's some precedent here.

@sfackler
Copy link
Member

That seems reasonable.

On Thu, Dec 11, 2014, 1:18 AM Chris Wong [email protected] wrote:

That makes sense.

Should test2 cause a compile error then? Annotating non-functions with
#[test] yields an error already (error: only functions may be used as
tests) so there's some precedent here.


Reply to this email directly or view it on GitHub
#19694 (comment).

@steveklabnik
Copy link
Member

Closing in favor of rust-lang/rfcs#612

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

5 participants