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

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

Closed
ohadravid opened this issue Jan 16, 2019 · 2 comments · Fixed by #57723
Closed

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

ohadravid opened this issue Jan 16, 2019 · 2 comments · Fixed by #57723
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@ohadravid
Copy link
Contributor

ohadravid commented Jan 16, 2019

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
@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 16, 2019
@estebank
Copy link
Contributor

Introduced in #57020.

@estebank estebank added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Jan 16, 2019
@pnkfelix pnkfelix added the P-high High priority label Jan 17, 2019
@pnkfelix
Copy link
Member

triage: P-high, assigning to @estebank . (But let me know if you have too much else on your plate and I'll reassign.)

Centril added a commit to Centril/rust that referenced this issue Jan 19, 2019
Point at cause for expectation in return type type error

Various improvements and fixes for type errors in return expressions.

Fix rust-lang#57664.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants