Skip to content

support code such as fn(x: !) -> ! { x } with #![feature(never_type)] #35940

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
durka opened this issue Aug 23, 2016 · 3 comments
Closed

support code such as fn(x: !) -> ! { x } with #![feature(never_type)] #35940

durka opened this issue Aug 23, 2016 · 3 comments

Comments

@durka
Copy link
Contributor

durka commented Aug 23, 2016

This kind of code worked with the original implementation of #![feature(never_type)], but that's because the check for diverging functions that converge was removed from liveness. With that restored, it incorrectly fires here.

@eddyb believes the fix involves:

<eddyb> and if you want to fix it *separately*, basically have a check like that that
        changes succ to be self.s.exit_ln if there's a NeverToAny adjustment for that
        expression, here https://github.com/rust-lang/rust/blob/master/src/librustc/middle/liveness.rs#L930
<eddyb> durka42: oh and if you do that separate PR, you can remove the ExprCall and
        ExprMethod call is_never checks

cc @canndrew. Discovered during #35883.

@arielb1
Copy link
Contributor

arielb1 commented Aug 29, 2016

You can also skip the check in liveness if the return expression has type TyNever - that's how MIR typeck does it.

@durka
Copy link
Contributor Author

durka commented Aug 29, 2016

@arielb1 isn't that the check that we put back in at #35883? If you don't check you end up with fn foo() -> ! { 42 } being accepted.

@Mark-Simulacrum
Copy link
Member

The below is now accepted. src/test/run-fail/call-fn-never-arg.rs tests for this.

#![feature(never_type)]

fn x(y: !) -> ! { y }

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants