Skip to content

#[main] attribute on #[test] function does not error properly #33946

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
LeoTestard opened this issue May 29, 2016 · 1 comment
Closed

#[main] attribute on #[test] function does not error properly #33946

LeoTestard opened this issue May 29, 2016 · 1 comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)

Comments

@LeoTestard
Copy link
Contributor

LeoTestard commented May 29, 2016

On stable, it gives the expected error:

#[test] #[main] fn main() {}
error: declaration of a nonstandard #[main] function may change over time, for now a top-level `fn main()` is required (see issue #29634)

But on nightly it just says:

error: main function not found

This is because since #32846, complete feature-gate-checking is done after #[test] items are stripped. It sounds to me easy to fix, but I'm wondering if feature-gate-checking is really the right place to catch this error. After all, we do not check #[test] items for correctness, so we shouldn't feature-gate-check them either, just like #[cfg()]-guarded items. Maybe the new message is fine after all.

cc @jseyfried

@jseyfried
Copy link
Contributor

we do not check #[test] items for correctness, so we shouldn't feature-gate-check them either, just like #[cfg()]-guarded items. Maybe the new message is fine after all.

Agreed. I think #[test] should behave the same as #[cfg(test)] when we aren't testing.

@steveklabnik steveklabnik added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Jun 6, 2016
bors added a commit that referenced this issue Jun 11, 2016
Treat `#[test]` like `#[cfg(test)]` in non-test builds

This PR treats `#[test]` like `#[cfg(test)]` in non-test builds. In particular, like `#[cfg(test)]`,
 - `#[test]` nodes are stripped during `cfg` processing, and
 - `#[test]` is disallowed on non-optional expressions.

Closes #33946.
r? @nrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)
Projects
None yet
Development

No branches or pull requests

3 participants