Skip to content

Commit 337fbb4

Browse files
committed
Clean up comments about the Can[Trivially]Derive* traits
The whole "should be a no-op" thing isn't really true for all of the traits, especially in the face of black listing. Also further expounded on the differences between the trivial versions and normal versions.
1 parent 508d917 commit 337fbb4

File tree

1 file changed

+43
-78
lines changed

1 file changed

+43
-78
lines changed

src/ir/derive.rs

Lines changed: 43 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
//! Traits for determining whether we can derive traits for a thing or not.
2+
//!
3+
//! These traits tend to come in pairs:
4+
//!
5+
//! 1. A "trivial" version, whose implementations aren't allowed to recursively
6+
//! look at other types or the results of fix point analyses.
7+
//!
8+
//! 2. A "normal" version, whose implementations simply query the results of a
9+
//! fix point analysis.
10+
//!
11+
//! The former is used by the analyses when creating the results queried by the
12+
//! second.
213
314
use super::context::BindgenContext;
415

516
/// A trait that encapsulates the logic for whether or not we can derive `Debug`
617
/// for a given thing.
7-
///
8-
/// This should ideally be a no-op that just returns `true`, but instead needs
9-
/// to be a recursive method that checks whether all the proper members can
10-
/// derive debug or not, because of the limit rust has on 32 items as max in the
11-
/// array.
1218
pub trait CanDeriveDebug {
1319
/// Return `true` if `Debug` can be derived for this thing, `false`
1420
/// otherwise.
1521
fn can_derive_debug(&self, ctx: &BindgenContext) -> bool;
1622
}
1723

18-
/// A trait that encapsulates the logic for whether or not we can derive `Debug`.
19-
/// The difference between this trait and the CanDeriveDebug is that the type
20-
/// implementing this trait cannot use recursion or lookup result from fix point
21-
/// analysis. It's a helper trait for fix point analysis.
24+
/// A trait that encapsulates the logic for whether or not we can trivially
25+
/// derive `Debug` without looking at any other types or the results of a fix
26+
/// point analysis. This is a helper trait for the fix point analysis.
2227
pub trait CanTriviallyDeriveDebug {
23-
/// Return `true` if `Debug` can be derived for this thing, `false`
24-
/// otherwise.
28+
/// Return `true` if `Debug` can trivially be derived for this thing,
29+
/// `false` otherwise.
2530
fn can_trivially_derive_debug(&self) -> bool;
2631
}
2732

@@ -33,72 +38,50 @@ pub trait CanDeriveCopy<'a> {
3338
fn can_derive_copy(&'a self, ctx: &'a BindgenContext) -> bool;
3439
}
3540

36-
/// A trait that encapsulates the logic for whether or not we can derive `Copy`.
37-
/// The difference between this trait and the CanDeriveCopy is that the type
38-
/// implementing this trait cannot use recursion or lookup result from fix point
39-
/// analysis. It's a helper trait for fix point analysis.
41+
/// A trait that encapsulates the logic for whether or not we can trivially
42+
/// derive `Copy` without looking at any other types or results of fix point
43+
/// analsyses. This is a helper trait for fix point analysis.
4044
pub trait CanTriviallyDeriveCopy {
41-
/// Return `true` if `Copy` can be derived for this thing, `false`
45+
/// Return `true` if `Copy` can be trivially derived for this thing, `false`
4246
/// otherwise.
4347
fn can_trivially_derive_copy(&self) -> bool;
4448
}
4549

46-
/// A trait that encapsulates the logic for whether or not we can derive `Default`
47-
/// for a given thing.
48-
///
49-
/// This should ideally be a no-op that just returns `true`, but instead needs
50-
/// to be a recursive method that checks whether all the proper members can
51-
/// derive default or not, because of the limit rust has on 32 items as max in the
52-
/// array.
50+
/// A trait that encapsulates the logic for whether or not we can derive
51+
/// `Default` for a given thing.
5352
pub trait CanDeriveDefault {
5453
/// Return `true` if `Default` can be derived for this thing, `false`
5554
/// otherwise.
5655
fn can_derive_default(&self, ctx: &BindgenContext) -> bool;
5756
}
5857

59-
/// A trait that encapsulates the logic for whether or not we can derive `Default`.
60-
/// The difference between this trait and the CanDeriveDefault is that the type
61-
/// implementing this trait cannot use recursion or lookup result from fix point
62-
/// analysis. It's a helper trait for fix point analysis.
58+
/// A trait that encapsulates the logic for whether or not we can trivially
59+
/// derive `Default` without looking at any other types or results of fix point
60+
/// analyses. This is a helper trait for the fix point analysis.
6361
pub trait CanTriviallyDeriveDefault {
64-
/// Return `true` if `Default` can be derived for this thing, `false`
62+
/// Return `true` if `Default` can trivially derived for this thing, `false`
6563
/// otherwise.
6664
fn can_trivially_derive_default(&self) -> bool;
6765
}
6866

6967
/// A trait that encapsulates the logic for whether or not we can derive `Hash`
7068
/// for a given thing.
71-
///
72-
/// This should ideally be a no-op that just returns `true`, but instead needs
73-
/// to be a recursive method that checks whether all the proper members can
74-
/// derive default or not, because of the limit rust has on 32 items as max in the
75-
/// array.
7669
pub trait CanDeriveHash {
77-
/// Return `true` if `Default` can be derived for this thing, `false`
70+
/// Return `true` if `Hash` can be derived for this thing, `false`
7871
/// otherwise.
7972
fn can_derive_hash(&self, ctx: &BindgenContext) -> bool;
8073
}
8174

82-
/// A trait that encapsulates the logic for whether or not we can derive `PartialEq`
83-
/// for a given thing.
84-
///
85-
/// This should ideally be a no-op that just returns `true`, but instead needs
86-
/// to be a recursive method that checks whether all the proper members can
87-
/// derive default or not, because of the limit rust has on 32 items as max in the
88-
/// array.
75+
/// A trait that encapsulates the logic for whether or not we can derive
76+
/// `PartialEq` for a given thing.
8977
pub trait CanDerivePartialEq {
9078
/// Return `true` if `PartialEq` can be derived for this thing, `false`
9179
/// otherwise.
9280
fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool;
9381
}
9482

95-
/// A trait that encapsulates the logic for whether or not we can derive `PartialOrd`
96-
/// for a given thing.
97-
///
98-
/// This should ideally be a no-op that just returns `true`, but instead needs
99-
/// to be a recursive method that checks whether all the proper members can
100-
/// derive partial ord or not, because of the limit rust has on 32 items as max in the
101-
/// array.
83+
/// A trait that encapsulates the logic for whether or not we can derive
84+
/// `PartialOrd` for a given thing.
10285
pub trait CanDerivePartialOrd {
10386
/// Return `true` if `PartialOrd` can be derived for this thing, `false`
10487
/// otherwise.
@@ -107,50 +90,32 @@ pub trait CanDerivePartialOrd {
10790

10891
/// A trait that encapsulates the logic for whether or not we can derive `Eq`
10992
/// for a given thing.
110-
///
111-
/// This should ideally be a no-op that just returns `true`, but instead needs
112-
/// to be a recursive method that checks whether all the proper members can
113-
/// derive eq or not, because of the limit rust has on 32 items as max in the
114-
/// array.
11593
pub trait CanDeriveEq {
116-
117-
/// Return `true` if `Eq` can be derived for this thing, `false`
118-
/// otherwise.
119-
fn can_derive_eq(&self,
120-
ctx: &BindgenContext)
121-
-> bool;
94+
/// Return `true` if `Eq` can be derived for this thing, `false` otherwise.
95+
fn can_derive_eq(&self, ctx: &BindgenContext) -> bool;
12296
}
12397

12498
/// A trait that encapsulates the logic for whether or not we can derive `Ord`
12599
/// for a given thing.
126-
///
127-
/// This should ideally be a no-op that just returns `true`, but instead needs
128-
/// to be a recursive method that checks whether all the proper members can
129-
/// derive ord or not, because of the limit rust has on 32 items as max in the
130-
/// array.
131100
pub trait CanDeriveOrd {
132-
/// Return `true` if `Ord` can be derived for this thing, `false`
133-
/// otherwise.
101+
/// Return `true` if `Ord` can be derived for this thing, `false` otherwise.
134102
fn can_derive_ord(&self, ctx: &BindgenContext) -> bool;
135103
}
136104

137-
/// A trait that encapsulates the logic for whether or not we can derive `Hash`.
138-
/// The difference between this trait and the CanDeriveHash is that the type
139-
/// implementing this trait cannot use recursion or lookup result from fix point
140-
/// analysis. It's a helper trait for fix point analysis.
105+
/// A trait that encapsulates the logic for whether or not we can derive `Hash`
106+
/// without looking at any other types or the results of any fix point
107+
/// analyses. This is a helper trait for the fix point analysis.
141108
pub trait CanTriviallyDeriveHash {
142-
/// Return `true` if `Hash` can be derived for this thing, `false`
109+
/// Return `true` if `Hash` can trivially be derived for this thing, `false`
143110
/// otherwise.
144111
fn can_trivially_derive_hash(&self) -> bool;
145112
}
146113

147-
/// A trait that encapsulates the logic for whether or not we can derive
148-
/// `PartialEq` or `PartialOrd`. The difference between this trait and the
149-
/// CanDerivePartialEq is that the type implementing this trait cannot use
150-
/// recursion or lookup result from fix point analysis. It's a helper trait for
151-
/// fix point analysis.
114+
/// A trait that encapsulates the logic for whether or not we can trivially
115+
/// derive `PartialEq` or `PartialOrd` without looking at any other types or
116+
/// results of fix point analyses. This is a helper for the fix point analysis.
152117
pub trait CanTriviallyDerivePartialEqOrPartialOrd {
153-
/// Return `true` if `PartialEq` or `PartialOrd` can be derived for this
154-
/// thing, `false` otherwise.
118+
/// Return `true` if `PartialEq` or `PartialOrd` can trivially be derived
119+
/// for this thing, `false` otherwise.
155120
fn can_trivially_derive_partialeq_or_partialord(&self) -> bool;
156121
}

0 commit comments

Comments
 (0)