@@ -3,7 +3,7 @@ use crate::rmeta::*;
33use rustc_data_structures:: fingerprint:: Fingerprint ;
44use rustc_hir:: def:: { CtorKind , CtorOf } ;
55use rustc_index:: vec:: Idx ;
6- use rustc_middle:: ty:: ParameterizedOverTcx ;
6+ use rustc_middle:: ty:: { ParameterizedOverTcx , UnusedGenericParams } ;
77use rustc_serialize:: opaque:: FileEncoder ;
88use rustc_serialize:: Encoder as _;
99use rustc_span:: hygiene:: MacroKind ;
@@ -50,6 +50,16 @@ impl IsDefault for DefPathHash {
5050 }
5151}
5252
53+ impl IsDefault for UnusedGenericParams {
54+ fn is_default ( & self ) -> bool {
55+ // UnusedGenericParams encodes the *un*usedness as a bitset.
56+ // This means that 0 corresponds to all bits used, which is indeed the default.
57+ let is_default = self . bits ( ) == 0 ;
58+ debug_assert_eq ! ( is_default, self . all_used( ) ) ;
59+ is_default
60+ }
61+ }
62+
5363/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
5464/// Used mainly for Lazy positions and lengths.
5565/// Unchecked invariant: `Self::default()` should encode as `[0; BYTE_LEN]`,
@@ -271,6 +281,21 @@ impl FixedSizeEncoding for bool {
271281 }
272282}
273283
284+ impl FixedSizeEncoding for UnusedGenericParams {
285+ type ByteArray = [ u8 ; 4 ] ;
286+
287+ #[ inline]
288+ fn from_bytes ( b : & [ u8 ; 4 ] ) -> Self {
289+ let x: u32 = u32:: from_bytes ( b) ;
290+ UnusedGenericParams :: from_bits ( x)
291+ }
292+
293+ #[ inline]
294+ fn write_to_bytes ( self , b : & mut [ u8 ; 4 ] ) {
295+ self . bits ( ) . write_to_bytes ( b) ;
296+ }
297+ }
298+
274299// NOTE(eddyb) there could be an impl for `usize`, which would enable a more
275300// generic `LazyValue<T>` impl, but in the general case we might not need / want
276301// to fit every `usize` in `u32`.
0 commit comments