Skip to content

nightly-2024-07-26: feat: turbofish operator on path segments (#5603)

Pre-release
Pre-release
Compare
Choose a tag to compare
@github-actions github-actions released this 26 Jul 02:19
· 972 commits to master since this release
0bb8372
# Description

## Problem

Part of #5584

## Summary

This PR adds support for parsing turbofishes in any path segments.
Turbofish is only still checked when elaborating variables, but only for
the last turbofish (like before). For now any other placement of a
turbofish will give a type error, but at least they can be parsed now.
In later PRs we can make them work in the middle of variables, in
constructors, etc.

## Additional Context

Right now turbofishes aren't parsed in named typed (for example in a
struct pattern). The reason is that if I use `path()` instead of
`path_no_turbofish()` then the parser gives a stack overflow and I'm not
sure why. Maybe it's because `parse_type()` is used recursively, I'm not
sure... but these stack overflow errors are kind of hard to diagnose. In
any case we can parse those later on once we decide to support turbofish
in struct patterns.

Also, because a `Path`'s segments changed from `Vec<Ident>` to
`Vec<PathSegment>` some functions, like `Path::last_segment()` made more
sense if they returned `PathSegment` instead of `Ident`. Then I
introduced a bunch of helper functions to reduce some call chains, but
also introduced helpers like `last_name()` which is nice because it
returns a `&str` where in some cases an unnecessary clone was made (so
some refactors/cleanups are included in this PR as part of this
feature).

## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [x] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.