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

Unsized extern statics no longer compile #55239

Closed
mjbshaw opened this issue Oct 21, 2018 · 2 comments
Closed

Unsized extern statics no longer compile #55239

mjbshaw opened this issue Oct 21, 2018 · 2 comments
Labels
A-ffi Area: Foreign Function Interface (FFI) C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mjbshaw
Copy link
Contributor

mjbshaw commented Oct 21, 2018

This is likely due to #55004. Consider the following code:

#![feature(extern_types)]

extern "C" {
    pub type StartFn;
    pub static start: StartFn;
}

This code compiles with rustc 1.31.0-nightly (e7f5d4805 2018-10-18), but fails with rustc 1.31.0-nightly (78ff609d7 2018-10-19). Error message from rustc:

error[E0277]: the size for values of type `StartFn` cannot be known at compilation time
 --> t.rs:5:23
  |
5 |     pub static start: StartFn;
  |                       ^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `StartFn`
  = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

I think this code should still be accepted, and I believe #55004 accidentally broke this. One of the purposes of the extern_types feature is to better interact with C code like this:

struct SomeOpaqueType;
extern struct SomeOpaqueType SomeGlobal;

I think Rust should accept unsized extern statics that use an extern type (possibly wrapped in a transparent newtype).

cc @oli-obk

@kennytm kennytm added A-ffi Area: Foreign Function Interface (FFI) regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Oct 21, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Oct 21, 2018

I don't see how this is a regression from stable as you need a feature gate to replicate the regression.

That said, I do think we should fix this for extern types. Should be doable by using the struct_tail method on the type and checking the final type for is_extern() || is_sized() instead of doing the current check

@mjbshaw
Copy link
Contributor Author

mjbshaw commented Oct 21, 2018

Thanks for the quick feedback and guidance on how to fix! If you don't mind, I'd like to take a stab at fixing this.

mjbshaw added a commit to mjbshaw/rust that referenced this issue Oct 22, 2018
kennytm added a commit to kennytm/rust that referenced this issue Oct 24, 2018
Allow extern statics with an extern type

Fixes rust-lang#55239
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 25, 2018
Allow extern statics with an extern type

Fixes rust-lang#55239
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Oct 27, 2018
Allow extern statics with an extern type

Fixes rust-lang#55239
kennytm added a commit to kennytm/rust that referenced this issue Oct 28, 2018
Allow extern statics with an extern type

Fixes rust-lang#55239
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ffi Area: Foreign Function Interface (FFI) C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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

3 participants