@@ -2093,8 +2093,9 @@ impl<T, E> MaybeResult<T> for Result<T, E> {
2093
2093
2094
2094
pub type TyAndLayout < ' tcx > = rustc_target:: abi:: TyAndLayout < ' tcx , Ty < ' tcx > > ;
2095
2095
2096
- /// Trait for contexts that can compute layouts of types.
2097
- pub trait LayoutOf < ' tcx > : HasDataLayout + HasTyCtxt < ' tcx > + HasParamEnv < ' tcx > {
2096
+ /// Trait for contexts that want to be able to compute layouts of types.
2097
+ /// This automatically gives access to `LayoutOf`, through a blanket `impl`.
2098
+ pub trait LayoutOfHelpers < ' tcx > : HasDataLayout + HasTyCtxt < ' tcx > + HasParamEnv < ' tcx > {
2098
2099
/// The `TyAndLayout`-wrapping type (or `TyAndLayout` itself), which will be
2099
2100
/// returned from `layout_of` (see also `handle_layout_err`).
2100
2101
type LayoutOfResult : MaybeResult < TyAndLayout < ' tcx > > ;
@@ -2119,7 +2120,10 @@ pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
2119
2120
span : Span ,
2120
2121
ty : Ty < ' tcx > ,
2121
2122
) -> <Self :: LayoutOfResult as MaybeResult < TyAndLayout < ' tcx > > >:: Error ;
2123
+ }
2122
2124
2125
+ /// Blanket extension trait for contexts that can compute layouts of types.
2126
+ pub trait LayoutOf < ' tcx > : LayoutOfHelpers < ' tcx > {
2123
2127
/// Computes the layout of a type. Note that this implicitly
2124
2128
/// executes in "reveal all" mode, and will normalize the input type.
2125
2129
#[ inline]
@@ -2143,7 +2147,9 @@ pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
2143
2147
}
2144
2148
}
2145
2149
2146
- impl LayoutOf < ' tcx > for LayoutCx < ' tcx , TyCtxt < ' tcx > > {
2150
+ impl < C : LayoutOfHelpers < ' tcx > > LayoutOf < ' tcx > for C { }
2151
+
2152
+ impl LayoutOfHelpers < ' tcx > for LayoutCx < ' tcx , TyCtxt < ' tcx > > {
2147
2153
type LayoutOfResult = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
2148
2154
2149
2155
#[ inline]
@@ -2152,7 +2158,7 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {
2152
2158
}
2153
2159
}
2154
2160
2155
- impl LayoutOf < ' tcx > for LayoutCx < ' tcx , ty:: query:: TyCtxtAt < ' tcx > > {
2161
+ impl LayoutOfHelpers < ' tcx > for LayoutCx < ' tcx , ty:: query:: TyCtxtAt < ' tcx > > {
2156
2162
type LayoutOfResult = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
2157
2163
2158
2164
#[ inline]
0 commit comments