Skip to content

Commit 593c77b

Browse files
Move codec module back into middle
1 parent 4729348 commit 593c77b

File tree

15 files changed

+121
-178
lines changed

15 files changed

+121
-178
lines changed

compiler/rustc_macros/src/serialize.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ use syn::spanned::Spanned;
66
pub(super) fn type_decodable_derive(
77
mut s: synstructure::Structure<'_>,
88
) -> proc_macro2::TokenStream {
9+
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
10+
s.add_impl_generic(parse_quote! { 'tcx });
11+
}
912
let decoder_ty = quote! { __D };
10-
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
11-
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
12-
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
13-
quote! { <I = I> }
14-
} else {
15-
quote! {}
16-
};
17-
18-
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_middle::ty::codec::TyDecoder #bound });
13+
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_middle::ty::codec::TyDecoder<'tcx> });
1914
s.add_bounds(synstructure::AddBounds::Fields);
2015
s.underscore_const(true);
2116

@@ -132,16 +127,11 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
132127
pub(super) fn type_encodable_derive(
133128
mut s: synstructure::Structure<'_>,
134129
) -> proc_macro2::TokenStream {
135-
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
136-
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
137-
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
138-
quote! { <I = I> }
139-
} else {
140-
quote! {}
141-
};
142-
143130
let encoder_ty = quote! { __E };
144-
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_middle::ty::codec::TyEncoder #bound });
131+
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
132+
s.add_impl_generic(parse_quote! { 'tcx });
133+
}
134+
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_middle::ty::codec::TyEncoder<'tcx> });
145135
s.add_bounds(synstructure::AddBounds::Fields);
146136
s.underscore_const(true);
147137

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,11 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
386386
}
387387
}
388388

389-
impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
389+
impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
390390
const CLEAR_CROSS_CRATE: bool = true;
391391

392-
type I = TyCtxt<'tcx>;
393-
394392
#[inline]
395-
fn interner(&self) -> Self::I {
393+
fn interner(&self) -> TyCtxt<'tcx> {
396394
self.tcx()
397395
}
398396

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,9 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for [u8] {
378378
}
379379
}
380380

381-
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> {
381+
impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
382382
const CLEAR_CROSS_CRATE: bool = true;
383383

384-
type I = TyCtxt<'tcx>;
385-
386384
fn position(&self) -> usize {
387385
self.opaque.position()
388386
}

compiler/rustc_middle/src/mir/interpret/allocation/init_mask.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::{hash, iter};
66

77
use rustc_abi::Size;
88
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
9-
use rustc_serialize::{Decodable, Encodable};
10-
use rustc_type_ir::{TyDecoder, TyEncoder};
9+
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
1110

1211
use super::AllocRange;
1312

@@ -194,7 +193,7 @@ struct InitMaskMaterialized {
194193
// and also produces more output when the high bits of each `u64` are occupied.
195194
// Note: There is probably a remaining optimization for masks that do not use an entire
196195
// `Block`.
197-
impl<E: TyEncoder> Encodable<E> for InitMaskMaterialized {
196+
impl<E: Encoder> Encodable<E> for InitMaskMaterialized {
198197
fn encode(&self, encoder: &mut E) {
199198
encoder.emit_usize(self.blocks.len());
200199
for block in &self.blocks {
@@ -204,7 +203,7 @@ impl<E: TyEncoder> Encodable<E> for InitMaskMaterialized {
204203
}
205204

206205
// This implementation is deliberately not derived, see the matching `Encodable` impl.
207-
impl<D: TyDecoder> Decodable<D> for InitMaskMaterialized {
206+
impl<D: Decoder> Decodable<D> for InitMaskMaterialized {
208207
fn decode(decoder: &mut D) -> Self {
209208
let num_blocks = decoder.read_usize();
210209
let mut blocks = Vec::with_capacity(num_blocks);

compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ enum AllocDiscriminant {
105105
Static,
106106
}
107107

108-
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>>(
108+
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<'tcx>>(
109109
encoder: &mut E,
110110
tcx: TyCtxt<'tcx>,
111111
alloc_id: AllocId,
@@ -175,7 +175,7 @@ impl<'s> AllocDecodingSession<'s> {
175175
/// Decodes an `AllocId` in a thread-safe way.
176176
pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
177177
where
178-
D: TyDecoder<I = TyCtxt<'tcx>>,
178+
D: TyDecoder<'tcx>,
179179
{
180180
// Read the index of the allocation.
181181
let idx = usize::try_from(decoder.read_u32()).unwrap();

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl<T> ClearCrossCrate<T> {
790790
const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
791791
const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;
792792

793-
impl<E: TyEncoder, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
793+
impl<'tcx, E: TyEncoder<'tcx>, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
794794
#[inline]
795795
fn encode(&self, e: &mut E) {
796796
if E::CLEAR_CROSS_CRATE {
@@ -806,7 +806,7 @@ impl<E: TyEncoder, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
806806
}
807807
}
808808
}
809-
impl<D: TyDecoder, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> {
809+
impl<'tcx, D: TyDecoder<'tcx>, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> {
810810
#[inline]
811811
fn decode(d: &mut D) -> ClearCrossCrate<T> {
812812
if D::CLEAR_CROSS_CRATE {

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ where
518518
value
519519
}
520520

521-
impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
522-
type I = TyCtxt<'tcx>;
521+
impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
523522
const CLEAR_CROSS_CRATE: bool = false;
524523

525524
#[inline]
@@ -943,8 +942,7 @@ impl<'a, 'tcx> SpanEncoder for CacheEncoder<'a, 'tcx> {
943942
}
944943
}
945944

946-
impl<'a, 'tcx> TyEncoder for CacheEncoder<'a, 'tcx> {
947-
type I = TyCtxt<'tcx>;
945+
impl<'a, 'tcx> TyEncoder<'tcx> for CacheEncoder<'a, 'tcx> {
948946
const CLEAR_CROSS_CRATE: bool = false;
949947

950948
#[inline]

0 commit comments

Comments
 (0)