-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
don't gratuitously error on tests returning Result with lifetime #80934
don't gratuitously error on tests returning Result with lifetime #80934
Conversation
Nice to see you back! Wouldn't this change also incorrectly allow |
I don't think so. When I tried fleshing out your proposed counterexample into something that "gets closer to" compiling, I ended up with: struct Quux;
trait Bar {
type Baz;
fn rah(&self) -> Self::Baz;
}
impl Bar for Quux {
type Baz = String;
fn rah(&self) -> Self::Baz {
"rah".to_owned()
}
}
#[test]
fn foo<T: Bar<Baz = String>>() -> <T as Bar>::Baz {
let q = Quux{};
<Quux as Bar>::rah(&q)
} which fails:
I think this is ideally Clippy's job rather than the compiler's? Certainly, it's weird to define a test with the return type signature |
I could argue that the current output for the type parameter case is better and this would be a slight regression:
Could we instead change this to check for |
8d2e193
to
1ebf430
Compare
@estebank OK, how about this (force-pushed)? |
This comment has been minimized.
This comment has been minimized.
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.
1ebf430
to
adf12f3
Compare
(fixed tidy) |
CC @rust-lang/lang to let people know of what's being changed here.
|
The language team discussed this in the last meeting. We felt uncertain about this particular change, in particular, because it felt like the motivation was not clearly communicated - since the lifetime must be 'static regardless, in all cases, it seems like we'd potentially confuse users but not actually gain much value. Could you say more about the motivation here? It seems like improving the diagnostic to not complain about a non-unit return type makes sense, but it's not clear that allowing more cases does. |
☔ The latest upstream changes (presumably #85346) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm going to go ahead and close this; it's still blocked on the motivation question raised in #80934 (comment). Feel free to reopen and/or poke on Zulip if you'd like to pick this back up again. |
(Personal note: I'm not dead; I just didn't have time for Rust for, um, seventeen months, because I had to fight a religious war over the philosophy of language in my local apocalyptic robot cult. I won, sort of. Um, I think according to the letter of RFC 2689, I was supposed to be demoted from compiler team contributors to alumni status on inactivity grounds, but it doesn't look like anyone noticed??)
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 aResult
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.
So the check to which this 2013 error message has survived attached, looking to see if the generic params are empty, can be deleted: non-empty generic params aren't necessarily an error anymore. Having been deleted, the match expression simplifies down to a conditional.This resolves #55228, and is of historical interest to #4391.
r? @estebank