Skip to content

Unsized extern statics no longer compile #55239

Closed
@mjbshaw

Description

@mjbshaw

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions