Skip to content

ICE when casting to trait object #17371

Closed
@nmsmith

Description

@nmsmith

This code is incorrect, since it tries to cast something to an unboxed trait object:

trait MyTrait {}
struct Foo;
impl MyTrait for Foo {}

fn main() {
    let foo: Foo = Foo;
    let t = foo as MyTrait;
}

But it causes an ICE, when it should simply cause an error.

May be related to #17322

Error:

test.rs:9:10: 9:13 error: internal compiler error: expected object type
test.rs:9  let t = foo as MyTrait;
                        ^~

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions