Commit f538b42
authored
Rollup merge of rust-lang#119562 - LegionMammal978:rename-pin-pointer, r=Amanieu,dtolnay
Rename `pointer` field on `Pin`
A few days ago, I was helping another user create a self-referential type using `PhantomPinned`. However, I noticed an odd behavior when I tried to access one of the type's fields via `Pin`'s `Deref` impl:
```rust
use std::{marker::PhantomPinned, ptr};
struct Pinned {
data: i32,
pointer: *const i32,
_pin: PhantomPinned,
}
fn main() {
let mut b = Box::pin(Pinned {
data: 42,
pointer: ptr::null(),
_pin: PhantomPinned,
});
{
let pinned = unsafe { b.as_mut().get_unchecked_mut() };
pinned.pointer = &pinned.data;
}
println!("{}", unsafe { *b.pointer });
}
```
```rust
error[E0658]: use of unstable library feature 'unsafe_pin_internals'
--> <source>:19:30
|
19 | println!("{}", unsafe { *b.pointer });
| ^^^^^^^^^
error[E0277]: `Pinned` doesn't implement `std::fmt::Display`
--> <source>:19:20
|
19 | println!("{}", unsafe { *b.pointer });
| ^^^^^^^^^^^^^^^^^^^^^ `Pinned` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Pinned`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
```
Since the user named their field `pointer`, it conflicts with the `pointer` field on `Pin`, which is public but unstable since Rust 1.60.0 with rust-lang#93176. On versions from 1.33.0 to 1.59.0, where the field on `Pin` is private, this program compiles and prints `42` as expected.
To avoid this confusing behavior, this PR renames `pointer` to `__pointer`, so that it's less likely to conflict with a `pointer` field on the underlying type, as accessed through the `Deref` impl. This is technically a breaking change for anyone who names their field `__pointer` on the inner type; if this is undesirable, it could be renamed to something more longwinded. It's also a nightly breaking change for any external users of `unsafe_pin_internals`.File tree
8 files changed
+35
-29
lines changed- compiler/rustc_hir_typeck/src/fn_ctxt
- library/core/src
- src/etc/natvis
- tests
- mir-opt/inline
- ui
- feature-gates
- pin-macro
8 files changed
+35
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2040 | 2040 | | |
2041 | 2041 | | |
2042 | 2042 | | |
2043 | | - | |
| 2043 | + | |
2044 | 2044 | | |
2045 | 2045 | | |
2046 | 2046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1092 | 1092 | | |
1093 | 1093 | | |
1094 | 1094 | | |
1095 | | - | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
1096 | 1102 | | |
1097 | 1103 | | |
1098 | | - | |
| 1104 | + | |
1099 | 1105 | | |
1100 | 1106 | | |
1101 | 1107 | | |
1102 | | - | |
| 1108 | + | |
1103 | 1109 | | |
1104 | 1110 | | |
1105 | 1111 | | |
| |||
1212 | 1218 | | |
1213 | 1219 | | |
1214 | 1220 | | |
1215 | | - | |
| 1221 | + | |
1216 | 1222 | | |
1217 | 1223 | | |
1218 | 1224 | | |
| |||
1349 | 1355 | | |
1350 | 1356 | | |
1351 | 1357 | | |
1352 | | - | |
| 1358 | + | |
1353 | 1359 | | |
1354 | 1360 | | |
1355 | 1361 | | |
| |||
1363 | 1369 | | |
1364 | 1370 | | |
1365 | 1371 | | |
1366 | | - | |
| 1372 | + | |
1367 | 1373 | | |
1368 | 1374 | | |
1369 | 1375 | | |
| |||
1388 | 1394 | | |
1389 | 1395 | | |
1390 | 1396 | | |
1391 | | - | |
| 1397 | + | |
1392 | 1398 | | |
1393 | 1399 | | |
1394 | 1400 | | |
| |||
1426 | 1432 | | |
1427 | 1433 | | |
1428 | 1434 | | |
1429 | | - | |
| 1435 | + | |
1430 | 1436 | | |
1431 | 1437 | | |
1432 | 1438 | | |
| |||
1455 | 1461 | | |
1456 | 1462 | | |
1457 | 1463 | | |
1458 | | - | |
| 1464 | + | |
1459 | 1465 | | |
1460 | 1466 | | |
1461 | 1467 | | |
| |||
1481 | 1487 | | |
1482 | 1488 | | |
1483 | 1489 | | |
1484 | | - | |
| 1490 | + | |
1485 | 1491 | | |
1486 | 1492 | | |
1487 | 1493 | | |
| |||
1511 | 1517 | | |
1512 | 1518 | | |
1513 | 1519 | | |
1514 | | - | |
| 1520 | + | |
1515 | 1521 | | |
1516 | 1522 | | |
1517 | 1523 | | |
| |||
1522 | 1528 | | |
1523 | 1529 | | |
1524 | 1530 | | |
1525 | | - | |
| 1531 | + | |
1526 | 1532 | | |
1527 | 1533 | | |
1528 | 1534 | | |
| |||
1542 | 1548 | | |
1543 | 1549 | | |
1544 | 1550 | | |
1545 | | - | |
| 1551 | + | |
1546 | 1552 | | |
1547 | 1553 | | |
1548 | 1554 | | |
| |||
1560 | 1566 | | |
1561 | 1567 | | |
1562 | 1568 | | |
1563 | | - | |
| 1569 | + | |
1564 | 1570 | | |
1565 | 1571 | | |
1566 | 1572 | | |
| |||
1684 | 1690 | | |
1685 | 1691 | | |
1686 | 1692 | | |
1687 | | - | |
| 1693 | + | |
1688 | 1694 | | |
1689 | 1695 | | |
1690 | 1696 | | |
1691 | 1697 | | |
1692 | 1698 | | |
1693 | 1699 | | |
1694 | | - | |
| 1700 | + | |
1695 | 1701 | | |
1696 | 1702 | | |
1697 | 1703 | | |
1698 | 1704 | | |
1699 | 1705 | | |
1700 | 1706 | | |
1701 | | - | |
| 1707 | + | |
1702 | 1708 | | |
1703 | 1709 | | |
1704 | 1710 | | |
| |||
1941 | 1947 | | |
1942 | 1948 | | |
1943 | 1949 | | |
1944 | | - | |
| 1950 | + | |
1945 | 1951 | | |
1946 | 1952 | | |
1947 | 1953 | | |
1948 | 1954 | | |
1949 | | - | |
| 1955 | + | |
1950 | 1956 | | |
1951 | 1957 | | |
1952 | 1958 | | |
1953 | 1959 | | |
1954 | 1960 | | |
1955 | | - | |
| 1961 | + | |
1956 | 1962 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments