Skip to content

Unclear error with type inference failure #41261

Open
@jethrogb

Description

@jethrogb
struct S {
    v: Vec<(u32, Vec<u32>)>,
}

impl S {
    pub fn remove(&mut self, i: u32) -> Option<std::vec::Drain<u32>> {
        self.v.get_mut(i as _).map(|&mut (_, ref mut v2)| {
            v2.drain(..)
        })
    }
}

Errors with:

error: the type of this value must be known in this context
 --> src/main.rs:8:16
  |
8 |             v2.drain(..)
  |                ^^^^^

I'm not sure which value the error is pointing at here. The fix here is to explicitly specify the type we want to cast i into.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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