Skip to content

Commit ca50818

Browse files
Rollup merge of rust-lang#152520 - Zalathar:traits-cache, r=dingxiangfei2009
Don't use `DepContext` in `rustc_middle::traits::cache` - A nice little simplification unlocked by rust-lang#152199. --- This code is now in `rustc_middle`, and doesn't need any non-trivial methods, so it can just use `TyCtxt` directly instead.
2 parents 060297d + 576901f commit ca50818

File tree

1 file changed

+6
-5
lines changed
  • compiler/rustc_middle/src/traits

1 file changed

+6
-5
lines changed

compiler/rustc_middle/src/traits/cache.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::hash::Hash;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::sync::Lock;
77

8-
use crate::dep_graph::{DepContext, DepNodeIndex};
8+
use crate::dep_graph::DepNodeIndex;
9+
use crate::ty::TyCtxt;
910

1011
pub struct WithDepNodeCache<Key, Value> {
1112
hashmap: Lock<FxHashMap<Key, WithDepNode<Value>>>,
@@ -24,7 +25,7 @@ impl<Key, Value> Default for WithDepNodeCache<Key, Value> {
2425
}
2526

2627
impl<Key: Eq + Hash, Value: Clone> WithDepNodeCache<Key, Value> {
27-
pub fn get<Tcx: DepContext>(&self, key: &Key, tcx: Tcx) -> Option<Value> {
28+
pub fn get<'tcx>(&self, key: &Key, tcx: TyCtxt<'tcx>) -> Option<Value> {
2829
Some(self.hashmap.borrow().get(key)?.get(tcx))
2930
}
3031

@@ -40,12 +41,12 @@ pub struct WithDepNode<T> {
4041
}
4142

4243
impl<T: Clone> WithDepNode<T> {
43-
pub fn new(dep_node: DepNodeIndex, cached_value: T) -> Self {
44+
pub(crate) fn new(dep_node: DepNodeIndex, cached_value: T) -> Self {
4445
WithDepNode { dep_node, cached_value }
4546
}
4647

47-
pub fn get<Tcx: DepContext>(&self, tcx: Tcx) -> T {
48-
tcx.dep_graph().read_index(self.dep_node);
48+
pub(crate) fn get<'tcx>(&self, tcx: TyCtxt<'tcx>) -> T {
49+
tcx.dep_graph.read_index(self.dep_node);
4950
self.cached_value.clone()
5051
}
5152
}

0 commit comments

Comments
 (0)