Skip to content

Spurious type deduced when using ? #71685

Closed
@yshui

Description

@yshui

I tried this code:

#![feature(associated_type_bounds)]
struct S;
fn fn1<I: IntoIterator<Item: AsRef<S>>>(_iter: I) -> Result<(), ()> {
    Ok(())
}

async fn fn2(s: &str) -> Result<(), ()> {
    let s = s.parse().map_err(|_| ())?; // <- Spurious type deduced
    fn1(std::iter::once(s)).map_err(|e| ())?;
    Ok(())
}

I expected to see this happen:

error[E0282]: type annotations needed, because type of s cannot be determined.

Instead, this happened:

error[E0277]: the trait bound '(): std::str::FromStr' is not satisfied

As if s is assigned type ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceC-bugCategory: This is a bug.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