Skip to content

Rustc does not to recognize array as a locally defined type. #20742

@georgschoelly

Description

@georgschoelly

I stumbled upon strange behaviour of rustc (1.0.0-nightly 2015-01-06). It seems to treat [uint; 5] differently from [SomeStruct; 5].

the type [uint; 1] does not reference any types defined in this crate; only traits defined in the current crate can be implemented for arbitrary types [E0117]

Is this expected behaviour or a bug in the compiler?

Code 1 (does not compile):

use std::default::Default;

type AnArray = [uint; 1];

impl Default for AnArray {
    fn default() -> AnArray {
        [0; 1]
    }
}

fn main() {}

Code 2 (compiles):

use std::default::Default;

struct UnitStruct;

type AnArray = [UnitStruct; 1];

impl Default for AnArray {
    fn default() -> AnArray {
        [UnitStruct; 1]
    }
}

fn main() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions