Skip to content

Compiler incorrectly reports function return type declaration as source of inner type mismatch with conservative_impl_trait #46644

@mqudsi

Description

@mqudsi

Given a function specified as returning a composite type that incorrectly returns an object with an inner type mismatch, the compiler reports the error as being in the function return type declaration rather than at the point the incorrect item is returned.

A sample git repo can be found here: https://git.neosmart.net/mqudsi/futuretest/src/rust-46644

The code in question:

fn create_future() -> impl Future<Item=(), Error=()> {
    return future::ok(Ok(()));
}

The compiler returns the following;

   Compiling futuretest v0.1.0 (file:///mnt/d/GIT/futuretest)
error[E0271]: type mismatch resolving `<futures::FutureResult<std::result::Result<(), _>, ()> as futures::Future>::Item == ()`
  --> src/main.rs:17:23
   |
17 | fn create_future() -> impl Future<Item=(), Error=()> {
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found ()
   |
   = note: expected type `std::result::Result<(), _>`
              found type `()`
   = note: the return type of a function must have a statically known size

error: aborting due to previous error

error: Could not compile `futuretest`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions