Skip to content

Commit b0b64dd

Browse files
committed
Added comment explaining purpose of search_for_adt_without_structural_match.
1 parent 02af3ca commit b0b64dd

File tree

1 file changed

+24
-0
lines changed
  • src/librustc_mir/hair/pattern

1 file changed

+24
-0
lines changed

src/librustc_mir/hair/pattern/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,30 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
11451145
}
11461146
}
11471147

1148+
/// This method traverses the structure of `ty`, trying to find an
1149+
/// instance of an ADT (i.e. struct or enum) that was declared without
1150+
/// the `#[structural_match]` attribute.
1151+
///
1152+
/// The "structure of a type" includes all components that would be
1153+
/// considered when doing a pattern match on a constant of that
1154+
/// type.
1155+
///
1156+
/// * This means this method descends into fields of structs/enums,
1157+
/// and also descends into the inner type `T` of `&T` and `&mut T`
1158+
///
1159+
/// * The traversal doesn't dereference unsafe pointers (`*const T`,
1160+
/// `*mut T`), and it does not visit the type arguments of an
1161+
/// instantiated generic like `PhantomData<T>`.
1162+
///
1163+
/// The reason we do this search is Rust currently require all ADT's
1164+
/// reachable from a constant's type to be annotated with
1165+
/// `#[structural_match]`, an attribute which essentially says that
1166+
/// the implementation of `PartialEq::eq` behaves *equivalently* to a
1167+
/// comparison against the unfolded structure.
1168+
///
1169+
/// For more background on why Rust has this requirement, and issues
1170+
/// that arose when the requirement was not enforced completely, see
1171+
/// Rust RFC 1445, rust-lang/rust#61188, and rust-lang/rust#62307.
11481172
fn search_for_adt_without_structural_match<'tcx>(tcx: TyCtxt<'tcx>,
11491173
ty: Ty<'tcx>)
11501174
-> Option<&'tcx AdtDef>

0 commit comments

Comments
 (0)