@@ -2093,8 +2093,9 @@ impl<T, E> MaybeResult<T> for Result<T, E> {
20932093
20942094pub type TyAndLayout < ' tcx > = rustc_target:: abi:: TyAndLayout < ' tcx , Ty < ' tcx > > ;
20952095
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 > {
20982099 /// The `TyAndLayout`-wrapping type (or `TyAndLayout` itself), which will be
20992100 /// returned from `layout_of` (see also `handle_layout_err`).
21002101 type LayoutOfResult : MaybeResult < TyAndLayout < ' tcx > > ;
@@ -2119,7 +2120,10 @@ pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
21192120 span : Span ,
21202121 ty : Ty < ' tcx > ,
21212122 ) -> <Self :: LayoutOfResult as MaybeResult < TyAndLayout < ' tcx > > >:: Error ;
2123+ }
21222124
2125+ /// Blanket extension trait for contexts that can compute layouts of types.
2126+ pub trait LayoutOf < ' tcx > : LayoutOfHelpers < ' tcx > {
21232127 /// Computes the layout of a type. Note that this implicitly
21242128 /// executes in "reveal all" mode, and will normalize the input type.
21252129 #[ inline]
@@ -2143,7 +2147,9 @@ pub trait LayoutOf<'tcx>: HasDataLayout + HasTyCtxt<'tcx> + HasParamEnv<'tcx> {
21432147 }
21442148}
21452149
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 > > {
21472153 type LayoutOfResult = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
21482154
21492155 #[ inline]
@@ -2152,7 +2158,7 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {
21522158 }
21532159}
21542160
2155- impl LayoutOf < ' tcx > for LayoutCx < ' tcx , ty:: query:: TyCtxtAt < ' tcx > > {
2161+ impl LayoutOfHelpers < ' tcx > for LayoutCx < ' tcx , ty:: query:: TyCtxtAt < ' tcx > > {
21562162 type LayoutOfResult = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
21572163
21582164 #[ inline]
0 commit comments