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

Mismatched type error: type of crate instead of std is displayed #46112

Closed
SWW13 opened this issue Nov 20, 2017 · 22 comments · Fixed by #46708
Closed

Mismatched type error: type of crate instead of std is displayed #46112

SWW13 opened this issue Nov 20, 2017 · 22 comments · Fixed by #46708
Assignees
Labels
C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@SWW13
Copy link

SWW13 commented Nov 20, 2017

On nightly rustc (cargo) I get misleading expected type errors. If a crate has the same(?) type it is displayed instead of the std type.

I tried this code:

extern crate bitflags;
fn test(r: Result<Option<()>, &'static str>) { }
fn main() { test(Ok(())); }

I expected to see this happen: (stable rust)

$ rustup default stable
$ cargo build
   Compiling rust-sample v0.1.0 (file:///[...]/rust-sample)
error[E0308]: mismatched types
 --> src/main.rs:3:21
  |
3 | fn main() { test(Ok(())); }
  |                     ^^
  |                     |
  |                     expected enum `std::option::Option`, found ()
  |                     help: try using a variant of the expected type: `Some(())`
  |
  = note: expected type `std::option::Option<()>`
             found type `()`

Instead, this happened: (nightly)

$ rustup default nightly
$ cargo build
   Compiling rust-sample v0.1.0 (file:///[...]/rust-sample)
error[E0308]: mismatched types
 --> src/main.rs:3:21
  |
3 | fn main() { test(Ok(())); }
  |                     ^^
  |                     |
  |                     expected enum `bitflags::<unnamed>::option::Option`, found ()
  |                     help: try using a variant of the expected type: `bitflags::<unnamed>::prelude::v1::Some(())`
  |
  = note: expected type `bitflags::<unnamed>::option::Option<()>`
             found type `()`

Meta

rustc --version --verbose:

rustc 1.23.0-nightly (5041b3bb3 2017-11-19)
binary: rustc
commit-hash: 5041b3bb3d953a14f32b15d1e41341c629acae12
commit-date: 2017-11-19
host: x86_64-unknown-linux-gnu
release: 1.23.0-nightly
LLVM version: 4.0

@arielb1
Copy link
Contributor

arielb1 commented Nov 20, 2017

Confirming - broken on nightly (1.23), good on beta.

@arielb1 arielb1 added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2017
@TimNN TimNN added the C-bug Category: This is a bug. label Nov 21, 2017
@arielb1 arielb1 added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Nov 30, 2017
@pnkfelix
Copy link
Member

pnkfelix commented Dec 1, 2017

bisected across nightlys: bug was injected between rustc 1.23.0-nightly (02004ef78 2017-11-08) and rustc 1.23.0-nightly (d6b06c63a 2017-11-09)

@pnkfelix
Copy link
Member

pnkfelix commented Dec 1, 2017

Skimming output from git log 02004ef78^..d6b06c63a, there are a number of different potential culprits. Rather than guess and "point fingers" right now, I'll just continue bisecting within that commit range.

@Mark-Simulacrum
Copy link
Member

This is recent enough that we should be able to run bisect-rust on it (cc @est31).

@est31
Copy link
Member

est31 commented Dec 1, 2017

Searching in 7 commits; about 3 steps
Checking
  |                        expected enum `std::option::Option`, found ()
INFO:bisect: tested fd9ecfdfd from Thu,  9 Nov 2017 04:14:28 +0000: test failed: true
Checking
  |                        expected enum `std::option::Option`, found ()
INFO:bisect: tested da3fbe750 from Wed,  8 Nov 2017 22:27:06 +0000: test failed: true
Checking
  |                        expected enum `std::option::Option`, found ()
INFO:bisect: tested 02004ef78 from Wed,  8 Nov 2017 20:00:41 +0000: test failed: true
searched commits 02004ef78383cb174a41df7735a552823fa10b90 through d6b06c63a0c735fc15c9c704422375c17b7c7e12
regression in 0; Some(Commit { sha: "02004ef78383cb174a41df7735a552823fa10b90", date: 2017-11-08T20:00:41Z, summary: "Auto merge of #45452 - estebank:colon-typo, r=nikomatsakis" })

#45452 it is cc @estebank @nikomatsakis .

@estebank
Copy link
Contributor

estebank commented Dec 1, 2017

I'm a little surprised that this would be caused by that PR. I can push a revert but would like to first test locally to make sure that revert that PR will fix this.

@est31
Copy link
Member

est31 commented Dec 1, 2017

I have misread @pnkfelix 's statement. Your PR is not at fault, sorry. I'm doing another search further back to find the causing PR.

@estebank
Copy link
Contributor

estebank commented Dec 1, 2017

@est31 I tried it locally in the meantime and I can confirm it is not :)

@est31
Copy link
Member

est31 commented Dec 1, 2017

Okay so the bug dates as far back as efceda2 from September 2nd which is as close to the limit as I dare to go. So to the people in control, please, prolong the limit :).

@Mark-Simulacrum
Copy link
Member

@pnkfelix suggests that the bug was introduced much more recently (11-08 to 11-09). Maybe the bisection script was wrong?

@est31
Copy link
Member

est31 commented Dec 1, 2017

@Mark-Simulacrum I should probably have read the original issue more closely :). @estebank sorry for pinging you!

Searching in 7 commits; about 3 steps
Checking
INFO:bisect: tested fd9ecfdfd from Thu,  9 Nov 2017 04:14:28 +0000: test failed: false
Checking
  |                        expected enum `bitflags::<unnamed>::option::Option`, found ()
  |                        help: try using a variant of the expected type: `bitflags::<unnamed>::prelude::v1::Some(())`
  = note: expected type `bitflags::<unnamed>::option::Option<()>`
INFO:bisect: tested f1ea23e2c from Thu,  9 Nov 2017 18:14:48 +0000: test failed: true
Checking
INFO:bisect: tested 98e791e7e from Thu,  9 Nov 2017 15:42:26 +0000: test failed: false
searched commits 02004ef78383cb174a41df7735a552823fa10b90 through d6b06c63a0c735fc15c9c704422375c17b7c7e12
regression in 5; Some(Commit { sha: "f1ea23e2cc72cafad1dc25a06c09ec2de8e323eb", date: 2017-11-09T18:14:48Z, summary: "Auto merge of #45725 - alexcrichton:std-less-rand, r=dtolnay" })

It seems to be #45725 cc @alexcrichton

@pnkfelix
Copy link
Member

pnkfelix commented Dec 4, 2017

In particular, I have bisected it down to the commit: 6bc8f16

I have been trying to further dissect that commit to figure out why it causes the change we observe here.

My current hypothesis (that I have not yet managed to confirm) is that it has to do with how we seed the hashmap's hashers with randomized state. (This commit changes our behavior in certain scenarios.) If this hypothesis is actually true, though, then I would think that this represents either a bug in hashmap itself, or a bug in how the compiler is using the hashmap...

@pnkfelix
Copy link
Member

pnkfelix commented Dec 5, 2017

Hmm. Its something more subtle than a hashmap-related bug.

In particular, I can reproduce the old behavior on master by just linking in the old librand crate into libstd (in addtion to linking in the one from crates.io; doing this requires changing the name of the old librand), without making any actual calls into the old librand crate.

That, to me, seems very strange. I'm now trying to reduce down the size of the librand crate that I am linking in (while still causing this delta in behavior).

@Mark-Simulacrum Mark-Simulacrum added this to the 1.23 milestone Dec 5, 2017
@nikomatsakis
Copy link
Contributor

triage: P-high

@rust-highfive rust-highfive added the P-high High priority label Dec 7, 2017
pnkfelix added a commit to pnkfelix/rust that referenced this issue Dec 13, 2017
pnkfelix added a commit to pnkfelix/rust that referenced this issue Dec 13, 2017
bors added a commit that referenced this issue Dec 13, 2017
Fix visible_parent_map to choose globally minimal paths

Fix #46112: visible_parent_map construction needs a BFS over whole crate forest to get globally minimal paths.

(There are other latent bugs that were e.g. causing this test case to have weirdness like `<unnamed>` in the diagnostic output. Those bugs are not fixed here, since they are issues long-standing in the stable channel.)
@SWW13
Copy link
Author

SWW13 commented Dec 15, 2017

I still get a non std types in erros when the path has the same length. That would be okay if it is somehow deterministic, but I get different type errors within the same file for the same types.

error[E0308]: mismatched types
   --> src/bus/mod.rs:350:25
    |
350 |                         Err(BusError::ServiceTimeout(elapsed))
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`
    |
    = note: expected type `std::option::Option<_>`
               found type `std::result::Result<_, bus::BusError>`
error[E0308]: mismatched types
   --> src/bus/mod.rs:339:37
    |
339 |                     .and_then(|len| T::from_bytes(&self.buffer[0..len]))
    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `serde::export::Option`, found enum `serde::export::Result`
    |
    = note: expected type `serde::export::Option<_>`
               found type `serde::export::Result<C, services::ServiceError>`

@estebank estebank reopened this Dec 15, 2017
@pnkfelix
Copy link
Member

@SWW13 is that a regression from the stable channel?

While I absolutely agree that a deterministic result would be better (and better stilll, a deterministic result that favored minimal-length paths rooted at std), I want to triage this appropriately.

@pnkfelix
Copy link
Member

pnkfelix commented Dec 19, 2017

Hmm I guess since @SWW13 is the person who filed the original ticket then it is reasonable to infer that they are indeed seeing the described behavior on regression compared to the stable channel.

@SWW13
Copy link
Author

SWW13 commented Dec 19, 2017

@SWW13 is that a regression from the stable channel?

cargo +stable build gives me:

error[E0308]: mismatched types
   --> src/bus/mod.rs:339:37
    |
339 |                     .and_then(|len| T::from_bytes(&self.buffer[0..len]))
    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `serde::export::Option`, found enum `serde::export::Result`
    |
    = note: expected type `serde::export::Option<_>`
               found type `serde::export::Result<C, services::ServiceError>`

error[E0308]: mismatched types
   --> src/bus/mod.rs:350:25
    |
350 |                         Err(BusError::ServiceTimeout(elapsed))
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `serde::export::Option`, found enum `serde::export::Result`
    |
    = note: expected type `serde::export::Option<_>`
               found type `serde::export::Result<_, bus::BusError>`

cargo +nightly build seems to work now:

error[E0308]: mismatched types
   --> src/bus/mod.rs:339:37
    |
339 |                     .and_then(|len| T::from_bytes(&self.buffer[0..len]))
    |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`
    |
    = note: expected type `std::option::Option<_>`
               found type `std::result::Result<C, services::ServiceError>`

error[E0308]: mismatched types
   --> src/bus/mod.rs:350:25
    |
350 |                         Err(BusError::ServiceTimeout(elapsed))
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found enum `std::result::Result`
    |
    = note: expected type `std::option::Option<_>`
               found type `std::result::Result<_, bus::BusError>`

Maybe this was some sort of partial compile cache issue? I haven't found a way to reproduce these mixed errors yet.

pnkfelix added a commit to pnkfelix/rust that referenced this issue Dec 19, 2017
Sorting by crate-num should ensure that we favor `std::foo::bar` over
`any_other_crate::foo::bar`.

Interestingly, *this* change had a much larger impact on our internal
test suite than PR rust-lang#46708 (which was my original fix to rust-lang#46112).
pnkfelix added a commit to pnkfelix/rust that referenced this issue Dec 20, 2017
Sorting by crate-num should ensure that we favor `std::foo::bar` over
`any_other_crate::foo::bar`.

Interestingly, *this* change had a much larger impact on our internal
test suite than PR rust-lang#46708 (which was my original fix to rust-lang#46112).

----

(This is cherry-pick of aa030dd to beta.)
pnkfelix added a commit to pnkfelix/rust that referenced this issue Dec 20, 2017
pnkfelix added a commit to pnkfelix/rust that referenced this issue Dec 21, 2017
…re::`

The reason we see `core::` even after visiting the `std` crate first
is the special case code that looks like this:

```rust
    Entry::Occupied(mut entry) => {
        // If `child` is defined in crate `cnum`, ensure
        // that it is mapped to a parent in `cnum`.
        if child.krate == cnum && entry.get().krate != cnum {
            entry.insert(parent);
        }
    }
```

This causes items to be associated with the crates they were
originally defined in, even if we had encountered them during the
traversal of an earlier crate.

(Having said that, I am not clear on why this same logic does not
apply when both rust-lang#46708 and rust-lang#46838 have been applied. But at this
point, I am just happy to have a plausible explanation for why we see
`core::foo::bar` in the output for these tests, and want to focus on
getting this fix for rust-lang#46112 backported to beta.)
bors added a commit that referenced this issue Dec 22, 2017
Followup for #46112.

Sorting by crate-num should ensure that we favor `std::foo::bar` over
`any_other_crate::foo::bar`.

Interestingly, *this* change had a much larger impact on our internal
test suite than PR #46708 (which was my original fix to #46112).
bors added a commit that referenced this issue Dec 23, 2017
…woerister

Backport 46112 fix to beta

Its probably easiest to focus on the diff rather than the commit series.

If you prefer I could squash them, but I figured preserving the cherry-picking will make it easier to relate what has happened here to what happens on the `master` branch.

Note: This is a backport of *just* #46838. It does not include #46708 (which we may end up wanting to revert).

Fix #46112
@dtolnay
Copy link
Member

dtolnay commented Dec 24, 2017

This looks like a duplicate of #45070. That issue has some repro cases that affect the 1.22.1 stable compiler but not 1.21.0.

@dtolnay dtolnay added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Dec 24, 2017
@ExpHP
Copy link
Contributor

ExpHP commented Dec 24, 2017

When I bisected the nightlies by hand on #45070 I ended up with a range (d93036a...dead08c) that does not include the rand commit identified here. Is it possible that the nondeterministic nature of the bug is also messing with our attempts to bisect?

Expectation: ................XXXXXXXXXXXXXXXXXXXXXXX
    Reality: ................XXX....X..X..XXXXXXXXXX
             (<-- past)                (present -->)

Legend:
   X: Commit where test fails
   .: Commit where test succeeds

I wonder whether merely linking rand affects #45070 in the same way as it affected this issue.

@arielb1
Copy link
Contributor

arielb1 commented Dec 24, 2017

@dtolnay

Any evidence of this problem existing with the newest nightly?

@dtolnay
Copy link
Member

dtolnay commented Dec 25, 2017

All the cases I tried seem to have been fixed by #46708 and #46838. Nicely done! I reported one follow-up in #46991.

@dtolnay dtolnay closed this as completed Dec 25, 2017
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. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.