Skip to content

Commit c89c174

Browse files
authored
Unrolled build for rust-lang#117396
Rollup merge of rust-lang#117396 - oli-obk:privacy_visitor_types, r=compiler-errors Don't treat closures/coroutine types as part of the public API Fixes a regression from rust-lang#117076 r? `@compiler-errors`
2 parents 236ac91 + 43ff2a7 commit c89c174

File tree

3 files changed

+56
-28
lines changed

3 files changed

+56
-28
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
121121
}
122122

123123
impl<'tcx> super::sig_types::SpannedTypeVisitor<'tcx> for OpaqueTypeCollector<'tcx> {
124+
#[instrument(skip(self), ret, level = "trace")]
124125
fn visit(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) -> ControlFlow<!> {
125126
self.visit_spanned(span, value);
126127
ControlFlow::Continue(())

compiler/rustc_ty_utils/src/sig_types.rs

+11-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::ops::ControlFlow;
55

66
use rustc_hir::{def::DefKind, def_id::LocalDefId};
7-
use rustc_middle::ty::{self, TyCtxt};
7+
use rustc_middle::ty::TyCtxt;
88
use rustc_span::Span;
99
use rustc_type_ir::visit::TypeVisitable;
1010

@@ -25,24 +25,9 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
2525
let kind = tcx.def_kind(item);
2626
trace!(?kind);
2727
match kind {
28-
DefKind::Coroutine => {
29-
match tcx.type_of(item).instantiate_identity().kind() {
30-
ty::Coroutine(_, args, _) => visitor.visit(tcx.def_span(item), args.as_coroutine().sig())?,
31-
_ => bug!(),
32-
}
33-
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
34-
visitor.visit(span, pred)?;
35-
}
36-
}
37-
// Walk over the signature of the function-like
38-
DefKind::Closure | DefKind::AssocFn | DefKind::Fn => {
39-
let ty_sig = match kind {
40-
DefKind::Closure => match tcx.type_of(item).instantiate_identity().kind() {
41-
ty::Closure(_, args) => args.as_closure().sig(),
42-
_ => bug!(),
43-
},
44-
_ => tcx.fn_sig(item).instantiate_identity(),
45-
};
28+
// Walk over the signature of the function
29+
DefKind::AssocFn | DefKind::Fn => {
30+
let ty_sig = tcx.fn_sig(item).instantiate_identity();
4631
let hir_sig = tcx.hir().get_by_def_id(item).fn_decl().unwrap();
4732
// Walk over the inputs and outputs manually in order to get good spans for them.
4833
visitor.visit(hir_sig.output.span(), ty_sig.output());
@@ -61,7 +46,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
6146
Some(ty) => ty.span,
6247
_ => tcx.def_span(item),
6348
};
64-
visitor.visit(span, tcx.type_of(item).instantiate_identity());
49+
visitor.visit(span, tcx.type_of(item).instantiate_identity());
6550
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
6651
visitor.visit(span, pred)?;
6752
}
@@ -74,13 +59,15 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
7459
// Look at field types
7560
DefKind::Struct | DefKind::Union | DefKind::Enum => {
7661
let span = tcx.def_ident_span(item).unwrap();
77-
visitor.visit(span, tcx.type_of(item).instantiate_identity());
62+
visitor.visit(span, tcx.type_of(item).instantiate_identity());
7863
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
7964
visitor.visit(span, pred)?;
8065
}
8166
}
82-
// Does not have a syntactical signature
83-
DefKind::InlineConst => {}
67+
// These are not part of a public API, they can only appear as hidden types, and there
68+
// the interesting parts are solely in the signature of the containing item's opaque type
69+
// or dyn type.
70+
DefKind::InlineConst | DefKind::Closure | DefKind::Coroutine => {}
8471
DefKind::Impl { of_trait } => {
8572
if of_trait {
8673
let span = tcx.hir().get_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span;
@@ -92,15 +79,11 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
9279
_ => tcx.def_span(item),
9380
};
9481
visitor.visit(span, tcx.type_of(item).instantiate_identity());
95-
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
96-
visitor.visit(span, pred)?;
97-
}}
98-
DefKind::Trait => {
9982
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
10083
visitor.visit(span, pred)?;
10184
}
10285
}
103-
DefKind::TraitAlias => {
86+
DefKind::TraitAlias | DefKind::Trait => {
10487
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
10588
visitor.visit(span, pred)?;
10689
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! This test checks that we do not walk types in async blocks for
2+
//! determining the opaque types that appear in a signature. async blocks,
3+
//! all other coroutines and closures are always private and not part of
4+
//! a signature. They become part of a signature via `dyn Trait` or `impl Trait`,
5+
//! which is something that we process abstractly without looking at its hidden
6+
//! types.
7+
// edition: 2021
8+
// check-pass
9+
10+
#![feature(impl_trait_in_assoc_type)]
11+
12+
use std::future::Future;
13+
14+
pub struct MemtableLocalStateStore {
15+
mem_table: MemTable,
16+
}
17+
18+
impl LocalStateStore for MemtableLocalStateStore {
19+
type IterStream<'a> = impl Sized + 'a where Self: 'a;
20+
21+
fn iter(&self) -> impl Future<Output = Self::IterStream<'_>> + '_ {
22+
async move { merge_stream(self.mem_table.iter()) }
23+
}
24+
}
25+
26+
trait LocalStateStore {
27+
type IterStream<'a>
28+
where
29+
Self: 'a;
30+
31+
fn iter(&self) -> impl Future<Output = Self::IterStream<'_>> + '_;
32+
}
33+
34+
struct MemTable;
35+
36+
impl MemTable {
37+
fn iter<'a>(&'a self) -> impl Iterator<Item = &'a ()> {
38+
std::iter::empty()
39+
}
40+
}
41+
42+
pub(crate) async fn merge_stream<'a>(mem_table_iter: impl Iterator<Item = &'a ()>) {}
43+
44+
fn main() {}

0 commit comments

Comments
 (0)