Skip to content

E0038 emmitted twice #128705

Open
Open
@lolbinarycat

Description

Code

trait Tr {
    const N: usize;
}

impl Tr for u8 {
    const N: usize = 1;
}

#[allow(dead_code)]
fn main() {
    let x: &dyn Tr = &0_u8;
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0038]: the trait `Tr` cannot be made into an object
  --> src/main.rs:11:22
   |
11 |     let x: &dyn Tr = &0_u8;
   |                      ^^^^^ `Tr` cannot be made into an object
   |
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> src/main.rs:2:11
   |
1  | trait Tr {
   |       -- this trait cannot be made into an object...
2  |     const N: usize;
   |           ^ ...because it contains this associated `const`
   = help: consider moving `N` to another trait
   = help: only type `u8` implements the trait, consider using it directly instead
   = note: required for the cast from `&u8` to `&dyn Tr`

error[E0038]: the trait `Tr` cannot be made into an object
  --> src/main.rs:11:12
   |
11 |     let x: &dyn Tr = &0_u8;
   |            ^^^^^^^ `Tr` cannot be made into an object
   |
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> src/main.rs:2:11
   |
1  | trait Tr {
   |       -- this trait cannot be made into an object...
2  |     const N: usize;
   |           ^ ...because it contains this associated `const`
   = help: consider moving `N` to another trait
   = help: only type `u8` implements the trait, consider using it directly instead

For more information about this error, try `rustc --explain E0038`.
error: could not compile `playground` (bin "playground") due to 2 previous errors

Desired output

Compiling playground v0.0.1 (/playground)
error[E0038]: the trait `Tr` cannot be made into an object
  --> src/main.rs:11:22
   |
11 |     let x: &dyn Tr = &0_u8;
   |                      ^^^^^ `Tr` cannot be made into an object
   |
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> src/main.rs:2:11
   |
1  | trait Tr {
   |       -- this trait cannot be made into an object...
2  |     const N: usize;
   |           ^ ...because it contains this associated `const`
   = help: consider moving `N` to another trait
   = help: only type `u8` implements the trait, consider using it directly instead
   = note: required for the cast from `&u8` to `&dyn Tr`

For more information about this error, try `rustc --explain E0038`.
error: could not compile `playground` (bin "playground") due to 2 previous errors

Rationale and extra context

visual noise

Other cases

No response

Rust Version

1.82.0-nightly (2024-08-04 176e5452095444815207)

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions