Properly implement explicit_item_bounds for RPITITs trait assoc ty
This commit is contained in:
parent
83c0ff8fa5
commit
e10034c636
2 changed files with 23 additions and 14 deletions
|
@ -3,7 +3,7 @@ use crate::astconv::AstConv;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::traits::util;
|
use rustc_infer::traits::util;
|
||||||
use rustc_middle::ty::subst::InternalSubsts;
|
use rustc_middle::ty::subst::InternalSubsts;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, ImplTraitInTraitData, Ty, TyCtxt};
|
||||||
use rustc_span::def_id::DefId;
|
use rustc_span::def_id::DefId;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -58,17 +58,10 @@ fn opaque_type_bounds<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
opaque_def_id: DefId,
|
opaque_def_id: DefId,
|
||||||
ast_bounds: &'tcx [hir::GenericBound<'tcx>],
|
ast_bounds: &'tcx [hir::GenericBound<'tcx>],
|
||||||
|
item_ty: Ty<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
in_trait: bool,
|
|
||||||
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
||||||
ty::print::with_no_queries!({
|
ty::print::with_no_queries!({
|
||||||
let substs = InternalSubsts::identity_for_item(tcx, opaque_def_id);
|
|
||||||
let item_ty = if in_trait {
|
|
||||||
tcx.mk_projection(opaque_def_id, substs)
|
|
||||||
} else {
|
|
||||||
tcx.mk_opaque(opaque_def_id, substs)
|
|
||||||
};
|
|
||||||
|
|
||||||
let icx = ItemCtxt::new(tcx, opaque_def_id);
|
let icx = ItemCtxt::new(tcx, opaque_def_id);
|
||||||
let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds);
|
let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds);
|
||||||
// Opaque types are implicitly sized unless a `?Sized` bound is found
|
// Opaque types are implicitly sized unless a `?Sized` bound is found
|
||||||
|
@ -83,7 +76,18 @@ pub(super) fn explicit_item_bounds(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
) -> &'_ [(ty::Predicate<'_>, Span)] {
|
) -> &'_ [(ty::Predicate<'_>, Span)] {
|
||||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
// If the def_id is about an RPITIT, delegate explicit_item_bounds to the opaque_def_id that
|
||||||
|
// generated the synthesized associate type.
|
||||||
|
let rpitit_info = if let Some(ImplTraitInTraitData::Trait { opaque_def_id, .. }) =
|
||||||
|
tcx.opt_rpitit_info(def_id)
|
||||||
|
{
|
||||||
|
Some(opaque_def_id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let bounds_def_id = rpitit_info.unwrap_or(def_id);
|
||||||
|
let hir_id = tcx.hir().local_def_id_to_hir_id(bounds_def_id.expect_local());
|
||||||
match tcx.hir().get(hir_id) {
|
match tcx.hir().get(hir_id) {
|
||||||
hir::Node::TraitItem(hir::TraitItem {
|
hir::Node::TraitItem(hir::TraitItem {
|
||||||
kind: hir::TraitItemKind::Type(bounds, _),
|
kind: hir::TraitItemKind::Type(bounds, _),
|
||||||
|
@ -94,7 +98,15 @@ pub(super) fn explicit_item_bounds(
|
||||||
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, in_trait, .. }),
|
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, in_trait, .. }),
|
||||||
span,
|
span,
|
||||||
..
|
..
|
||||||
}) => opaque_type_bounds(tcx, def_id, bounds, *span, *in_trait),
|
}) => {
|
||||||
|
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||||
|
let item_ty = if *in_trait || rpitit_info.is_some() {
|
||||||
|
tcx.mk_projection(def_id, substs)
|
||||||
|
} else {
|
||||||
|
tcx.mk_opaque(def_id, substs)
|
||||||
|
};
|
||||||
|
opaque_type_bounds(tcx, bounds_def_id, bounds, item_ty, *span)
|
||||||
|
}
|
||||||
_ => bug!("item_bounds called on {:?}", def_id),
|
_ => bug!("item_bounds called on {:?}", def_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,9 +302,6 @@ fn associated_item_for_impl_trait_in_trait(
|
||||||
// There are no inferred outlives for the synthesized associated type.
|
// There are no inferred outlives for the synthesized associated type.
|
||||||
trait_assoc_ty.inferred_outlives_of(&[]);
|
trait_assoc_ty.inferred_outlives_of(&[]);
|
||||||
|
|
||||||
// FIXME implement this.
|
|
||||||
trait_assoc_ty.explicit_item_bounds(&[]);
|
|
||||||
|
|
||||||
local_def_id
|
local_def_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue