-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed as not planned
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.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
I tried this code:
struct S<F>(F);
impl <'a, F, G> S<F>
where
F: Fn(&'a u8) -> G
{
fn call(&mut self) -> G {
(self.0)(&1)
}
}I expected to see this happen: G should be considered a constrained type.
Instead, this happened:
error[E0207]: the type parameter `G` is not constrained by the impl trait, self type, or predicates
Note that if you use '_ as the lifetime instead of 'a, it works. It also works if there is no lifetime on the input parameter (e.g. if it's not a reference). However I want to constrain G to the same lifetime (eventually) so that's not an option. Is this an issue due to some lifetime assumptions about the return type from Fn traits, specifically that having G: 'a makes it unconstrained as it can't reason about that?
This is identical for FnOnce and FnMut as well.
Meta
rustc --version --verbose:
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-unknown-linux-gnu
release: 1.53.0
LLVM version: 12.0.1
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.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.