@@ -1566,33 +1566,6 @@ It is not possible to use stability attributes outside of the standard library.
15661566Also, for now, it is not possible to write deprecation messages either.
15671567"## ,
15681568
1569- E0512 : r##"
1570- Transmute with two differently sized types was attempted. Erroneous code
1571- example:
1572-
1573- ```compile_fail,E0512
1574- fn takes_u8(_: u8) {}
1575-
1576- fn main() {
1577- unsafe { takes_u8(::std::mem::transmute(0u16)); }
1578- // error: cannot transmute between types of different sizes,
1579- // or dependently-sized types
1580- }
1581- ```
1582-
1583- Please use types with same size or use the expected type directly. Example:
1584-
1585- ```
1586- fn takes_u8(_: u8) {}
1587-
1588- fn main() {
1589- unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
1590- // or:
1591- unsafe { takes_u8(0u8); } // ok!
1592- }
1593- ```
1594- "## ,
1595-
15961569E0517 : r##"
15971570This error indicates that a `#[repr(..)]` attribute was placed on an
15981571unsupported item.
@@ -1787,84 +1760,6 @@ See [RFC 1522] for more details.
17871760[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
17881761"## ,
17891762
1790- E0591 : r##"
1791- Per [RFC 401][rfc401], if you have a function declaration `foo`:
1792-
1793- ```
1794- // For the purposes of this explanation, all of these
1795- // different kinds of `fn` declarations are equivalent:
1796- struct S;
1797- fn foo(x: S) { /* ... */ }
1798- # #[cfg(for_demonstration_only)]
1799- extern "C" { fn foo(x: S); }
1800- # #[cfg(for_demonstration_only)]
1801- impl S { fn foo(self) { /* ... */ } }
1802- ```
1803-
1804- the type of `foo` is **not** `fn(S)`, as one might expect.
1805- Rather, it is a unique, zero-sized marker type written here as `typeof(foo)`.
1806- However, `typeof(foo)` can be _coerced_ to a function pointer `fn(S)`,
1807- so you rarely notice this:
1808-
1809- ```
1810- # struct S;
1811- # fn foo(_: S) {}
1812- let x: fn(S) = foo; // OK, coerces
1813- ```
1814-
1815- The reason that this matter is that the type `fn(S)` is not specific to
1816- any particular function: it's a function _pointer_. So calling `x()` results
1817- in a virtual call, whereas `foo()` is statically dispatched, because the type
1818- of `foo` tells us precisely what function is being called.
1819-
1820- As noted above, coercions mean that most code doesn't have to be
1821- concerned with this distinction. However, you can tell the difference
1822- when using **transmute** to convert a fn item into a fn pointer.
1823-
1824- This is sometimes done as part of an FFI:
1825-
1826- ```compile_fail,E0591
1827- extern "C" fn foo(userdata: Box<i32>) {
1828- /* ... */
1829- }
1830-
1831- # fn callback(_: extern "C" fn(*mut i32)) {}
1832- # use std::mem::transmute;
1833- # unsafe {
1834- let f: extern "C" fn(*mut i32) = transmute(foo);
1835- callback(f);
1836- # }
1837- ```
1838-
1839- Here, transmute is being used to convert the types of the fn arguments.
1840- This pattern is incorrect because, because the type of `foo` is a function
1841- **item** (`typeof(foo)`), which is zero-sized, and the target type (`fn()`)
1842- is a function pointer, which is not zero-sized.
1843- This pattern should be rewritten. There are a few possible ways to do this:
1844-
1845- - change the original fn declaration to match the expected signature,
1846- and do the cast in the fn body (the preferred option)
1847- - cast the fn item fo a fn pointer before calling transmute, as shown here:
1848-
1849- ```
1850- # extern "C" fn foo(_: Box<i32>) {}
1851- # use std::mem::transmute;
1852- # unsafe {
1853- let f: extern "C" fn(*mut i32) = transmute(foo as extern "C" fn(_));
1854- let f: extern "C" fn(*mut i32) = transmute(foo as usize); // works too
1855- # }
1856- ```
1857-
1858- The same applies to transmutes to `*mut fn()`, which were observed in practice.
1859- Note though that use of this type is generally incorrect.
1860- The intention is typically to describe a function pointer, but just `fn()`
1861- alone suffices for that. `*mut fn()` is a pointer to a fn pointer.
1862- (Since these values are typically just passed to C code, however, this rarely
1863- makes a difference in practice.)
1864-
1865- [rfc401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1866- "## ,
1867-
18681763E0593 : r##"
18691764You tried to supply an `Fn`-based type with an incorrect number of arguments
18701765than what was expected.
0 commit comments