]> git.lizzy.rs Git - rust.git/blob - src/librustc/dep_graph/safe.rs
Rollup merge of #66633 - GuillaumeGomez:err-codes-cleanup, r=Dylan-DPC
[rust.git] / src / librustc / dep_graph / safe.rs
1 //! The `DepGraphSafe` trait
2
3 use crate::hir::BodyId;
4 use crate::hir::def_id::DefId;
5 use syntax::ast::NodeId;
6 use crate::ty::TyCtxt;
7
8 /// The `DepGraphSafe` trait is used to specify what kinds of values
9 /// are safe to "leak" into a task. The idea is that this should be
10 /// only be implemented for things like the tcx as well as various id
11 /// types, which will create reads in the dep-graph whenever the trait
12 /// loads anything that might depend on the input program.
13 pub trait DepGraphSafe {
14 }
15
16 /// A `BodyId` on its own doesn't give access to any particular state.
17 /// You must fetch the state from the various maps or generate
18 /// on-demand queries, all of which create reads.
19 impl DepGraphSafe for BodyId {
20 }
21
22 /// A `NodeId` on its own doesn't give access to any particular state.
23 /// You must fetch the state from the various maps or generate
24 /// on-demand queries, all of which create reads.
25 impl DepGraphSafe for NodeId {
26 }
27
28 /// A `DefId` on its own doesn't give access to any particular state.
29 /// You must fetch the state from the various maps or generate
30 /// on-demand queries, all of which create reads.
31 impl DepGraphSafe for DefId {
32 }
33
34 /// The type context itself can be used to access all kinds of tracked
35 /// state, but those accesses should always generate read events.
36 impl<'tcx> DepGraphSafe for TyCtxt<'tcx> {}
37
38 /// Tuples make it easy to build up state.
39 impl<A, B> DepGraphSafe for (A, B)
40     where A: DepGraphSafe, B: DepGraphSafe
41 {
42 }
43
44 /// Shared ref to dep-graph-safe stuff should still be dep-graph-safe.
45 impl<'a, A> DepGraphSafe for &'a A
46     where A: DepGraphSafe,
47 {
48 }
49
50 /// Mut ref to dep-graph-safe stuff should still be dep-graph-safe.
51 impl<'a, A> DepGraphSafe for &'a mut A
52     where A: DepGraphSafe,
53 {
54 }
55
56
57 /// No data here! :)
58 impl DepGraphSafe for () {
59 }
60
61 /// A convenient override that lets you pass arbitrary state into a
62 /// task. Every use should be accompanied by a comment explaining why
63 /// it makes sense (or how it could be refactored away in the future).
64 pub struct AssertDepGraphSafe<T>(pub T);
65
66 impl<T> DepGraphSafe for AssertDepGraphSafe<T> {
67 }