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

Allow ! as the return type of proc/closure literals #16836

Merged
merged 2 commits into from
Sep 17, 2014

Conversation

ftxqxd
Copy link
Contributor

@ftxqxd ftxqxd commented Aug 29, 2014

Fixes #13490.

@alexcrichton
Copy link
Member

This may be a very untested part of the compiler (as it may have never been exercised before), so it would be nice to see a larger array of tests to ensure that this feature does indeed work. Some things such as:

  • If a ! closure returns, an error should be generated.
  • Code after a ! closure invocation should be dead.
  • Calling a ! closure in a ! function should be ok

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Aug 30, 2014

There’s already some testing for this: compile-fail/closure-that-fails.rs tests that closures that return ! cannot return. But I’ll add some more tests to this PR.

@nikomatsakis
Copy link
Contributor

More tests I would like:

  • A closure that is declared as -> ! but in fact does not fail (compile-fail).
  • A closure being passed to a fn that expects -> !
    • This raises the question of whether we will require an explicit -> ! also in the callee side, I think we will
      • To be honest, I am happy with more-or-less either behavior, but I want a test showing what it is

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Sep 3, 2014

I think compile-fail/closure-that-fails.rs covers most of those cases, but it doesn’t directly specify the -> ! type in the closure literal, only in the function declaration. I’ll update that test to test that -> ! actually means something in literals.

@bors bors closed this Sep 17, 2014
@bors bors merged commit e5bbbbe into rust-lang:master Sep 17, 2014
ehuss added a commit to ehuss/rust that referenced this pull request Apr 15, 2023
This test was ignored long ago in
rust-lang#20578 when the syntax for
closures was changed.

The current status is that a closure with an explicit `!` return type
will trigger the `unreachable_code` lint which appears to be the
original intent of the test
(rust-lang#16836). A closure without a
return type won't trigger the lint since the `!` type isn't inferred
(AFAIK). This restores the test to its original form.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proc and closure expressions do not accept ! as a return type
4 participants