Skip to content

Commit 41720af

Browse files
committed
Sanitize DEP_KINDS arrays.
1 parent 42baef9 commit 41720af

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Diff for: compiler/rustc_middle/src/dep_graph/dep_node.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,14 @@ macro_rules! define_dep_nodes {
348348
)*
349349
}
350350

351+
/// This enum serves as an index into the `DEP_KINDS` array.
351352
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
352353
#[allow(non_camel_case_types)]
353354
pub enum DepKindIndex {
354355
$($name),*
355356
}
356357

357-
pub static DEP_KINDS: &[DepKind] = &[ $(&dep_kind::$name),* ];
358+
crate static DEP_KINDS: &[DepKind] = &[ $(&dep_kind::$name),* ];
358359

359360
pub struct DepConstructor;
360361

@@ -643,7 +644,9 @@ impl<E: Encoder> Encodable<E> for &dyn DepKindTrait {
643644
impl<D: Decoder> Decodable<D> for &dyn DepKindTrait {
644645
fn decode(dec: &mut D) -> Result<Self, D::Error> {
645646
let idx = DepKindIndex::decode(dec)?;
646-
Ok(DEP_KINDS[idx as usize])
647+
let dk = DEP_KINDS[idx as usize];
648+
debug_assert!(dk.index() == idx);
649+
Ok(dk)
647650
}
648651
}
649652

Diff for: compiler/rustc_middle/src/dep_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub use rustc_query_system::dep_graph::{
1313
WorkProduct, WorkProductId,
1414
};
1515

16+
crate use dep_node::DEP_KINDS;
1617
pub use dep_node::{
1718
dep_kind, label_strs, DepConstructor, DepKind, DepKindIndex, DepKindTrait, DepNode, DepNodeExt,
18-
DEP_KINDS,
1919
};
2020

2121
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;

0 commit comments

Comments
 (0)