Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
asterycs opened this issue Nov 10, 2021 · 0 comments · Fixed by #90771
Closed

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

asterycs opened this issue Nov 10, 2021 · 0 comments · Fixed by #90771
Labels
C-bug Category: This is a bug.

Comments

@asterycs
Copy link
Contributor

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>

@asterycs asterycs added the C-bug Category: This is a bug. label Nov 10, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 11, 2021
…e, r=michaelwoerister

Fix trait object error code

closes rust-lang#90768

I `grep`:d and changed the occurrences that seemed relevant. Please let me know what you think and if anything is missing!
the8472 added a commit to the8472/rust that referenced this issue Nov 11, 2021
…e, r=michaelwoerister

Fix trait object error code

closes rust-lang#90768

I `grep`:d and changed the occurrences that seemed relevant. Please let me know what you think and if anything is missing!
hellow554 added a commit to hellow554/rust that referenced this issue Nov 12, 2021
…e, r=michaelwoerister

Fix trait object error code

closes rust-lang#90768

I `grep`:d and changed the occurrences that seemed relevant. Please let me know what you think and if anything is missing!
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 13, 2021
…e, r=michaelwoerister

Fix trait object error code

closes rust-lang#90768

I `grep`:d and changed the occurrences that seemed relevant. Please let me know what you think and if anything is missing!
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 13, 2021
…e, r=michaelwoerister

Fix trait object error code

closes rust-lang#90768

I `grep`:d and changed the occurrences that seemed relevant. Please let me know what you think and if anything is missing!
@bors bors closed this as completed in b35af0d Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant