Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0178: expected a path on the left-hand side of `+`
What it meansThe + type operator was used in an ambiguous context.
What rustc prints
error[E0178]: expected a path on the left-hand side of `+` --> main.rs:4:8 | 4 | x: &'a Foo + 'a, // error! | ^^^^^^^ | help: try adding parentheses | 4 | x: &'a (Foo + 'a), // error! | + +
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
The + type operator was used in an ambiguous context.
Erroneous code example:
trait Foo {}
struct Bar<'a> {
x: &'a Foo + 'a, // error!
y: &'a mut Foo + 'a, // error!
z: fn() -> Foo + 'a, // error!
}
In types, the + type operator has low precedence, so it is often necessary to use parentheses:
trait Foo {}
struct Bar<'a> {
x: &'a (Foo + 'a), // ok!
y: &'a mut (Foo + 'a), // ok!
z: fn() -> (Foo + 'a), // ok!
}
More details can be found in RFC 438.
From rustc --explain E0178 (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
- E0158constant pattern cannot depend on generic parameters
- E0170pattern binding `GET` is named the same as one of the variants of the type `Method`
- E0183manual implementations of `FnOnce` are experimental
- E0184the trait `Copy` cannot be implemented for this type; the type has a destructor
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?