1
Fork 0

specialization_graph_of's errored field is used in the only call site, and used to immediately throw away the rest of the value. Let's use Result to statically signal that this is happening

This commit is contained in:
Oli Scherer 2024-01-11 10:05:12 +00:00
parent 3a6bf351a3
commit 5461836281
5 changed files with 49 additions and 46 deletions

View file

@ -113,6 +113,7 @@ macro_rules! arena_types {
[] stripped_cfg_items: rustc_ast::expand::StrippedCfgItem,
[] mod_child: rustc_middle::metadata::ModChild,
[] features: rustc_feature::Features,
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
]);
)
}

View file

@ -1294,8 +1294,7 @@ rustc_queries! {
desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
}
query specialization_graph_of(trait_id: DefId) -> &'tcx specialization_graph::Graph {
arena_cache
query specialization_graph_of(trait_id: DefId) -> Result<&'tcx specialization_graph::Graph, ErrorGuaranteed> {
desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
cache_on_disk_if { true }
}

View file

@ -786,6 +786,15 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [rustc_ast::InlineAsm
}
}
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>>
for &'tcx crate::traits::specialization_graph::Graph
{
#[inline]
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
RefDecodable::decode(d)
}
}
macro_rules! impl_ref_decoder {
(<$tcx:tt> $($ty:ty,)*) => {
$(impl<'a, $tcx> Decodable<CacheDecoder<'a, $tcx>> for &$tcx [$ty] {

View file

@ -30,18 +30,16 @@ pub struct Graph {
/// The "root" impls are found by looking up the trait's def_id.
pub children: DefIdMap<Children>,
/// Whether an error was emitted while constructing the graph.
pub has_errored: Option<ErrorGuaranteed>,
}
impl Graph {
pub fn new() -> Graph {
Graph { parent: Default::default(), children: Default::default(), has_errored: None }
Graph { parent: Default::default(), children: Default::default() }
}
/// The parent of a given impl, which is the `DefId` of the trait when the
/// impl is a "specialization root".
#[track_caller]
pub fn parent(&self, child: DefId) -> DefId {
*self.parent.get(&child).unwrap_or_else(|| panic!("Failed to get parent for {child:?}"))
}
@ -255,13 +253,9 @@ pub fn ancestors(
trait_def_id: DefId,
start_from_impl: DefId,
) -> Result<Ancestors<'_>, ErrorGuaranteed> {
let specialization_graph = tcx.specialization_graph_of(trait_def_id);
let specialization_graph = tcx.specialization_graph_of(trait_def_id)?;
if let Some(reported) = specialization_graph.has_errored {
Err(reported)
} else if let Err(reported) =
tcx.type_of(start_from_impl).instantiate_identity().error_reported()
{
if let Err(reported) = tcx.type_of(start_from_impl).instantiate_identity().error_reported() {
Err(reported)
} else {
Ok(Ancestors {