Skip to content

impl Error on Enum with str type #34934

Closed
@adjivas

Description

@adjivas

Hello, I repport this issue.

I tried this code:

use std::fmt;
use std::fmt::{Display, Debug};

use std::error::Error;

enum PartError {
    UnknownPart(str),
    ForbiddenGlyph(char),
}

impl Error for PartError {
    fn description(&self) -> &str {
        match *self {
            PartError::UnknownPart(_) => "the name of part is unknown",
            PartError::ForbiddenGlyph(_) => "the glyph is on a forbidden range",
        }
    }
}

impl Display for PartError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self)
    }
}

impl Debug for PartError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self)
    }
}

fn main() {
}

I expected to see this happen:

error: internal compiler error: ../src/librustc_trans/type_of.rs:178: Unexpected tail in unsized_info_ty: PartError for ty=PartError

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:634
note: Run with `RUST_BACKTRACE=1` for a backtrace.

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