Closed
Description
#53542 introduced impl Trait
bindings in consts and statics (along with let bindings), but of course they cannot be assigned a value of a generic type. The error message is presently a bit confusing:
error[E0434]: can't capture dynamic environment in a fn item
--> .../bindings.rs:4:29
|
4 | const foo: impl Clone = x;
| ^
|
= help: use the `|| { ... }` closure form instead
Example:
#![feature(impl_trait_in_bindings)]
fn a<T: Clone>(x: T) {
const foo: impl Clone = x;
}
A message like cannot assign value of generic type to const or static of opaque type
would be better, I think (unless there's already a suitable error that can be reused).
See also the bindings
test from the above PR and its stderr.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Category: An issue proposing an enhancement or a PR with one.`#![feature(impl_trait_in_bindings)]`Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.