Commit 8df670b
committed
Auto merge of #43540 - petrochenkov:pathrelax, r=nikomatsakis
syntax: Relax path grammar
TLDR: Accept the disambiguator `::` in "type" paths (`Type::<Args>`), accept the disambiguator `::` before parenthesized generic arguments (`Fn::(Args)`).
The "turbofish" disambiguator `::<>` in expression paths is a necessary evil required for path parsing to be both simple and to give reasonable results.
Since paths in expressions usually refer to values (but not necessarily, e.g. `Struct::<u8> { field: 0 }` is disambiguated, but refers to a type), people often consider `::<>` to be inherent to *values*, and not *expressions* and want to write disambiguated paths for values even in contexts where disambiguation is not strictly necessary, for example when a path is passed to a macro `m!(Vec::<i32>::new)`.
The problem is that currently, if the disambiguator is not *required*, then it's *prohibited*. This results in confusion - see #41740, https://internals.rust-lang.org/t/macro-path-uses-novel-syntax/5561.
This PR makes the disambiguator *optional* instead of prohibited in contexts where it's not strictly required, so people can pass paths to macros in whatever form they consider natural (e.g. disambiguated form for value paths).
This PR also accepts the disambiguator in paths with parenthesized arguments (`Fn::(Args)`) for consistency and to simplify testing of stuff like #41856 (comment).
Closes #41740
cc @rust-lang/lang
r? @nikomatsakisFile tree
6 files changed
+49
-44
lines changed- src
- libsyntax
- ext/tt
- parse
- test
- compile-fail
- parse-fail
6 files changed
+49
-44
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
603 | | - | |
604 | | - | |
| 602 | + | |
605 | 603 | | |
606 | 604 | | |
607 | 605 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
1755 | 1755 | | |
1756 | 1756 | | |
1757 | 1757 | | |
1758 | | - | |
| 1758 | + | |
1759 | 1759 | | |
1760 | 1760 | | |
1761 | 1761 | | |
| |||
1770 | 1770 | | |
1771 | 1771 | | |
1772 | 1772 | | |
1773 | | - | |
1774 | | - | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
1775 | 1779 | | |
1776 | 1780 | | |
1777 | 1781 | | |
1778 | 1782 | | |
1779 | 1783 | | |
1780 | 1784 | | |
1781 | 1785 | | |
1782 | | - | |
| 1786 | + | |
1783 | 1787 | | |
1784 | 1788 | | |
1785 | 1789 | | |
| |||
1804 | 1808 | | |
1805 | 1809 | | |
1806 | 1810 | | |
1807 | | - | |
1808 | | - | |
| 1811 | + | |
| 1812 | + | |
1809 | 1813 | | |
1810 | | - | |
| 1814 | + | |
1811 | 1815 | | |
1812 | 1816 | | |
1813 | 1817 | | |
1814 | 1818 | | |
1815 | 1819 | | |
1816 | 1820 | | |
1817 | 1821 | | |
1818 | | - | |
| 1822 | + | |
| 1823 | + | |
1819 | 1824 | | |
1820 | 1825 | | |
1821 | 1826 | | |
| |||
1835 | 1840 | | |
1836 | 1841 | | |
1837 | 1842 | | |
1838 | | - | |
1839 | | - | |
1840 | | - | |
1841 | | - | |
1842 | | - | |
1843 | | - | |
1844 | | - | |
1845 | | - | |
1846 | | - | |
1847 | | - | |
1848 | | - | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
1849 | 1846 | | |
1850 | 1847 | | |
1851 | 1848 | | |
| |||
2382 | 2379 | | |
2383 | 2380 | | |
2384 | 2381 | | |
2385 | | - | |
| 2382 | + | |
2386 | 2383 | | |
2387 | 2384 | | |
2388 | 2385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 22 | + | |
27 | 23 | | |
28 | 24 | | |
29 | 25 | | |
30 | | - | |
| 26 | + | |
31 | 27 | | |
32 | 28 | | |
33 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
11 | 23 | | |
12 | 24 | | |
13 | 25 | | |
14 | 26 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
19 | 32 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 33 | + | |
23 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
Lines changed: 5 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
| 11 | + | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
| |||
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | | - | |
| 22 | + | |
25 | 23 | | |
26 | | - | |
27 | | - | |
| 24 | + | |
| 25 | + | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
0 commit comments