Skip to content
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

More informative error messages when using #[test] or #fmt without std #1127

Closed
marijnh opened this issue Nov 4, 2011 · 11 comments
Closed
Labels
A-frontend Area: frontend (errors, parsing and HIR) A-testsuite Area: The testsuite used to check the correctness of rustc

Comments

@marijnh
Copy link
Contributor

marijnh commented Nov 4, 2011

Currently, you'll get an unexplained

error: unresolved modulename: std

Which is bound to confuse people.

@marijnh
Copy link
Contributor Author

marijnh commented Nov 4, 2011

Maybe we should automagically link in std when compiling with --test.

@brson
Copy link
Contributor

brson commented Nov 4, 2011

I was hoping for the syntax extension plugin system to materialize and offer a way to declare runtime dependencies, but maybe we should just hack something up for 0.1. It's a common error.

@graydon
Copy link
Contributor

graydon commented Mar 11, 2012

Both are in core now. I think this is obsolete.

@graydon graydon closed this as completed Mar 11, 2012
@brson
Copy link
Contributor

brson commented Mar 12, 2012

The test runner is still in std, so I think this is still a problem.

@brson brson reopened this Mar 12, 2012
@catamorphism
Copy link
Contributor

Is this fixed? #1448 suggests it is, but @brson 's comment from a month ago post-dates #1448 being closed.

@ghost ghost assigned brson Apr 12, 2012
@brson
Copy link
Contributor

brson commented Apr 12, 2012

Not fixed. This still happens when compiling tests for crates that don't use std.

@killerswan
Copy link
Contributor

Yeah, this confused me.

@nejucomo
Copy link

There are three issues here, which this log shows:

$ cat ./test_compile_error_example.rs
fn inc_int(x: int) -> int { x + 1 }


#[test]
fn test_inc_int() {
  assert (inc_int(3) == 4);
}

$ rustc --test ./test_compile_error_example.rs
./test_compile_error_example.rs:1:0: 1:0 error: unresolved name
./test_compile_error_example.rs:1 fn inc_int(x: int) -> int { x + 1 }
                                  ^
./test_compile_error_example.rs:1:0: 1:0 error: use of undeclared module `std::test`
./test_compile_error_example.rs:1 fn inc_int(x: int) -> int { x + 1 }
                                  ^
./test_compile_error_example.rs:1:0: 1:0 error: unresolved name: std::test::test_main
./test_compile_error_example.rs:1 fn inc_int(x: int) -> int { x + 1 }
                                  ^
./test_compile_error_example.rs:1:0: 1:0 error: unresolved name
./test_compile_error_example.rs:1 fn inc_int(x: int) -> int { x + 1 }
                                  ^
./test_compile_error_example.rs:1:0: 1:0 error: use of undeclared module `std::test`
./test_compile_error_example.rs:1 fn inc_int(x: int) -> int { x + 1 }
                                  ^
./test_compile_error_example.rs:1:0: 1:0 error: use of undeclared type name `std::test::test_desc`
./test_compile_error_example.rs:1 fn inc_int(x: int) -> int { x + 1 }
                                  ^
error: aborting due to 6 previous errors
  1. The tutorial doesn't mention the need for "use std" when passing --test, so there is a doc bug.
  2. The location of the errors is confusing. Shouldn't the location be where the #[test] annotation is found? In this example, that's line 3, not line 1. (Related to Issue Macro errors are reported at def, not use #1448 ?)
  3. There are two errors which seem unrelated to "std::test", the first and the fourth. Which name is unresolved?

Should we file separate tickets for these three cases? Is 2 here a duplicate of #1448 or is it a distinct bug?

Is there any way to make the errors in 3 more clear? If so, is it a general problem and fix that should be a separate github issue?

@nejucomo
Copy link

I added a distinct ticket about making the tutorial more explicit: #3241

@nejucomo
Copy link

I added a separate ticket about the first and fourth error messages which are "unresolved name", because it's not clear which name is unresolved: #3242

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

Compiling with --test now automatically links to std.

@brson brson closed this as completed Jan 8, 2013
bjorn3 added a commit to bjorn3/rust that referenced this issue Feb 1, 2021
Support building with the new Cranelift backends
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: frontend (errors, parsing and HIR) A-testsuite Area: The testsuite used to check the correctness of rustc
Projects
None yet
Development

No branches or pull requests

6 participants