Skip to content

Enabling kv_unstable causes inference breakage #397

@dtolnay

Description

@dtolnay

As of https://github.com/rust-analyzer/rust-analyzer/tree/1dba84019e0f3e7175f204624629a52013332e52, building with cargo check succeeds but with cargo check --features log/kv_unstable fails.

$ cargo check --manifest-path crates/ra_hir_def/Cargo.toml 
    Checking ra_hir_def v0.1.0
    Finished dev [unoptimized] target(s) in 0.75s

$ cargo check --manifest-path crates/ra_hir_def/Cargo.toml --features log/kv_unstable
    Checking ra_hir_def v0.1.0
error[E0282]: type annotations needed for the closure `fn(&str) -> std::result::Result<(), _>`
   --> crates/ra_hir_def/src/path.rs:278:17
    |
278 |                 f.write_str("::")?;
    |                 ^^^^^^^^^^^^^^^^^^ cannot infer type
    |
help: give this closure an explicit return type without `_` placeholders
    |
276 |         let mut add_segment = |s| -> std::result::Result<(), _> {
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The code surrounding the error looks like:

impl Display for ModPath {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut first_segment = true;
        let mut add_segment = |s| {
            if !first_segment {
                f.write_str("::")?;     // 278
            }
            first_segment = false;
            f.write_str(s)?;
            Ok(())
        };
        match self.kind {
            PathKind::Plain => {}
            PathKind::Super(n) => {
                if n == 0 {
                    add_segment("self")?;
                }
                for _ in 0..n {
                    add_segment("super")?;
                }
            }
            PathKind::Crate => add_segment("crate")?,
            PathKind::Abs => add_segment("")?,
            PathKind::DollarCrate(_) => add_segment("$crate")?,
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions