Skip to content

Include name in "unresolved name" error messages. #3242

Closed
@nejucomo

Description

@nejucomo

As commented in #1127 here: #1127 (comment) there are two confusing error messages when compiling with --test without "use std":

$ 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

The first and fourth error message are quite ambiguous. Both say this:

./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 }
                                  ^

Which name is unresolved? All identifiers in the given text are either declared ("inc_int" and "x") or should be in scope ("int" and "x").

This issue would be fixed by including the name in the error message which is unresolvable.

Note that even this fix may still yield confusing error messages due to other issues, such as #1448 or #1127, but this issue is distinct and should be separately addressed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions