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

Weird rustc errors about expected types. #57713

Closed
AmlingPalantir opened this issue Jan 17, 2019 · 3 comments · Fixed by #57802
Closed

Weird rustc errors about expected types. #57713

AmlingPalantir opened this issue Jan 17, 2019 · 3 comments · Fixed by #57802
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution

Comments

@AmlingPalantir
Copy link

AmlingPalantir commented Jan 17, 2019

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`
@AmlingPalantir
Copy link
Author

This actually happened to me in real code, I've just stripped it way down. In the real case top was me, left was syn[::export], right was quote, bottom was proc_macro, bottom2 was proc_macro2, and Structo was TokenStream.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 18, 2019
@estebank
Copy link
Contributor

Pretty sure this is a duplicate of #56943, but the repro case is very helpful.

@estebank estebank added the A-resolve Area: Path resolution label Jan 18, 2019
@AmlingPalantir
Copy link
Author

Yeah, you can get errors similar to that ("expected X, found a different X") if you remove the top -> bottom link in my example.

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 A-resolve Area: Path resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants