Skip to content

rustc suggests _::_serde::__private::Ok(1) instead of Ok(1) #90982

Closed
@jendrikw

Description

@jendrikw

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use%20serde%3A%3ADeserialize%3B%0A%0A%23%5Bderive(Deserialize)%5D%0Astruct%20S%20%7B%7D%0A%0Afn%20f()%20-%3E%20Result%3Ci8%2C%20()%3E%20%7B%0A%20%20%20%201%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20println!(%22Hello%2C%20world!%22)%3B%0A%7D

use serde::Deserialize;

#[derive(Deserialize)]
struct S {}

fn f() -> Result<i8, ()> {
    1
}

fn main() {
    println!("Hello, world!");
}

The current output is:

error[E0308]: mismatched types
 --> src/main.rs:7:5
  |
6 | fn f() -> Result<i8, ()> {
  |           -------------- expected `Result<i8, ()>` because of return type
7 |     1
  |     ^
  |     |
  |     expected enum `Result`, found integer
  |     help: try using a variant of the expected enum: `_::_serde::__private::Ok(1)`
  |
  = note: expected enum `Result<i8, ()>`
             found type `{integer}`

Ideally the output should look like:

error[E0308]: mismatched types
 --> src/main.rs:7:5
  |
6 | fn f() -> Result<i8, ()> {
  |           -------------- expected `Result<i8, ()>` because of return type
7 |     1
  |     ^
  |     |
  |     expected enum `Result`, found integer
  |     help: try using a variant of the expected enum: `Ok(1)`
  |
  = note: expected enum `Result<i8, ()>`
             found type `{integer}`

The bug exists on stable 1.56.1 and current nightly 2021-11-16.

Metadata

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