Skip to content

Commit 175238b

Browse files
Make decoding non-optional LazyArray panic if not set
1 parent 9649706 commit 175238b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ impl<'a, 'tcx, T: Copy + Decodable<DecodeContext<'a, 'tcx>>> ProcessQueryValue<'
7171
for Option<DecodeIterator<'a, 'tcx, T>>
7272
{
7373
#[inline(always)]
74-
fn process_decoded(self, tcx: TyCtxt<'tcx>, _err: impl Fn() -> !) -> &'tcx [T] {
75-
if let Some(iter) = self { tcx.arena.alloc_from_iter(iter) } else { &[] }
74+
fn process_decoded(self, tcx: TyCtxt<'tcx>, err: impl Fn() -> !) -> &'tcx [T] {
75+
if let Some(iter) = self { tcx.arena.alloc_from_iter(iter) } else { err() }
7676
}
7777
}
7878

@@ -84,12 +84,12 @@ impl<'a, 'tcx, T: Copy + Decodable<DecodeContext<'a, 'tcx>>>
8484
fn process_decoded(
8585
self,
8686
tcx: TyCtxt<'tcx>,
87-
_err: impl Fn() -> !,
87+
err: impl Fn() -> !,
8888
) -> ty::EarlyBinder<'tcx, &'tcx [T]> {
8989
ty::EarlyBinder::bind(if let Some(iter) = self {
9090
tcx.arena.alloc_from_iter(iter)
9191
} else {
92-
&[]
92+
err()
9393
})
9494
}
9595
}
@@ -301,7 +301,20 @@ provide! { tcx, def_id, other, cdata,
301301
.unwrap_or_else(|| panic!("{def_id:?} does not have eval_static_initializer")))
302302
}
303303
trait_def => { table }
304-
deduced_param_attrs => { table }
304+
deduced_param_attrs => {
305+
// FIXME: `deduced_param_attrs` has some sketchy encoding settings,
306+
// where we don't encode unless we're optimizing, doing codegen,
307+
// and not incremental (see `encoder.rs`). I don't think this is right!
308+
cdata
309+
.root
310+
.tables
311+
.deduced_param_attrs
312+
.get(cdata, def_id.index)
313+
.map(|lazy| {
314+
&*tcx.arena.alloc_from_iter(lazy.decode((cdata, tcx)))
315+
})
316+
.unwrap_or_default()
317+
}
305318
is_type_alias_impl_trait => {
306319
debug_assert_eq!(tcx.def_kind(def_id), DefKind::OpaqueTy);
307320
cdata.root.tables.is_type_alias_impl_trait.get(cdata, def_id.index)

0 commit comments

Comments
 (0)