@@ -811,28 +811,44 @@ pub enum PatKind<'tcx> {
811811 /// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
812812 /// much simpler.
813813 /// * `String`, if `string_deref_patterns` is enabled.
814+ ///
815+ /// # Caution
816+ ///
817+ /// Note that in general, "constants" don't necessarily get lowered to this!
818+ /// For example, a constant of an enum type would typically be lowered to
819+ /// `PatKind::Variant` instead.
814820 Constant {
815821 value : mir:: Const < ' tcx > ,
816822 } ,
817823
818- /// Pattern obtained by converting a constant (inline or named) to its pattern
819- /// representation using `const_to_pat`.
824+ /// Marker node that wraps the result of converting some kind of "constant"
825+ /// (currently either a named constant, or an inline const block) to a
826+ /// pattern.
827+ ///
828+ /// This is needed because constants can potentially be lowered to several
829+ /// different kinds of pattern node (not just `Constant`), but some checks
830+ /// and diagnostics need to know whether a pattern was the result of
831+ /// lowering a constant, and what constant it was.
832+ ///
833+ /// Note that range patterns can potentially contain two constants
834+ /// (one for each endpoint). In that case there might be two nested
835+ /// `ExpandedConstant` nodes wrapping the `Range` node.
820836 ExpandedConstant {
821- /// [DefId] of the constant, we need this so that we have a
822- /// reference that can be used by unsafety checking to visit nested
823- /// unevaluated constants and for diagnostics. If the `DefId` doesn't
824- /// correspond to a local crate, it points at the `const` item.
837+ /// [`DefId`] of the constant that was lowered to the contents of this
838+ /// pattern. This allows code that cares about lowered constants to
839+ /// identify the original constant.
840+ ///
841+ /// For inline const blocks, this should always be a [`LocalDefId`].
825842 def_id : DefId ,
826- /// If `false`, then `def_id` points at a `const` item, otherwise it
827- /// corresponds to a local inline const.
843+
844+ /// - If true, this wrapper represents an inline const block
845+ /// (e.g. `const { 1 + 1 }`).
846+ /// - If false, this wrapper represents a named constant
847+ /// (e.g. `foo::BAR`).
828848 is_inline : bool ,
829- /// If the inline constant is used in a range pattern, this subpattern
830- /// represents the range (if both ends are inline constants, there will
831- /// be multiple InlineConstant wrappers).
832- ///
833- /// Otherwise, the actual pattern that the constant lowered to. As with
834- /// other constants, inline constants are matched structurally where
835- /// possible.
849+
850+ /// The underlying pattern that the constant was lowered to.
851+ /// (Or possibly another `ExpandedConstant`, for range patterns.)
836852 subpattern : Box < Pat < ' tcx > > ,
837853 } ,
838854
0 commit comments