Skip to content

Commit a739e9d

Browse files
committed
comments
1 parent c10c973 commit a739e9d

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,10 +2496,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24962496
}
24972497

24982498
if mutability.is_not() {
2499-
// FIXME: for shared reborrow we need to relate the types manually,
2500-
// field by field with CoerceShared drilling down and down and down.
2501-
// We cannot just attempt to relate T and <T as CoerceShared>::Target
2502-
// by calling relate_types.
2499+
// FIXME(@aapoalas): for CoerceShared we need to relate the types manually, field by
2500+
// field. We cannot just attempt to relate `T` and `<T as CoerceShared>::Target` by
2501+
// calling relate_types as they are (generally) two unrelated user-defined ADTs, such as
2502+
// `CustomMut<'a>` and `CustomRef<'a>`, or `CustomMut<'a, T>` and `CustomRef<'a, T>`.
2503+
// Field-by-field relate_types is expected to work based on the wf-checks that the
2504+
// CoerceShared trait performs.
25032505
let ty::Adt(dest_adt, dest_args) = dest_ty.kind() else { unreachable!() };
25042506
let ty::Adt(borrowed_adt, borrowed_args) = borrowed_ty.kind() else { unreachable!() };
25052507
let borrowed_fields = borrowed_adt.all_fields().collect::<Vec<_>>();

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,11 +1474,15 @@ pub enum Rvalue<'tcx> {
14741474
WrapUnsafeBinder(Operand<'tcx>, Ty<'tcx>),
14751475

14761476
/// Creates a bitwise copy of the indicated place with the same type (if Mut) or its
1477-
/// CoerceShared target type (if Not), and disables the place for writes (and reads, if Mut) for
1478-
/// the copy's lifetime. The type is known to be an ADT with exactly one lifetime parameter, and
1479-
/// it is known to implement the Reborrow trait (for Mut), and the CoerceShared trait (only if
1480-
/// Not). The CoerceShared target type is known to implement Copy and have the same memory
1481-
/// layout as the source type.
1477+
/// CoerceShared target type (if Not). The type is known to be an ADT with exactly one lifetime
1478+
/// parameter, and it is known to implement the Reborrow trait (for Mut), and the CoerceShared
1479+
/// trait (only if Not). The CoerceShared target type is known to also have exactly one lifetime
1480+
/// parameter, implement Copy and (currently) have the same memory layout as the source type.
1481+
///
1482+
/// The borrow checker uses the single lifetime in the source and target types to create a
1483+
/// Covariant outlives-bound between the source and target with the Mutability of the Reborrow.
1484+
/// This makes accessing the source value for writes (and reads if Mut) for the lifetime of the
1485+
/// target value a borrow check error, imitating `&mut T` and `&T`'s reborrowing on user ADTs.
14821486
///
14831487
/// Future work may add support for multiple lifetimes and changing memory layout as part of
14841488
/// CoerceShared. These may be end up implemented as multiple MIR operations.

0 commit comments

Comments
 (0)