Skip to content

Weird rustc errors about expected types. #57713

Closed
@AmlingPalantir

Description

@AmlingPalantir

I tried this code:

https://github.com/AmlingPalantir/20190117-rustc-bug

I expected to see this happen:

Compiler error complains about return type, something like "expected
Bottom::Structo, found Bottom2::Structo".

Instead, this happened:

Compiler error seems to be trying to replace actual types (like
Bottom2::Structo) with visible aliases for them. In this case Bottom2::Structo
isn't actually visible to the code so this makes a kind of sense, but what
happens is ... bad.

It says "expected bottom::Structo because of return type" which makes sense
because the return type is left::Structo which is an alias for bottom::Structo
and bottom::Structo is visible.

But then it says "found left::Structo" which is less sensible. In particular,
the called function returns bottom2::Structo which is not visible. I assume
it's trying to find an alias and sees that left has imported bottom2::Structo
so it says left::Structo, but left actually imported it as Structo2 (so it's left::Structo2).

Meta

This was from a freshly rustup'd nightly as of today (20190117).

$ ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --version --verbose
rustc 1.33.0-nightly (ceb2512 2019-01-16)
binary: rustc
commit-hash: ceb2512
commit-date: 2019-01-16
host: x86_64-unknown-linux-gnu
release: 1.33.0-nightly
LLVM version: 8.0

Backtrace:

 error[E0308]: mismatched types
  --> top/src/lib.rs:6:5
   |
 5 | fn foo() -> left::Structo {
   |             ------------- expected `bottom::Structo` because of return type
 6 |     right::f()
   |     ^^^^^^^^^^ expected struct `bottom::Structo`, found struct `left::Structo`
   |
   = note: expected type `bottom::Structo`
              found type `left::Structo`

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions