]> git.lizzy.rs Git - rust.git/blob - src/librustc/dep_graph/safe.rs
Rollup merge of #58237 - sdroege:docs-its-its, r=SimonSapin
[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<'a, 'gcx, 'tcx> DepGraphSafe for TyCtxt<'a, 'gcx, 'tcx> {
37 }
38
39 /// Tuples make it easy to build up state.
40 impl<A, B> DepGraphSafe for (A, B)
41     where A: DepGraphSafe, B: DepGraphSafe
42 {
43 }
44
45 /// Shared ref to dep-graph-safe stuff should still be dep-graph-safe.
46 impl<'a, A> DepGraphSafe for &'a A
47     where A: DepGraphSafe,
48 {
49 }
50
51 /// Mut ref to dep-graph-safe stuff should still be dep-graph-safe.
52 impl<'a, A> DepGraphSafe for &'a mut A
53     where A: DepGraphSafe,
54 {
55 }
56
57
58 /// No data here! :)
59 impl DepGraphSafe for () {
60 }
61
62 /// A convenient override that lets you pass arbitrary state into a
63 /// task. Every use should be accompanied by a comment explaining why
64 /// it makes sense (or how it could be refactored away in the future).
65 pub struct AssertDepGraphSafe<T>(pub T);
66
67 impl<T> DepGraphSafe for AssertDepGraphSafe<T> {
68 }