Skip to content

Be more explicit about #[test] dependency on std. #3241

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
nejucomo opened this issue Aug 21, 2012 · 2 comments
Closed

Be more explicit about #[test] dependency on std. #3241

nejucomo opened this issue Aug 21, 2012 · 2 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Milestone

Comments

@nejucomo
Copy link

Another ticket, issue #1127 describes how dropping the std import will give confusing error messages when compiling with --test. In addition to improving those error messages, the tutorial should be very clear about this need.

The example already includes std:

use std;

fn twice(x: int) -> int { x + x }

#[test]
fn test_twice() {
    let mut i = -100;
    while i < 100 {
        assert twice(i) == 2 * i;
        i += 1;
    }
}

However the surrounding text does not emphasize that "use std" is necessary for tests. A complementary fix (and quicker) to #1127 is to simple change the sentence preceding the code snippet to something like this:

"Tests can be interspersed with other code, and annotated with the #[test] attribute. The #[test] attribute requires std to be in scope, so "use std" is required for compiling test code."

@steveklabnik
Copy link
Member

Yep, as a newbie to Rust, I ran into this pretty hard too.

brson added a commit to brson/rust that referenced this issue Dec 28, 2012
brson added a commit that referenced this issue Jan 8, 2013
@brson
Copy link
Contributor

brson commented Jan 8, 2013

use std is no longer necessary for tests. --test will link std automatically.

@brson brson closed this as completed Jan 8, 2013
RalfJung pushed a commit to RalfJung/rust that referenced this issue Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

3 participants