-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
After I try to use the tool.rs implementation of second
I get this error message:
Compiling fizzbuzz v0.0.1 (file:///C:/Users/Igor/Documents/rust/fizzbuzz)
error[E0281]: type mismatch: the type `fn(_) -> _ {tool::second::<_>}` implements the trait `std::ops::FnMut<(_,)>`, but the trait `for<'r> std::ops::FnMut<(&'r _,)>` is required (expected concrete lifetime, found bound lifetime parameter )
--> src\lib.rs:52:11
|
52 | .filter(apply(second, i))
| ^^^^^
|
= note: required by `apply`
error[E0271]: type mismatch resolving `for<'r> <fn(_) -> _ {tool::second::<_>} as std::ops::FnOnce<(&'r _,)>>::Output == _`
--> src\lib.rs:52:11
|
52 | .filter(apply(second, i))
| ^^^^^ expected bound lifetime parameter , found concrete lifetime
|
= note: concrete lifetime that was found is lifetime '_#11r
= note: required by `apply`
I still don't quite understand this error message. The lifetimes are anonymous, so I don't know what it's talking about. The 'r
lifetime is elided, I assume? There's no error code to help me understand the issue with concrete lifetimes vs. bound lifetime parameters.
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
nagisa commentedon Oct 22, 2016
Its saying that your
fn(_) -> _ {tool::second::<_>}
must implementstd::ops::FnMut<(&'r _,)>
for all possible lifetimes'r
(∀, for all, any, arbitrary), unrelated to any other lifetime. The function only implementsstd::ops::FnMut(_,)>
, i.e. a FnMut which does not really satisfy that requirement.To help with reasoning why this error is reported consider an equivalent:
The types here are:
c: &&(&str, &std::ops::Fn(i32) -> bool)
;second: fn second<P: Second>(seq: P) -> P::Second
;&(&str, &std::ops::Fn(i32) -> bool): Second
, but not&&(&str, &std::ops::Fn(i32) -> bool): Second
;At this point compiler tries these things:
&&(&str, &std::ops::Fn(i32) -> bool): Second
, which is not satisfied;&(&str, &std::ops::Fn(i32) -> bool): Second
does hold try finding thesecond: for<'r> Fn*(&'r T)
whereT = &(&str, &std::ops::Fn(i32) -> bool)
.I feel like the error reported in such circumstances cannot be pointing at the right place 100% of the time, as the actual error might be either that
&&(_,_): Second
is not satisfied or the one that you just got, and user might be interested in either of those.The solution fixing the error would be to dereference the
c
somehow… for example this way:iopq commentedon Oct 23, 2016
filter(apply(|c| second(c), i))
gives a really NICE error message:ah, so I need to use the git version of tool
the newest version has the correct impl, so when I do
tool = { git = "https://github.com/Stebalien/tool-rs" }
it actually compilesso now the issue is:
filter(apply(|c| second(c), i))
works andfilter(apply(second, i))
doesn'tand I assume the author of tool can't fix this one because of the higher rank lifetime issue?
nagisa commentedon Oct 23, 2016
Oh, so I didn’t check the issue closely enough.
So… even with the change to the
tool
crate,second
still only implementsFn*<(_,)>
, whereas in yourapply
you haveF: FnMut(&B) -> G
bound (which is equivalent toF: for<'r> FnMut(&'r B) -> G
). These will never match as I’ve already explained in the comment above.Changing your
apply
to the code below (with reasoning comments) fixes your problem.The error still (and even more so, now) seems totally correct (although kind-of opaque) to me.
iopq commentedon Oct 23, 2016
Ah, that does fix my issue.
The error is correct, but I still don't understand it that well.
How would that function implement such a thing?
nagisa commentedon Oct 23, 2016
I have no idea, but I have a feeling that you cannot implement traits for regular functions, so the only way to deal with the issue is to tweak bounds.
c7hm4r commentedon Jun 25, 2020
The error message for this problem has changed to:
While this is wrong or at least incomplete, it would be at least much more comprehensible. I think this bug can be closed. The problem seems to be a duplicate of #41078.