Rust errors / Ownership and borrowing
Rust compiler error · checked with rustc 1.99.0
Rust error E0747: type provided when a lifetime was expected
What it meansGeneric arguments were not provided in the same order as the corresponding generic parameters are declared.
What rustc prints
error[E0747]: type provided when a lifetime was expected
--> main.rs:3:12
|
3 | type X = S<(), 'static>; // error: the type argument is provided before the
| ^^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
Generic arguments were not provided in the same order as the corresponding generic parameters are declared.
Erroneous code example:
struct S<'a, T>(&'a T);
type X = S<(), 'static>; // error: the type argument is provided before the
// lifetime argument
The argument order should be changed to match the parameter declaration order, as in the following:
struct S<'a, T>(&'a T);
type X = S<'static, ()>; // okFrom rustc --explain E0747 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0382borrow of moved value
- E0499cannot borrow as mutable more than once at a time
- E0502cannot borrow as mutable because it is also borrowed as immutable
- E0106missing lifetime specifier
- E0726implicit elided lifetime not allowed here
- E0745cannot take address of a temporary
- E0764mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
- E0794cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
Up next
Often hit nextE0382: borrow of moved valueA related error from the same family.Read it next →Did this answer your question?