Skip to content

Diagnostics: mismatched types show wrong because of this statement #57664

Closed
@ohadravid

Description

@ohadravid

The following code

fn main() -> Result<(), std::string::ParseError> { 
    let x = 0;

    match x {
        1 => {
            let property_value_as_string = "a".parse()?;
        }
        2 => {
            let value: &bool = unsafe { &42 };
        }
    };
    
    Ok(())
}

(Playground)

Will generate the following error under nightly (rustc 1.33.0-nightly):

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/main.rs:9:41
  |
6 |             let property_value_as_string = "a".parse()?;
  |                                            ------------ expected because of this statement
...
9 |             let value: &bool = unsafe { &42 };
  |                                         ^^^ expected bool, found integer
  |
  = note: expected type `&bool`
             found type `&{integer}`

Which is incorrect (and confusing!).

stable produce the correct message:

error[E0308]: mismatched types
 --> src/main.rs:9:41
  |
9 |             let value: &bool = unsafe { &42 };
  |                                         ^^^ expected bool, found integral variable
  |
  = note: expected type `&bool`
             found type `&{integer}`

and removing either the ? or the unsafe { } will make nightly generate a correct message as well.

Meta

rustc --version --verbose (Windows):

rustc 1.33.0-nightly (e2f221c75 2019-01-15)
binary: rustc
commit-hash: e2f221c75932de7a29845c8d6f1f73536ad00c41
commit-date: 2019-01-15
host: x86_64-pc-windows-msvc
release: 1.33.0-nightly
LLVM version: 8.0

and

rustc --version --verbose (macOS):

rustc 1.33.0-nightly (e2f221c75 2019-01-15)
binary: rustc
commit-hash: e2f221c75932de7a29845c8d6f1f73536ad00c41
commit-date: 2019-01-15
host: x86_64-apple-darwin
release: 1.33.0-nightly
LLVM version: 8.0

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsP-highHigh priorityregression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions