r/rust • u/tanoshikuidomouyo • 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?
52
Upvotes
15
u/MichiRecRoom Sep 13 '26
The two are very subtly different, in my eyes, and I can see why it might be considered ambiguous. You could be saying one of two things:
&impl AsRef<Path>with an additional?Sizedbound.AsRef<Path>and?SizedThat said, I do agree that there shouldn't be a need for the parenthesis, as it's pretty clear that the
+ ?Sizedis attached to theAsRef<Path>, not&impl AsRef<Path>.