Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0666: nested `impl Trait` is not allowed
What it meansimpl Trait types cannot appear nested in the generic arguments of other impl Trait types.
What rustc prints
error[E0666]: nested `impl Trait` is not allowed
--> main.rs:5:30
|
5 | bar: impl MyGenericTrait<impl MyInnerTrait>, // error!
| --------------------^^^^^^^^^^^^^^^^^-
| | |
| | nested `impl Trait` here
| outer `impl Trait`Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
impl Trait types cannot appear nested in the generic arguments of other impl Trait types.
Erroneous code example:
trait MyGenericTrait<T> {}
trait MyInnerTrait {}
fn foo(
bar: impl MyGenericTrait<impl MyInnerTrait>, // error!
) {}
Type parameters for impl Trait types must be explicitly defined as named generic parameters:
trait MyGenericTrait<T> {}
trait MyInnerTrait {}
fn foo<T: MyInnerTrait>(
bar: impl MyGenericTrait<T>, // ok!
) {}From rustc --explain E0666 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0433failed to resolve
- E0644closure/coroutine type that references itself
- E0665`#[derive(Default)]` on enum with no `#[default]`
- E0689can't call method `neg` on ambiguous numeric type `{float}`
- E0690transparent struct needs at most one non-trivial field, but has 2
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?