Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e46c58f

Browse files
committed
Fix tests and address review comments
1 parent a225ddd commit e46c58f

File tree

8 files changed

+47
-202
lines changed

8 files changed

+47
-202
lines changed

src/librustc_middle/middle/codegen_fn_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_attr::{InlineAttr, OptimizeAttr};
33
use rustc_session::config::SanitizerSet;
44
use rustc_span::symbol::Symbol;
55

6-
#[derive(Clone, Encodable, Decodable, HashStable)]
6+
#[derive(Clone, TyEncodable, TyDecodable, HashStable)]
77
pub struct CodegenFnAttrs {
88
pub flags: CodegenFnAttrFlags,
99
/// Parsed representation of the `#[inline]` attribute
@@ -37,7 +37,7 @@ pub struct CodegenFnAttrs {
3737
}
3838

3939
bitflags! {
40-
#[derive(Encodable, Decodable, HashStable)]
40+
#[derive(TyEncodable, TyDecodable, HashStable)]
4141
pub struct CodegenFnAttrFlags: u32 {
4242
/// `#[cold]`: a hint to LLVM that this function, when called, is never on
4343
/// the hot path.

src/librustc_middle/middle/exported_symbols.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_macros::HashStable;
88
/// kind of crate, including cdylibs which export very few things.
99
/// `Rust` will only be exported if the crate produced is a Rust
1010
/// dylib.
11-
#[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable)]
11+
#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
1212
pub enum SymbolExportLevel {
1313
C,
1414
Rust,

src/librustc_middle/mir/mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub struct CodegenUnit<'tcx> {
242242
/// Specifies the linkage type for a `MonoItem`.
243243
///
244244
/// See https://llvm.org/docs/LangRef.html#linkage-types for more details about these variants.
245-
#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable, HashStable)]
245+
#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)]
246246
pub enum Linkage {
247247
External,
248248
AvailableExternally,

src/librustc_middle/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ impl<'tcx> VariantDef {
20982098
}
20992099
}
21002100

2101-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Encodable, Decodable, HashStable)]
2101+
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
21022102
pub enum VariantDiscr {
21032103
/// Explicit value for this variant, i.e., `X = 123`.
21042104
/// The `DefId` corresponds to the embedded constant.

src/librustc_middle/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl TyKind<'tcx> {
215215
/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
216216
/// except through `tcx.err*()`.
217217
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
218-
#[derive(Encodable, Decodable, HashStable)]
218+
#[derive(TyEncodable, TyDecodable, HashStable)]
219219
pub struct DelaySpanBugEmitted(pub(super) ());
220220

221221
// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.

src/librustc_serialize/serialize.rs

Lines changed: 39 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ pub trait Decoder {
385385
/// `MetadataEncodable` macros.
386386
///
387387
/// * `Encodable` should be used in crates that don't depend on
388-
/// `librustc_middle`.
388+
/// `rustc_middle`.
389+
/// * `MetadataEncodable` is used in `rustc_metadata` for types that contain
390+
/// `rustc_metadata::rmeta::Lazy`.
389391
/// * `TyEncodable` should be used for types that are only serialized in crate
390-
/// metadata or the incremental cache, except for simple enums.where
391-
/// * `MetadataEncodable` is used in `rustc_metadata` for types that are only
392-
/// serialized in crate metadata.
392+
/// metadata or the incremental cache. This is most types in `rustc_middle`.
393393
pub trait Encodable<S: Encoder> {
394394
fn encode(&self, s: &mut S) -> Result<(), S::Error>;
395395
}
@@ -400,61 +400,50 @@ pub trait Encodable<S: Encoder> {
400400
/// `MetadataDecodable` macros.
401401
///
402402
/// * `Decodable` should be used in crates that don't depend on
403-
/// `librustc_middle`.
403+
/// `rustc_middle`.
404+
/// * `MetadataDecodable` is used in `rustc_metadata` for types that contain
405+
/// `rustc_metadata::rmeta::Lazy`.
404406
/// * `TyDecodable` should be used for types that are only serialized in crate
405-
/// metadata or the incremental cache, except for simple enums.where
406-
/// * `MetadataDecodable` is used in `rustc_metadata` for types that are only
407-
/// serialized in crate metadata.
407+
/// metadata or the incremental cache. This is most types in `rustc_middle`.
408408
pub trait Decodable<D: Decoder>: Sized {
409409
fn decode(d: &mut D) -> Result<Self, D::Error>;
410410
}
411411

412-
impl<S: Encoder> Encodable<S> for usize {
413-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
414-
s.emit_usize(*self)
415-
}
416-
}
417-
418-
impl<D: Decoder> Decodable<D> for usize {
419-
fn decode(d: &mut D) -> Result<usize, D::Error> {
420-
d.read_usize()
421-
}
422-
}
423-
424-
impl<S: Encoder> Encodable<S> for u8 {
425-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
426-
s.emit_u8(*self)
427-
}
428-
}
429-
430-
impl<D: Decoder> Decodable<D> for u8 {
431-
fn decode(d: &mut D) -> Result<u8, D::Error> {
432-
d.read_u8()
433-
}
434-
}
435-
436-
impl<S: Encoder> Encodable<S> for u16 {
437-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
438-
s.emit_u16(*self)
439-
}
440-
}
441-
442-
impl<D: Decoder> Decodable<D> for u16 {
443-
fn decode(d: &mut D) -> Result<u16, D::Error> {
444-
d.read_u16()
445-
}
446-
}
412+
macro_rules! direct_serialize_impls {
413+
($($ty:ident $emit_method:ident $read_method:ident),*) => {
414+
$(
415+
impl<S: Encoder> Encodable<S> for $ty {
416+
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
417+
s.$emit_method(*self)
418+
}
419+
}
447420

448-
impl<S: Encoder> Encodable<S> for u32 {
449-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
450-
s.emit_u32(*self)
421+
impl<D: Decoder> Decodable<D> for $ty {
422+
fn decode(d: &mut D) -> Result<$ty, D::Error> {
423+
d.$read_method()
424+
}
425+
}
426+
)*
451427
}
452428
}
453429

454-
impl<D: Decoder> Decodable<D> for u32 {
455-
fn decode(d: &mut D) -> Result<u32, D::Error> {
456-
d.read_u32()
457-
}
430+
direct_serialize_impls! {
431+
usize emit_usize read_usize,
432+
u8 emit_u8 read_u8,
433+
u16 emit_u16 read_u16,
434+
u32 emit_u32 read_u32,
435+
u64 emit_u64 read_u64,
436+
u128 emit_u128 read_u128,
437+
isize emit_isize read_isize,
438+
i8 emit_i8 read_i8,
439+
i16 emit_i16 read_i16,
440+
i32 emit_i32 read_i32,
441+
i64 emit_i64 read_i64,
442+
i128 emit_i128 read_i128,
443+
f32 emit_f32 read_f32,
444+
f64 emit_f64 read_f64,
445+
bool emit_bool read_bool,
446+
char emit_char read_char
458447
}
459448

460449
impl<S: Encoder> Encodable<S> for ::std::num::NonZeroU32 {
@@ -469,102 +458,6 @@ impl<D: Decoder> Decodable<D> for ::std::num::NonZeroU32 {
469458
}
470459
}
471460

472-
impl<S: Encoder> Encodable<S> for u64 {
473-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
474-
s.emit_u64(*self)
475-
}
476-
}
477-
478-
impl<D: Decoder> Decodable<D> for u64 {
479-
fn decode(d: &mut D) -> Result<u64, D::Error> {
480-
d.read_u64()
481-
}
482-
}
483-
484-
impl<S: Encoder> Encodable<S> for u128 {
485-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
486-
s.emit_u128(*self)
487-
}
488-
}
489-
490-
impl<D: Decoder> Decodable<D> for u128 {
491-
fn decode(d: &mut D) -> Result<u128, D::Error> {
492-
d.read_u128()
493-
}
494-
}
495-
496-
impl<S: Encoder> Encodable<S> for isize {
497-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
498-
s.emit_isize(*self)
499-
}
500-
}
501-
502-
impl<D: Decoder> Decodable<D> for isize {
503-
fn decode(d: &mut D) -> Result<isize, D::Error> {
504-
d.read_isize()
505-
}
506-
}
507-
508-
impl<S: Encoder> Encodable<S> for i8 {
509-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
510-
s.emit_i8(*self)
511-
}
512-
}
513-
514-
impl<D: Decoder> Decodable<D> for i8 {
515-
fn decode(d: &mut D) -> Result<i8, D::Error> {
516-
d.read_i8()
517-
}
518-
}
519-
520-
impl<S: Encoder> Encodable<S> for i16 {
521-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
522-
s.emit_i16(*self)
523-
}
524-
}
525-
526-
impl<D: Decoder> Decodable<D> for i16 {
527-
fn decode(d: &mut D) -> Result<i16, D::Error> {
528-
d.read_i16()
529-
}
530-
}
531-
532-
impl<S: Encoder> Encodable<S> for i32 {
533-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
534-
s.emit_i32(*self)
535-
}
536-
}
537-
538-
impl<D: Decoder> Decodable<D> for i32 {
539-
fn decode(d: &mut D) -> Result<i32, D::Error> {
540-
d.read_i32()
541-
}
542-
}
543-
544-
impl<S: Encoder> Encodable<S> for i64 {
545-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
546-
s.emit_i64(*self)
547-
}
548-
}
549-
550-
impl<D: Decoder> Decodable<D> for i64 {
551-
fn decode(d: &mut D) -> Result<i64, D::Error> {
552-
d.read_i64()
553-
}
554-
}
555-
556-
impl<S: Encoder> Encodable<S> for i128 {
557-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
558-
s.emit_i128(*self)
559-
}
560-
}
561-
562-
impl<D: Decoder> Decodable<D> for i128 {
563-
fn decode(d: &mut D) -> Result<i128, D::Error> {
564-
d.read_i128()
565-
}
566-
}
567-
568461
impl<S: Encoder> Encodable<S> for str {
569462
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
570463
s.emit_str(self)
@@ -589,54 +482,6 @@ impl<D: Decoder> Decodable<D> for String {
589482
}
590483
}
591484

592-
impl<S: Encoder> Encodable<S> for f32 {
593-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
594-
s.emit_f32(*self)
595-
}
596-
}
597-
598-
impl<D: Decoder> Decodable<D> for f32 {
599-
fn decode(d: &mut D) -> Result<f32, D::Error> {
600-
d.read_f32()
601-
}
602-
}
603-
604-
impl<S: Encoder> Encodable<S> for f64 {
605-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
606-
s.emit_f64(*self)
607-
}
608-
}
609-
610-
impl<D: Decoder> Decodable<D> for f64 {
611-
fn decode(d: &mut D) -> Result<f64, D::Error> {
612-
d.read_f64()
613-
}
614-
}
615-
616-
impl<S: Encoder> Encodable<S> for bool {
617-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
618-
s.emit_bool(*self)
619-
}
620-
}
621-
622-
impl<D: Decoder> Decodable<D> for bool {
623-
fn decode(d: &mut D) -> Result<bool, D::Error> {
624-
d.read_bool()
625-
}
626-
}
627-
628-
impl<S: Encoder> Encodable<S> for char {
629-
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
630-
s.emit_char(*self)
631-
}
632-
}
633-
634-
impl<D: Decoder> Decodable<D> for char {
635-
fn decode(d: &mut D) -> Result<char, D::Error> {
636-
d.read_char()
637-
}
638-
}
639-
640485
impl<S: Encoder> Encodable<S> for () {
641486
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
642487
s.emit_unit()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"_field0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]}
1+
{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"prelude_import","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"","span":{"lo":0,"hi":0}},"kind":{"variant":"Use","fields":[{"prefix":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"{{root}}","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"std","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"prelude","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"v1","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"kind":"Glob","span":{"lo":0,"hi":0}}]},"tokens":null},{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"macro_use","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"std","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null},{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"_field0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]}
1+
{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"prelude_import","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"","span":{"lo":0,"hi":0}},"kind":{"variant":"Use","fields":[{"prefix":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"{{root}}","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"std","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"prelude","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"v1","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"kind":"Glob","span":{"lo":0,"hi":0}}]},"tokens":null},{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"macro_use","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"std","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null},{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]}

0 commit comments

Comments
 (0)