Skip to content

Add diagnostic hint for when properties are not loaded

vlorentz requested to merge diagnostic-unimpl-prop into master

For example, this code:

use std::path::PathBuf;
use swh_graph::graph::*;

pub fn main() {
    let graph = load_unidirectional(PathBuf::from("./graph"))
        .unwrap()
        //.load_all_properties().unwrap()
        .init_properties()
        .load_labels()
        .unwrap();

    swh_graph::stdlib::find_latest_snp(&graph, 42).unwrap();
}

now errors with:

error[E0277]: the trait bound `NoMaps: Maps` is not satisfied
  --> rust/examples/bad.rs:12:40
   |
12 |     swh_graph::stdlib::find_latest_snp(&graph, 42).unwrap();
   |     ---------------------------------- ^^^^^^ does not have NodeId<->SWHID mappings loaded
   |     |
   |     required by a bound introduced by this call
   |
   = help: the trait `Maps` is not implemented for `NoMaps`
   = note: Use `let graph = graph.load_properties(|props| props.load_maps::<GOVMPH>()).unwrap()` to load them
   = note: Or replace `graph.init_properties()` with `graph.load_all_properties::<GOVMPH>().unwrap()` to load all properties
   = help: the following other types implement trait `Maps`:
             MappedMaps<MPHF>
             VecMaps

instead of:

error[E0277]: the trait bound `NoMaps: Maps` is not satisfied
  --> rust/examples/bad.rs:12:40
   |
12 |     swh_graph::stdlib::find_latest_snp(&graph, 42).unwrap();
   |     ---------------------------------- ^^^^^^ the trait `Maps` is not implemented for `NoMaps`
   |     |
   |     required by a bound introduced by this call
   |
   = help: the following other types implement trait `Maps`:
             MappedMaps<MPHF>
             VecMaps

Merge request reports