That's not a particularly hard problem, all tools which try to solve it (for example, IntelliJ), solve it easily. For example, here's the syntax tree that rust-analyzer builds for this example:
fn foo() { }
fn
fn bar() { }
Syntax tree (whitespace nodes elided for clarity):
When llvm was young, one of its design goals was to be useful for live code analysis, to prevent that problem of having two parsers that might not agree.