Why isn't `.. . foo()` a valid method-call-expression?

trait A{
    fn foo(&self){}
}
impl<T> A for T{
}
fn main(){
    .. . foo();
}

The compiler says

error: expected one of ; or }, found .

However, according to the syntax in Method call expressions - The Rust Reference

MethodCallExpression

Expression . PathExprSegment ( CallParams? )

The first Expression can be a RangeExpression that is a RangeFullExpr, which matches .. and the single dot matches the dot in MethodCallExpression, and foo is the PathExprSegment

No rules mentioned in the Referenced prohibit this usage. What's the wrong here?

1 Like

I think it is related to this issue: `&..`: unexpected token .. · Issue #25119 · rust-lang/rust · GitHub

This is intentional in rustc. .. is only accepted as expression in locations where a..b would also be accepted.

That is, because the parentheses in &(a..b) are required, they are also required in &(..).

5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.