reference icon indicating copy to clipboard operation
reference copied to clipboard

Elaborate on relative precedence between method calls and field accesses

Open Rua opened this issue 1 month ago • 1 comments

Currently, the precedence table lists method calls higher than field accesses. Which gives the impression that for example a.b.c() is parsed as a.(b.c()) rather than the correct (a.b).c(). I don't know if that's an actual error in the table (seems unlikely?) or that the writers had a different interpretation in mind than I do. Either way, it would be useful to clarify how this is actually intended.

Rua avatar Nov 08 '25 17:11 Rua

struct Foo { bar: Bar, }

impl Foo { fn get_bar(&self) -> &Bar { &self.bar } }

struct Bar;

impl Bar { fn greet(&self) { println!("Hello!"); } }

fn main() { let foo = Foo { bar: Bar }; foo.bar.greet(); // ✅ parsed as (foo.bar).greet() foo.get_bar().greet(); // ✅ method call then field access }

Jstey avatar Nov 08 '25 18:11 Jstey