Rollup merge of #138954 - compiler-errors:hash-opaques, r=oli-obk
Ensure `define_opaque` attrs are accounted for in HIR hash Fixes #138948 r? oli-obk
This commit is contained in:
commit
19a53b7d3f
4 changed files with 28 additions and 3 deletions
|
@ -623,7 +623,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|
|
||||||
// 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) =
|
let (opt_hash_including_bodies, attrs_hash) =
|
||||||
self.tcx.hash_owner_nodes(node, &bodies, &attrs);
|
self.tcx.hash_owner_nodes(node, &bodies, &attrs, define_opaque);
|
||||||
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 };
|
||||||
|
|
|
@ -14,7 +14,7 @@ use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_macros::{Decodable, Encodable, HashStable};
|
use rustc_macros::{Decodable, Encodable, HashStable};
|
||||||
use rustc_span::{ErrorGuaranteed, ExpnId};
|
use rustc_span::{ErrorGuaranteed, ExpnId, Span};
|
||||||
|
|
||||||
use crate::query::Providers;
|
use crate::query::Providers;
|
||||||
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
|
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
|
||||||
|
@ -157,6 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
node: OwnerNode<'_>,
|
node: OwnerNode<'_>,
|
||||||
bodies: &SortedMap<ItemLocalId, &Body<'_>>,
|
bodies: &SortedMap<ItemLocalId, &Body<'_>>,
|
||||||
attrs: &SortedMap<ItemLocalId, &[Attribute]>,
|
attrs: &SortedMap<ItemLocalId, &[Attribute]>,
|
||||||
|
define_opaque: Option<&[(Span, LocalDefId)]>,
|
||||||
) -> (Option<Fingerprint>, Option<Fingerprint>) {
|
) -> (Option<Fingerprint>, Option<Fingerprint>) {
|
||||||
if self.needs_crate_hash() {
|
if self.needs_crate_hash() {
|
||||||
self.with_stable_hashing_context(|mut hcx| {
|
self.with_stable_hashing_context(|mut hcx| {
|
||||||
|
@ -168,6 +169,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
let mut stable_hasher = StableHasher::new();
|
let mut stable_hasher = StableHasher::new();
|
||||||
attrs.hash_stable(&mut hcx, &mut stable_hasher);
|
attrs.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
|
|
||||||
|
// Hash the defined opaque types, which are not present in the attrs.
|
||||||
|
define_opaque.hash_stable(&mut hcx, &mut stable_hasher);
|
||||||
|
|
||||||
let h2 = stable_hasher.finish();
|
let h2 = stable_hasher.finish();
|
||||||
(Some(h1), Some(h2))
|
(Some(h1), Some(h2))
|
||||||
})
|
})
|
||||||
|
|
|
@ -1288,7 +1288,8 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
|
||||||
let bodies = Default::default();
|
let bodies = Default::default();
|
||||||
let attrs = hir::AttributeMap::EMPTY;
|
let attrs = hir::AttributeMap::EMPTY;
|
||||||
|
|
||||||
let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
|
let (opt_hash_including_bodies, _) =
|
||||||
|
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque);
|
||||||
let node = node.into();
|
let node = node.into();
|
||||||
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
|
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
|
||||||
opt_hash_including_bodies,
|
opt_hash_including_bodies,
|
||||||
|
|
19
tests/incremental/define-opaques.rs
Normal file
19
tests/incremental/define-opaques.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
//@ revisions: rpass1 cfail2
|
||||||
|
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
pub type Foo = impl Sized;
|
||||||
|
|
||||||
|
#[cfg_attr(rpass1, define_opaque())]
|
||||||
|
#[cfg_attr(cfail2, define_opaque(Foo))]
|
||||||
|
fn a() {
|
||||||
|
//[cfail2]~^ ERROR item does not constrain `Foo::{opaque#0}`
|
||||||
|
let _: Foo = b();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[define_opaque(Foo)]
|
||||||
|
fn b() -> Foo {
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue