Skip to content

Incorrect error code when using a trait object without dyn #90768

Closed
@asterycs

Description

@asterycs

Hi all, thank you for the great work on rust!

I believe the compiler might be suggesting an incorrect error code when omitting dyn with trait objects. An example is the following snippet (playground):

trait MyTrait {
}

impl dyn MyTrait {
    fn get_num() -> i32 {
        7
    }
}

fn main() {
    println!("The number is: {}", MyTrait::get_num());
}

The error code E0783 in the error message seems to point to an error regarding the range pattern. I believe the correct error may instead be E0782.

   Compiling playground v0.0.1 (/playground)
error[E0783]: trait objects without an explicit `dyn` are deprecated
  --> src/main.rs:13:35
   |
13 |     println!("The number is: {}", MyTrait::get_num());
   |                                   ^^^^^^^ help: use `dyn`: `<dyn MyTrait>`

For more information about this error, try `rustc --explain E0783`.
error: could not compile `playground` due to previous error

Meta

rustc --version --verbose:

rustc --version --verbose
rustc 1.58.0-nightly (8b09ba6a5 2021-11-09)
binary: rustc
commit-hash: 8b09ba6a5d5c644fe0f1c27c7f9c80b334241707
commit-date: 2021-11-09
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions