Auto merge of #117415 - matthiaskrgr:rollup-jr2p1t2, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #116862 (Detect when trait is implemented for type and suggest importing it) - #117389 (Some diagnostics improvements of `gen` blocks) - #117396 (Don't treat closures/coroutine types as part of the public API) - #117398 (Correctly handle nested or-patterns in exhaustiveness) - #117403 (Poison check_well_formed if method receivers are invalid to prevent typeck from running on it) - #117411 (Improve some diagnostics around `?Trait` bounds) - #117414 (Don't normalize to an un-revealed opaque when we hit the recursion limit) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
31bc7e2c47
31 changed files with 288 additions and 151 deletions
|
@ -121,6 +121,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> super::sig_types::SpannedTypeVisitor<'tcx> for OpaqueTypeCollector<'tcx> {
|
||||
#[instrument(skip(self), ret, level = "trace")]
|
||||
fn visit(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) -> ControlFlow<!> {
|
||||
self.visit_spanned(span, value);
|
||||
ControlFlow::Continue(())
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use rustc_hir::{def::DefKind, def_id::LocalDefId};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::Span;
|
||||
use rustc_type_ir::visit::TypeVisitable;
|
||||
|
||||
|
@ -25,24 +25,9 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
|
|||
let kind = tcx.def_kind(item);
|
||||
trace!(?kind);
|
||||
match kind {
|
||||
DefKind::Coroutine => {
|
||||
match tcx.type_of(item).instantiate_identity().kind() {
|
||||
ty::Coroutine(_, args, _) => visitor.visit(tcx.def_span(item), args.as_coroutine().sig())?,
|
||||
_ => bug!(),
|
||||
}
|
||||
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
|
||||
visitor.visit(span, pred)?;
|
||||
}
|
||||
}
|
||||
// Walk over the signature of the function-like
|
||||
DefKind::Closure | DefKind::AssocFn | DefKind::Fn => {
|
||||
let ty_sig = match kind {
|
||||
DefKind::Closure => match tcx.type_of(item).instantiate_identity().kind() {
|
||||
ty::Closure(_, args) => args.as_closure().sig(),
|
||||
_ => bug!(),
|
||||
},
|
||||
_ => tcx.fn_sig(item).instantiate_identity(),
|
||||
};
|
||||
// Walk over the signature of the function
|
||||
DefKind::AssocFn | DefKind::Fn => {
|
||||
let ty_sig = tcx.fn_sig(item).instantiate_identity();
|
||||
let hir_sig = tcx.hir().get_by_def_id(item).fn_decl().unwrap();
|
||||
// Walk over the inputs and outputs manually in order to get good spans for them.
|
||||
visitor.visit(hir_sig.output.span(), ty_sig.output());
|
||||
|
@ -61,7 +46,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
|
|||
Some(ty) => ty.span,
|
||||
_ => tcx.def_span(item),
|
||||
};
|
||||
visitor.visit(span, tcx.type_of(item).instantiate_identity());
|
||||
visitor.visit(span, tcx.type_of(item).instantiate_identity());
|
||||
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
|
||||
visitor.visit(span, pred)?;
|
||||
}
|
||||
|
@ -74,13 +59,15 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
|
|||
// Look at field types
|
||||
DefKind::Struct | DefKind::Union | DefKind::Enum => {
|
||||
let span = tcx.def_ident_span(item).unwrap();
|
||||
visitor.visit(span, tcx.type_of(item).instantiate_identity());
|
||||
visitor.visit(span, tcx.type_of(item).instantiate_identity());
|
||||
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
|
||||
visitor.visit(span, pred)?;
|
||||
}
|
||||
}
|
||||
// Does not have a syntactical signature
|
||||
DefKind::InlineConst => {}
|
||||
// These are not part of a public API, they can only appear as hidden types, and there
|
||||
// the interesting parts are solely in the signature of the containing item's opaque type
|
||||
// or dyn type.
|
||||
DefKind::InlineConst | DefKind::Closure | DefKind::Coroutine => {}
|
||||
DefKind::Impl { of_trait } => {
|
||||
if of_trait {
|
||||
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>>(
|
|||
_ => tcx.def_span(item),
|
||||
};
|
||||
visitor.visit(span, tcx.type_of(item).instantiate_identity());
|
||||
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
|
||||
visitor.visit(span, pred)?;
|
||||
}}
|
||||
DefKind::Trait => {
|
||||
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
|
||||
visitor.visit(span, pred)?;
|
||||
}
|
||||
}
|
||||
DefKind::TraitAlias => {
|
||||
DefKind::TraitAlias | DefKind::Trait => {
|
||||
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
|
||||
visitor.visit(span, pred)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue