Resynthesize foo<bar>( and foo<bar>:: in check_no_chained_comparison by xizheyin · Pull Request #144884 · rust-lang/rust (original) (raw)

This PR addresses a FIXME in parser/diagnostics.rs.

When detecting mistyped turbofish syntax (e.g., foo<bar>() instead of foo::<bar>()), the parser would always generate an ExprKind::Err placeholder without validating the expressions & attempting recovery.

The parser now checks that both sides of the binary operation are actually path expressions before proceeding and reconstructs the intended expression when it's safe to do so.

PathSep Branch (Type<Generic>::method() patterns)

For expressions like Vec<i32>::new():
It V=validates that both sides of the comparison are path expressions, and reconstructs the corrected path prefix (Vec::<i32>). And then, it merges the corrected path with the parsed suffix (new()). Finally, it return corrected expression Vec::<i32>::new().

OpenParen Branch (func<arg>() patterns)

For expressions like my_func<T>(). It validates path expressions, and Reconstructs the complete function call with proper turbofish syntax.

r? @estebank