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

diverging function with wrapped diverging tail expression regression #35849

Closed
Dushistov opened this issue Aug 20, 2016 · 7 comments
Closed

diverging function with wrapped diverging tail expression regression #35849

Dushistov opened this issue Aug 20, 2016 · 7 comments
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Dushistov
Copy link
Contributor

Such code:

#[allow(dead_code)]
fn _assert_pointers_are_64bits() -> ! {
    unsafe {
        ::std::mem::transmute::<*const f64, [u8; 8]>(panic!())
    }
}

fn main() {
}

compiled just fine with stable(1.11.0 (9b21dcd 2016-08-15)),
but failed with beta(rustc 1.12.0-beta.1 (822166b 2016-08-16)) and
nightly(rustc 1.13.0-nightly (499484f 2016-08-18)) with such error:

error[E0308]: mismatched types
 --> bug.rs:4:9
  |
4 |         ::std::mem::transmute::<*const f64, [u8; 8]>(panic!())
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected !, found array of 8 elements
  |
  = note: expected type `!`
  = note:    found type `[u8; 8]`

error: aborting due to previous error
@Aatch Aatch added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Aug 20, 2016
@Aatch
Copy link
Contributor

Aatch commented Aug 20, 2016

I assume this is related to the recent changes to how we treat !.

/cc @rust-lang/compiler

@eddyb
Copy link
Member

eddyb commented Aug 20, 2016

@canndrew Did you remove some sort of codepath that assumed a call with diverging arguments is also diverging?

@arielb1 arielb1 added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-nominated labels Aug 20, 2016
@arielb1
Copy link
Contributor

arielb1 commented Aug 20, 2016

Nothing to do with transmute:

fn _assert_pointers_are_64bits() -> ! {
    [panic!()]
}

fn main() {}

Stable has something that marks unreachable pointers as type variables.

@arielb1 arielb1 changed the title transmute + diverging function regression wrapped diverging function regression Aug 20, 2016
@arielb1
Copy link
Contributor

arielb1 commented Aug 20, 2016

Ah well. The issue here is that now, because ! is a type, typeck checks that the final expression of a diverging function has type ! (which it doesn't).

The older check was liveness's more general check that diverging functions don't return (see e.g. #31617), which observes that panic!() never returns.

As a fix, we can pass NoExpectation when the return type is ! - https:/rust-lang/rust/blob/stable/src/librustc_typeck/check/mod.rs#L683.

@arielb1
Copy link
Contributor

arielb1 commented Aug 20, 2016

Note that adding a semicolon to the expression also makes things compile on all versions (as it goes straight to the liveness check at https:/rust-lang/rust/blob/4901896/src/librustc/middle/liveness.rs#L1503), even if the function returns something other than !:

fn _assert_pointers_are_64bits() -> String {
    [panic!()];
}

Maybe we should just let this one slip?

@eddyb
Copy link
Member

eddyb commented Aug 20, 2016

Using NoExpectation seems like the direct fix, yes.

@arielb1 arielb1 changed the title wrapped diverging function regression diverging function with wrapped diverging tail expression regression Aug 20, 2016
@durka
Copy link
Contributor

durka commented Aug 21, 2016

Talked to @eddyb on IRC, I will try to fix this (he told me exactly what to write so hopefully it will be straightforward :D).

durka pushed a commit to durka/rust that referenced this issue Aug 22, 2016
This fixes rust-lang#35849, a regression introduced by the typeck refactoring
around TyNever/!.
eddyb added a commit to eddyb/rust that referenced this issue Aug 22, 2016
typeck: use NoExpectation to check return type of diverging fn

Fixes rust-lang#35849.

Thanks @eddyb.
durka pushed a commit to durka/rust that referenced this issue Aug 23, 2016
This fixes rust-lang#35849, a regression introduced by the typeck refactoring
around TyNever/!.
eddyb added a commit to eddyb/rust that referenced this issue Aug 23, 2016
typeck: use NoExpectation to check return type of diverging fn

Fixes rust-lang#35849.

Thanks @eddyb.
eddyb added a commit to eddyb/rust that referenced this issue Aug 23, 2016
typeck: use NoExpectation to check return type of diverging fn

Fixes rust-lang#35849.

Thanks @eddyb.
bors added a commit that referenced this issue Aug 24, 2016
typeck: use NoExpectation to check return type of diverging fn

Fixes #35849.

Thanks @eddyb.
alexcrichton pushed a commit to alexcrichton/rust that referenced this issue Sep 13, 2016
This fixes rust-lang#35849, a regression introduced by the typeck refactoring
around TyNever/!.
pmatos pushed a commit to LinkiTools/rust that referenced this issue Sep 27, 2016
This fixes rust-lang#35849, a regression introduced by the typeck refactoring
around TyNever/!.
arielb1 added a commit to arielb1/rust that referenced this issue Nov 15, 2017
This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
bors added a commit that referenced this issue Nov 15, 2017
[needs crater] make coercions to `!` in unreachable code a hard error

This was added to cover up a lazy extra semicolon in #35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
arielb1 added a commit to arielb1/rust that referenced this issue Nov 28, 2017
This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
make coercions to `!` in unreachable code a hard error

This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
arielb1 added a commit to arielb1/rust that referenced this issue Nov 30, 2017
This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
make coercions to `!` in unreachable code a hard error

This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
make coercions to `!` in unreachable code a hard error

This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 30, 2017
make coercions to `!` in unreachable code a hard error

This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
kennytm added a commit to kennytm/rust that referenced this issue Dec 1, 2017
make coercions to `!` in unreachable code a hard error

This was added to cover up a lazy extra semicolon in rust-lang#35849, but does
not actually make sense. This is removed as a part of the stabilization
of `never_type`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants