-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I tried this code:
use std::marker::PhantomData;
fn test_good() -> Builder<String> {
// this compiles
Builder::default().with_func(|s| drop(s))
}
fn test_bad() -> Builder<String> {
// error[E0282]: type annotations needed
Builder::default().with_func(|s| drop(s.len()))
}
#[derive(Default)]
pub struct Builder<Foo>(PhantomData<Foo>);
impl<Foo> Builder<Foo> {
fn with_func(self, _: impl Fn(Foo)) -> Self {
self
}
}
I expect this to compile, but the test_bad
function does not compile.
Meta
Rust Version: 1.86.0
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.