Commit d845685
committed
Suggest replacing
When encountering a type error caused by the use of `Self`, suggest
using the actual type name instead.
```
error[E0308]: mismatched types
--> $DIR/struct-path-self-type-mismatch.rs:13:9
|
LL | impl<T> Foo<T> {
| - ------ this is the type of the `Self` literal
| |
| found type parameter
LL | fn new<U>(u: U) -> Foo<U> {
| - ------ expected `Foo<U>` because of return type
| |
| expected type parameter
LL | / Self {
LL | |
LL | | inner: u
LL | |
LL | | }
| |_________^ expected `Foo<U>`, found `Foo<T>`
|
= note: expected struct `Foo<U>`
found struct `Foo<T>`
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
help: use the type name directly
|
LL | Foo::<U> {
| ~~~~~~~~
```
Fix rust-lang#76086.Self with the right type on type error1 parent a7e035a commit d845685
File tree
2 files changed
+27
-4
lines changed- compiler/rustc_hir_typeck/src
- tests/ui/structs
2 files changed
+27
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
1738 | 1740 | | |
1739 | 1741 | | |
1740 | 1742 | | |
1741 | | - | |
| 1743 | + | |
1742 | 1744 | | |
1743 | 1745 | | |
1744 | 1746 | | |
| |||
1816 | 1818 | | |
1817 | 1819 | | |
1818 | 1820 | | |
| 1821 | + | |
| 1822 | + | |
1819 | 1823 | | |
1820 | 1824 | | |
1821 | 1825 | | |
1822 | 1826 | | |
1823 | 1827 | | |
1824 | | - | |
| 1828 | + | |
1825 | 1829 | | |
1826 | 1830 | | |
1827 | 1831 | | |
| |||
1830 | 1834 | | |
1831 | 1835 | | |
1832 | 1836 | | |
1833 | | - | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
1834 | 1842 | | |
1835 | 1843 | | |
1836 | 1844 | | |
| |||
1843 | 1851 | | |
1844 | 1852 | | |
1845 | 1853 | | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
1846 | 1865 | | |
1847 | 1866 | | |
1848 | 1867 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
0 commit comments