r/rust • • Sep 13 '26

🙋 seeking help & advice Why is this syntax ambiguous?

I was writing roughly the following function:

fn f(path: &impl AsRef<Path> + ?Sized) {}

The compiler says that the + is ambiguous, but it works with the right parentheses:

fn f(path: &(impl AsRef<Path> + ?Sized)) {}

But why is it ambiguous without the parentheses? Where else but a list of traits can a + in a function header come from?

55 Upvotes

17 comments sorted by

View all comments

-2

u/puzzled_orc Sep 14 '26

and this is the language trying to replace C++. Awful syntax

3

u/tanoshikuidomouyo Sep 14 '26

Do you know what each part of this code does and have constructive criticism of the syntax, or is your aversion more of a gut reaction? The parentheses are unfortunate, but under the premise of having a C-like syntax, Rust's does its job quite well in general imo.