rm ItemKind::OpaqueTy
This introduce an additional collection of opaques on HIR, as they can no longer be listed using the free item list.
This commit is contained in:
parent
4ec7839afa
commit
d6f247f3d5
45 changed files with 306 additions and 368 deletions
|
@ -284,14 +284,9 @@ pub fn suggest_new_region_bound(
|
|||
}
|
||||
match fn_return.kind {
|
||||
// FIXME(precise_captures): Suggest adding to `use<...>` list instead.
|
||||
TyKind::OpaqueDef(item_id, _) => {
|
||||
let item = tcx.hir().item(item_id);
|
||||
let ItemKind::OpaqueTy(opaque) = &item.kind else {
|
||||
return;
|
||||
};
|
||||
|
||||
TyKind::OpaqueDef(opaque, _) => {
|
||||
// Get the identity type for this RPIT
|
||||
let did = item_id.owner_id.to_def_id();
|
||||
let did = opaque.def_id.to_def_id();
|
||||
let ty = Ty::new_opaque(tcx, did, ty::GenericArgs::identity_for_item(tcx, did));
|
||||
|
||||
if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg {
|
||||
|
|
|
@ -720,7 +720,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *proj_ty.self_ty().kind() {
|
||||
let opaque_local_def_id = def_id.as_local();
|
||||
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
|
||||
tcx.hir().expect_item(opaque_local_def_id).expect_opaque_ty()
|
||||
tcx.hir().expect_opaque_ty(opaque_local_def_id)
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
|
|
|
@ -842,14 +842,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
lifetime: Region<'tcx>,
|
||||
add_lt_suggs: &mut Vec<(Span, String)>,
|
||||
) -> String {
|
||||
struct LifetimeReplaceVisitor<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
struct LifetimeReplaceVisitor<'a> {
|
||||
needle: hir::LifetimeName,
|
||||
new_lt: &'a str,
|
||||
add_lt_suggs: &'a mut Vec<(Span, String)>,
|
||||
}
|
||||
|
||||
impl<'hir, 'tcx> hir::intravisit::Visitor<'hir> for LifetimeReplaceVisitor<'_, 'tcx> {
|
||||
impl<'hir> hir::intravisit::Visitor<'hir> for LifetimeReplaceVisitor<'_> {
|
||||
fn visit_lifetime(&mut self, lt: &'hir hir::Lifetime) {
|
||||
if lt.res == self.needle {
|
||||
self.add_lt_suggs.push(lt.suggestion(self.new_lt));
|
||||
|
@ -857,10 +856,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'hir hir::Ty<'hir>) {
|
||||
let hir::TyKind::OpaqueDef(item_id, _) = ty.kind else {
|
||||
let hir::TyKind::OpaqueDef(opaque_ty, _) = ty.kind else {
|
||||
return hir::intravisit::walk_ty(self, ty);
|
||||
};
|
||||
let opaque_ty = self.tcx.hir().item(item_id).expect_opaque_ty();
|
||||
if let Some(&(_, b)) =
|
||||
opaque_ty.lifetime_mapping.iter().find(|&(a, _)| a.res == self.needle)
|
||||
{
|
||||
|
@ -905,7 +903,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
};
|
||||
|
||||
let mut visitor = LifetimeReplaceVisitor {
|
||||
tcx: self.tcx,
|
||||
needle: hir::LifetimeName::Param(lifetime_def_id),
|
||||
add_lt_suggs,
|
||||
new_lt: &new_lt,
|
||||
|
@ -1269,7 +1266,7 @@ fn suggest_precise_capturing<'tcx>(
|
|||
diag: &mut Diag<'_>,
|
||||
) {
|
||||
let hir::OpaqueTy { bounds, origin, .. } =
|
||||
tcx.hir_node_by_def_id(opaque_def_id).expect_item().expect_opaque_ty();
|
||||
tcx.hir_node_by_def_id(opaque_def_id).expect_opaque_ty();
|
||||
|
||||
let hir::OpaqueTyOrigin::FnReturn { parent: fn_def_id, .. } = *origin else {
|
||||
return;
|
||||
|
|
|
@ -731,12 +731,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
let exp_local_id = exp_def_id.as_local()?;
|
||||
|
||||
match (
|
||||
&self.tcx.hir().expect_item(last_local_id).kind,
|
||||
&self.tcx.hir().expect_item(exp_local_id).kind,
|
||||
&self.tcx.hir().expect_opaque_ty(last_local_id),
|
||||
&self.tcx.hir().expect_opaque_ty(exp_local_id),
|
||||
) {
|
||||
(
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: last_bounds, .. }),
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: exp_bounds, .. }),
|
||||
hir::OpaqueTy { bounds: last_bounds, .. },
|
||||
hir::OpaqueTy { bounds: exp_bounds, .. },
|
||||
) if std::iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| match (
|
||||
left, right,
|
||||
) {
|
||||
|
|
|
@ -355,12 +355,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
| hir::ItemKind::Fn(_, generics, _)
|
||||
| hir::ItemKind::TyAlias(_, generics)
|
||||
| hir::ItemKind::Const(_, generics, _)
|
||||
| hir::ItemKind::TraitAlias(generics, _)
|
||||
| hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }),
|
||||
| hir::ItemKind::TraitAlias(generics, _),
|
||||
..
|
||||
})
|
||||
| hir::Node::TraitItem(hir::TraitItem { generics, .. })
|
||||
| hir::Node::ImplItem(hir::ImplItem { generics, .. })
|
||||
| hir::Node::OpaqueTy(hir::OpaqueTy { generics, .. })
|
||||
if param_ty =>
|
||||
{
|
||||
// We skip the 0'th arg (self) because we do not want
|
||||
|
@ -421,10 +421,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
| hir::ItemKind::Fn(_, generics, _)
|
||||
| hir::ItemKind::TyAlias(_, generics)
|
||||
| hir::ItemKind::Const(_, generics, _)
|
||||
| hir::ItemKind::TraitAlias(generics, _)
|
||||
| hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }),
|
||||
| hir::ItemKind::TraitAlias(generics, _),
|
||||
..
|
||||
}) if !param_ty => {
|
||||
})
|
||||
| hir::Node::OpaqueTy(hir::OpaqueTy { generics, .. })
|
||||
if !param_ty =>
|
||||
{
|
||||
// Missing generic type parameter bound.
|
||||
if suggest_arbitrary_trait_bound(
|
||||
self.tcx,
|
||||
|
@ -4542,7 +4544,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
|
||||
// ... whose signature is `async` (i.e. this is an AFIT)
|
||||
let (sig, body) = item.expect_fn();
|
||||
let hir::FnRetTy::Return(hir::Ty { kind: hir::TyKind::OpaqueDef(def, ..), .. }) =
|
||||
let hir::FnRetTy::Return(hir::Ty { kind: hir::TyKind::OpaqueDef(opaq_def, ..), .. }) =
|
||||
sig.decl.output
|
||||
else {
|
||||
// This should never happen, but let's not ICE.
|
||||
|
@ -4551,7 +4553,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
|
||||
// Check that this is *not* a nested `impl Future` RPIT in an async fn
|
||||
// (i.e. `async fn foo() -> impl Future`)
|
||||
if def.owner_id.to_def_id() != opaque_def_id {
|
||||
if opaq_def.def_id.to_def_id() != opaque_def_id {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5159,7 +5161,7 @@ pub fn suggest_desugaring_async_fn_to_impl_future_in_trait<'tcx>(
|
|||
};
|
||||
let async_span = tcx.sess.source_map().span_extend_while_whitespace(async_span);
|
||||
|
||||
let future = tcx.hir_node_by_def_id(opaque_def_id).expect_item().expect_opaque_ty();
|
||||
let future = tcx.hir_node_by_def_id(opaque_def_id).expect_opaque_ty();
|
||||
let [hir::GenericBound::Trait(trait_ref, _)] = future.bounds else {
|
||||
// `async fn` should always lower to a single bound... but don't ICE.
|
||||
return None;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue