-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-impl_trait_in_bindings`#![feature(impl_trait_in_bindings)]``#![feature(impl_trait_in_bindings)]`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.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-impl_trait_in_bindings`#![feature(impl_trait_in_bindings)]``#![feature(impl_trait_in_bindings)]`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.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.