mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Fill in HIR hash for associated opaque types
This commit is contained in:
parent
30f74ff0dc
commit
ef5513f278
@ -642,23 +642,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
let bodies = SortedMap::from_presorted_elements(bodies);
|
let bodies = SortedMap::from_presorted_elements(bodies);
|
||||||
|
|
||||||
// Don't hash unless necessary, because it's expensive.
|
// Don't hash unless necessary, because it's expensive.
|
||||||
let (opt_hash_including_bodies, attrs_hash) = if self.tcx.needs_crate_hash() {
|
let (opt_hash_including_bodies, attrs_hash) =
|
||||||
self.tcx.with_stable_hashing_context(|mut hcx| {
|
self.tcx.hash_owner_nodes(node, &bodies, &attrs);
|
||||||
let mut stable_hasher = StableHasher::new();
|
|
||||||
node.hash_stable(&mut hcx, &mut stable_hasher);
|
|
||||||
// Bodies are stored out of line, so we need to pull them explicitly in the hash.
|
|
||||||
bodies.hash_stable(&mut hcx, &mut stable_hasher);
|
|
||||||
let h1 = stable_hasher.finish();
|
|
||||||
|
|
||||||
let mut stable_hasher = StableHasher::new();
|
|
||||||
attrs.hash_stable(&mut hcx, &mut stable_hasher);
|
|
||||||
let h2 = stable_hasher.finish();
|
|
||||||
|
|
||||||
(Some(h1), Some(h2))
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
(None, None)
|
|
||||||
};
|
|
||||||
let num_nodes = self.item_local_id_counter.as_usize();
|
let num_nodes = self.item_local_id_counter.as_usize();
|
||||||
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
|
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
|
||||||
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
|
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
|
||||||
|
@ -8,6 +8,9 @@ pub mod place;
|
|||||||
|
|
||||||
use crate::query::Providers;
|
use crate::query::Providers;
|
||||||
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
|
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
|
||||||
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
|
use rustc_data_structures::sorted_map::SortedMap;
|
||||||
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::sync::{try_par_for_each_in, DynSend, DynSync};
|
use rustc_data_structures::sync::{try_par_for_each_in, DynSend, DynSync};
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
|
||||||
@ -121,6 +124,30 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
self.opt_parent(def_id.into())
|
self.opt_parent(def_id.into())
|
||||||
.is_some_and(|parent| matches!(self.def_kind(parent), DefKind::ForeignMod))
|
.is_some_and(|parent| matches!(self.def_kind(parent), DefKind::ForeignMod))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hash_owner_nodes(
|
||||||
|
self,
|
||||||
|
node: OwnerNode<'_>,
|
||||||
|
bodies: &SortedMap<ItemLocalId, &Body<'_>>,
|
||||||
|
attrs: &SortedMap<ItemLocalId, &[rustc_ast::Attribute]>,
|
||||||
|
) -> (Option<Fingerprint>, Option<Fingerprint>) {
|
||||||
|
if self.needs_crate_hash() {
|
||||||
|
self.with_stable_hashing_context(|mut hcx| {
|
||||||
|
let mut stable_hasher = StableHasher::new();
|
||||||
|
node.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
|
// Bodies are stored out of line, so we need to pull them explicitly in the hash.
|
||||||
|
bodies.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
|
let h1 = stable_hasher.finish();
|
||||||
|
|
||||||
|
let mut stable_hasher = StableHasher::new();
|
||||||
|
attrs.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
|
let h2 = stable_hasher.finish();
|
||||||
|
(Some(h1), Some(h2))
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
(None, None)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
|
@ -240,8 +240,14 @@ fn associated_types_for_impl_traits_in_associated_fn(
|
|||||||
|
|
||||||
fn feed_hir(feed: &TyCtxtFeed<'_, LocalDefId>) {
|
fn feed_hir(feed: &TyCtxtFeed<'_, LocalDefId>) {
|
||||||
feed.local_def_id_to_hir_id(HirId::make_owner(feed.def_id()));
|
feed.local_def_id_to_hir_id(HirId::make_owner(feed.def_id()));
|
||||||
|
|
||||||
|
let node = hir::OwnerNode::AssocOpaqueTy(&hir::AssocOpaqueTy {});
|
||||||
|
let bodies = Default::default();
|
||||||
|
let attrs = hir::AttributeMap::EMPTY;
|
||||||
|
|
||||||
|
let (opt_hash_including_bodies, _) = feed.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
|
||||||
feed.opt_hir_owner_nodes(Some(feed.tcx.arena.alloc(hir::OwnerNodes {
|
feed.opt_hir_owner_nodes(Some(feed.tcx.arena.alloc(hir::OwnerNodes {
|
||||||
opt_hash_including_bodies: None,
|
opt_hash_including_bodies,
|
||||||
nodes: IndexVec::from_elem_n(
|
nodes: IndexVec::from_elem_n(
|
||||||
hir::ParentedNode {
|
hir::ParentedNode {
|
||||||
parent: hir::ItemLocalId::INVALID,
|
parent: hir::ItemLocalId::INVALID,
|
||||||
@ -249,9 +255,9 @@ fn feed_hir(feed: &TyCtxtFeed<'_, LocalDefId>) {
|
|||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
bodies: Default::default(),
|
bodies,
|
||||||
})));
|
})));
|
||||||
feed.feed_owner_id().hir_attrs(hir::AttributeMap::EMPTY);
|
feed.feed_owner_id().hir_attrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated
|
/// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated
|
||||||
|
11
tests/ui/async-await/in-trait/hir-hash.rs
Normal file
11
tests/ui/async-await/in-trait/hir-hash.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Issue #122508
|
||||||
|
|
||||||
|
//@ check-pass
|
||||||
|
//@ incremental
|
||||||
|
//@ edition:2021
|
||||||
|
|
||||||
|
trait MyTrait {
|
||||||
|
async fn bar(&self) -> i32;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user