Skip to content

Commit 19a53b7

Browse files
authored
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
2 parents 2ae5d34 + 4b22ac5 commit 19a53b7

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
623623

624624
// Don't hash unless necessary, because it's expensive.
625625
let (opt_hash_including_bodies, attrs_hash) =
626-
self.tcx.hash_owner_nodes(node, &bodies, &attrs);
626+
self.tcx.hash_owner_nodes(node, &bodies, &attrs, define_opaque);
627627
let num_nodes = self.item_local_id_counter.as_usize();
628628
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
629629
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };

Diff for: compiler/rustc_middle/src/hir/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::def::DefKind;
1414
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
1515
use rustc_hir::*;
1616
use rustc_macros::{Decodable, Encodable, HashStable};
17-
use rustc_span::{ErrorGuaranteed, ExpnId};
17+
use rustc_span::{ErrorGuaranteed, ExpnId, Span};
1818

1919
use crate::query::Providers;
2020
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
@@ -157,6 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
157157
node: OwnerNode<'_>,
158158
bodies: &SortedMap<ItemLocalId, &Body<'_>>,
159159
attrs: &SortedMap<ItemLocalId, &[Attribute]>,
160+
define_opaque: Option<&[(Span, LocalDefId)]>,
160161
) -> (Option<Fingerprint>, Option<Fingerprint>) {
161162
if self.needs_crate_hash() {
162163
self.with_stable_hashing_context(|mut hcx| {
@@ -168,6 +169,10 @@ impl<'tcx> TyCtxt<'tcx> {
168169

169170
let mut stable_hasher = StableHasher::new();
170171
attrs.hash_stable(&mut hcx, &mut stable_hasher);
172+
173+
// Hash the defined opaque types, which are not present in the attrs.
174+
define_opaque.hash_stable(&mut hcx, &mut stable_hasher);
175+
171176
let h2 = stable_hasher.finish();
172177
(Some(h1), Some(h2))
173178
})

Diff for: compiler/rustc_middle/src/ty/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,8 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
12881288
let bodies = Default::default();
12891289
let attrs = hir::AttributeMap::EMPTY;
12901290

1291-
let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
1291+
let (opt_hash_including_bodies, _) =
1292+
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque);
12921293
let node = node.into();
12931294
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
12941295
opt_hash_including_bodies,

Diff for: tests/incremental/define-opaques.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ revisions: rpass1 cfail2
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
pub type Foo = impl Sized;
6+
7+
#[cfg_attr(rpass1, define_opaque())]
8+
#[cfg_attr(cfail2, define_opaque(Foo))]
9+
fn a() {
10+
//[cfail2]~^ ERROR item does not constrain `Foo::{opaque#0}`
11+
let _: Foo = b();
12+
}
13+
14+
#[define_opaque(Foo)]
15+
fn b() -> Foo {
16+
()
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)