Skip to content

Unsized types allowed in trait method declarations and default type parameters #19182

Closed
@apasel422

Description

@apasel422

It appears that the rules for where unsized types may appear are inconsistently enforced. This doesn't appear to cause unsoundness, because the items are unusable, but an early error would probably be helpful.

The following snippets compile with rustc 0.13.0-nightly (399ff259e 2014-11-20 00:27:07 +0000):

trait Foo {
    fn bar(a: [u8]);
    fn baz() -> [u8];
}

Attempting to implement Foo or provide a default implementation for bar or baz results in the expected compilation error per #13376.

#![feature(default_type_params)]
trait Foo<T = [u8]> {}
struct Bar<T = [u8]>;
enum Baz<T = [u8]> {}
fn quux<T = [u8]>() {}

Note that T is not declared Sized?. Attempting to explicitly instantiate this type parameter with an unsized type results in the expected compilation error for each of these cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DSTsArea: Dynamically-sized types (DSTs)A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions