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

Test functions with a lifetime parameter that return Results produce incorrect error message #55228

Open
sanmai-NL opened this issue Oct 20, 2018 · 0 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-libtest Area: #[test] related C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sanmai-NL
Copy link

This works:

#[test]
fn unit_1() -> Result<(), &'static str>
{
}

But this doesn’t:

#[test]
fn unit_1<'a>() -> Result<(), &'a str>
{
}
error: functions used as tests must have signature fn() -> ()
   --> crate/test.rs:162:5
    |
162 | /     fn unit_1<'a>() -> Result<(), &'a str>

Meta

rustc 1.31.0-nightly (46880f41b 2018-10-15)
binary: rustc
commit-hash: 46880f41b7aeb897b8245474196bba9dc11f0e88
commit-date: 2018-10-15
host: x86_64-unknown-linux-gnu
release: 1.31.0-nightly
LLVM version: 8.0
@zackmdavis zackmdavis added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 20, 2018
@estebank estebank added A-libtest Area: #[test] related D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 18, 2019
@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
@zackmdavis zackmdavis self-assigned this Jan 11, 2021
zackmdavis added a commit to zackmdavis/rust that referenced this issue Jan 17, 2021
Sander Maijers reports that #[test] functions that return a `Result`
with a named lifetime fail to compile with a "functions used as tests
must have signature fn() -> ()" error message—but that can't really be
right, because #[test] functions that return a `Result` with a static
lifetime are accepted!

It turns out that this error message dates all the way back to April
2013's 5f1a90e ("Issue 4391: rustc should not silently skip tests
with erroneous signature."). But after RFC 1937, we actually do accept
non-unit return types in tests. Let's edit the error message
accordingly.

This resolves rust-lang#55228, and is of historical interest to rust-lang#4391.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-libtest Area: #[test] related C-enhancement Category: An issue proposing an enhancement or a PR with one. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants