Skip to content

Commit 8d03e13

Browse files
committed
Don't treat closures/coroutines as part of the public API
1 parent 972ee01 commit 8d03e13

File tree

4 files changed

+16
-36
lines changed

4 files changed

+16
-36
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

+8-21
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());
@@ -79,8 +64,10 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'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;

tests/ui/type-alias-impl-trait/nested_impl_trait_in_assoc_ty.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
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.
17
// edition: 2021
8+
// check-pass
29

310
#![feature(impl_trait_in_assoc_type)]
411

tests/ui/type-alias-impl-trait/nested_impl_trait_in_assoc_ty.stderr

-15
This file was deleted.

0 commit comments

Comments
 (0)