Use derivative
for better derive bounds
This commit is contained in:
parent
c1fc1d18cd
commit
c6aa16c469
@ -4340,6 +4340,7 @@ dependencies = [
|
|||||||
name = "rustc_pattern_analysis"
|
name = "rustc_pattern_analysis"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"derivative",
|
||||||
"rustc_apfloat",
|
"rustc_apfloat",
|
||||||
"rustc_arena",
|
"rustc_arena",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
@ -5,6 +5,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
|
derivative = "2.2.0"
|
||||||
rustc_apfloat = "0.2.0"
|
rustc_apfloat = "0.2.0"
|
||||||
rustc_arena = { path = "../rustc_arena", optional = true }
|
rustc_arena = { path = "../rustc_arena", optional = true }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
||||||
|
@ -642,7 +642,8 @@ impl OpaqueId {
|
|||||||
/// `specialize_constructor` returns the list of fields corresponding to a pattern, given a
|
/// `specialize_constructor` returns the list of fields corresponding to a pattern, given a
|
||||||
/// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and
|
/// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and
|
||||||
/// `Fields`.
|
/// `Fields`.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Debug(bound = ""), Clone(bound = ""), PartialEq(bound = ""))]
|
||||||
pub enum Constructor<Cx: TypeCx> {
|
pub enum Constructor<Cx: TypeCx> {
|
||||||
/// Tuples and structs.
|
/// Tuples and structs.
|
||||||
Struct,
|
Struct,
|
||||||
|
@ -49,7 +49,7 @@ impl<'a, T: ?Sized> Captures<'a> for T {}
|
|||||||
/// Context that provides type information about constructors.
|
/// Context that provides type information about constructors.
|
||||||
///
|
///
|
||||||
/// Most of the crate is parameterized on a type that implements this trait.
|
/// Most of the crate is parameterized on a type that implements this trait.
|
||||||
pub trait TypeCx: Sized + Clone + fmt::Debug {
|
pub trait TypeCx: Sized + fmt::Debug {
|
||||||
/// The type of a pattern.
|
/// The type of a pattern.
|
||||||
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
|
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
|
||||||
/// The index of an enum variant.
|
/// The index of an enum variant.
|
||||||
@ -86,7 +86,8 @@ pub trait TypeCx: Sized + Clone + fmt::Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Context that provides information global to a match.
|
/// Context that provides information global to a match.
|
||||||
#[derive(Clone)]
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Clone(bound = ""), Copy(bound = ""))]
|
||||||
pub struct MatchCtxt<'a, 'p, Cx: TypeCx> {
|
pub struct MatchCtxt<'a, 'p, Cx: TypeCx> {
|
||||||
/// The context for type information.
|
/// The context for type information.
|
||||||
pub tycx: &'a Cx,
|
pub tycx: &'a Cx,
|
||||||
@ -94,18 +95,16 @@ pub struct MatchCtxt<'a, 'p, Cx: TypeCx> {
|
|||||||
pub wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
|
pub wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'p, Cx: TypeCx> Copy for MatchCtxt<'a, 'p, Cx> {}
|
|
||||||
|
|
||||||
/// The arm of a match expression.
|
/// The arm of a match expression.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Debug)]
|
||||||
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Clone(bound = ""), Copy(bound = ""))]
|
||||||
pub struct MatchArm<'p, Cx: TypeCx> {
|
pub struct MatchArm<'p, Cx: TypeCx> {
|
||||||
pub pat: &'p DeconstructedPat<'p, Cx>,
|
pub pat: &'p DeconstructedPat<'p, Cx>,
|
||||||
pub has_guard: bool,
|
pub has_guard: bool,
|
||||||
pub arm_data: Cx::ArmData,
|
pub arm_data: Cx::ArmData,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'p, Cx: TypeCx> Copy for MatchArm<'p, Cx> {}
|
|
||||||
|
|
||||||
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
|
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
|
||||||
/// useful, and runs some lints.
|
/// useful, and runs some lints.
|
||||||
#[cfg(feature = "rustc")]
|
#[cfg(feature = "rustc")]
|
||||||
|
@ -160,7 +160,8 @@ impl<'p, Cx: TypeCx> fmt::Debug for DeconstructedPat<'p, Cx> {
|
|||||||
|
|
||||||
/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
|
/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
|
||||||
/// purposes. As such they don't use interning and can be cloned.
|
/// purposes. As such they don't use interning and can be cloned.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Debug(bound = ""), Clone(bound = ""))]
|
||||||
pub struct WitnessPat<Cx: TypeCx> {
|
pub struct WitnessPat<Cx: TypeCx> {
|
||||||
ctor: Constructor<Cx>,
|
ctor: Constructor<Cx>,
|
||||||
pub(crate) fields: Vec<WitnessPat<Cx>>,
|
pub(crate) fields: Vec<WitnessPat<Cx>>,
|
||||||
|
@ -569,8 +569,10 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Context that provides information local to a place under investigation.
|
/// Context that provides information local to a place under investigation.
|
||||||
#[derive(Clone)]
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Debug(bound = ""), Clone(bound = ""), Copy(bound = ""))]
|
||||||
pub(crate) struct PlaceCtxt<'a, 'p, Cx: TypeCx> {
|
pub(crate) struct PlaceCtxt<'a, 'p, Cx: TypeCx> {
|
||||||
|
#[derivative(Debug = "ignore")]
|
||||||
pub(crate) mcx: MatchCtxt<'a, 'p, Cx>,
|
pub(crate) mcx: MatchCtxt<'a, 'p, Cx>,
|
||||||
/// Type of the place under investigation.
|
/// Type of the place under investigation.
|
||||||
pub(crate) ty: Cx::Ty,
|
pub(crate) ty: Cx::Ty,
|
||||||
@ -596,14 +598,6 @@ impl<'a, 'p, Cx: TypeCx> PlaceCtxt<'a, 'p, Cx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'p, Cx: TypeCx> Copy for PlaceCtxt<'a, 'p, Cx> {}
|
|
||||||
|
|
||||||
impl<'a, 'p, Cx: TypeCx> fmt::Debug for PlaceCtxt<'a, 'p, Cx> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("PlaceCtxt").field("ty", &self.ty).finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serves two purposes:
|
/// Serves two purposes:
|
||||||
/// - in a wildcard, tracks whether the wildcard matches only valid values (i.e. is a binding `_a`)
|
/// - in a wildcard, tracks whether the wildcard matches only valid values (i.e. is a binding `_a`)
|
||||||
/// or also invalid values (i.e. is a true `_` pattern).
|
/// or also invalid values (i.e. is a true `_` pattern).
|
||||||
@ -670,7 +664,8 @@ impl fmt::Display for ValidityConstraint {
|
|||||||
// - 'a allocated by us
|
// - 'a allocated by us
|
||||||
// - 'p coming from the input
|
// - 'p coming from the input
|
||||||
// - Cx global compilation context
|
// - Cx global compilation context
|
||||||
#[derive(Clone)]
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Clone(bound = ""))]
|
||||||
struct PatStack<'a, 'p, Cx: TypeCx> {
|
struct PatStack<'a, 'p, Cx: TypeCx> {
|
||||||
// Rows of len 1 are very common, which is why `SmallVec[_; 2]` works well.
|
// Rows of len 1 are very common, which is why `SmallVec[_; 2]` works well.
|
||||||
pats: SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]>,
|
pats: SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]>,
|
||||||
@ -1022,7 +1017,8 @@ impl<'a, 'p, Cx: TypeCx> fmt::Debug for Matrix<'a, 'p, Cx> {
|
|||||||
/// The final `Pair(Some(_), true)` is then the resulting witness.
|
/// The final `Pair(Some(_), true)` is then the resulting witness.
|
||||||
///
|
///
|
||||||
/// See the top of the file for more detailed explanations and examples.
|
/// See the top of the file for more detailed explanations and examples.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Debug(bound = ""), Clone(bound = ""))]
|
||||||
struct WitnessStack<Cx: TypeCx>(Vec<WitnessPat<Cx>>);
|
struct WitnessStack<Cx: TypeCx>(Vec<WitnessPat<Cx>>);
|
||||||
|
|
||||||
impl<Cx: TypeCx> WitnessStack<Cx> {
|
impl<Cx: TypeCx> WitnessStack<Cx> {
|
||||||
@ -1069,7 +1065,8 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
|
|||||||
///
|
///
|
||||||
/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
|
/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
|
||||||
/// column, which contains the patterns that are missing for the match to be exhaustive.
|
/// column, which contains the patterns that are missing for the match to be exhaustive.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(derivative::Derivative)]
|
||||||
|
#[derivative(Debug(bound = ""), Clone(bound = ""))]
|
||||||
struct WitnessMatrix<Cx: TypeCx>(Vec<WitnessStack<Cx>>);
|
struct WitnessMatrix<Cx: TypeCx>(Vec<WitnessStack<Cx>>);
|
||||||
|
|
||||||
impl<Cx: TypeCx> WitnessMatrix<Cx> {
|
impl<Cx: TypeCx> WitnessMatrix<Cx> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user