ImplTraitPlaceholder -> is_impl_trait_in_trait
This commit is contained in:
parent
39d19ca9f2
commit
e41491fe05
@ -1,7 +1,6 @@
|
||||
use crate::autoderef::Autoderef;
|
||||
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
|
||||
|
||||
use hir::def::DefKind;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||
@ -1549,7 +1548,12 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
|
||||
for arg in fn_output.walk() {
|
||||
if let ty::GenericArgKind::Type(ty) = arg.unpack()
|
||||
&& let ty::Alias(ty::Opaque, proj) = ty.kind()
|
||||
&& tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
|
||||
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) we should just check
|
||||
// `tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder`. Right now
|
||||
// `check_associated_type_bounds` is not called for RPITITs synthesized as
|
||||
// associated types. See `check_mod_type_wf` to see how synthesized associated
|
||||
// types are missed due to iterating over HIR.
|
||||
&& tcx.is_impl_trait_in_trait(proj.def_id)
|
||||
&& tcx.impl_trait_in_trait_parent_fn(proj.def_id) == fn_def_id.to_def_id()
|
||||
{
|
||||
let span = tcx.def_span(proj.def_id);
|
||||
|
@ -112,10 +112,14 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match t.kind() {
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||
if matches!(
|
||||
self.tcx.def_kind(*def_id),
|
||||
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
|
||||
) =>
|
||||
if matches!(self.tcx.def_kind(*def_id), DefKind::OpaqueTy) =>
|
||||
{
|
||||
self.visit_opaque(*def_id, substs)
|
||||
}
|
||||
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) check whether this is necessary
|
||||
// at all for RPITITs.
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||
if self.tcx.is_impl_trait_in_trait(*def_id) =>
|
||||
{
|
||||
self.visit_opaque(*def_id, substs)
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
|
||||
|
||||
use hir::def::DefKind;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
@ -713,14 +712,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.subst_iter_copied(self.tcx, substs)
|
||||
.find_map(|(p, s)| get_future_output(p, s))?,
|
||||
ty::Error(_) => return None,
|
||||
ty::Alias(ty::Projection, proj)
|
||||
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
self.tcx
|
||||
.bound_explicit_item_bounds(proj.def_id)
|
||||
.subst_iter_copied(self.tcx, proj.substs)
|
||||
.find_map(|(p, s)| get_future_output(p, s))?
|
||||
}
|
||||
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
|
||||
.tcx
|
||||
.bound_explicit_item_bounds(proj.def_id)
|
||||
.subst_iter_copied(self.tcx, proj.substs)
|
||||
.find_map(|(p, s)| get_future_output(p, s))?,
|
||||
_ => span_bug!(
|
||||
self.tcx.def_span(expr_def_id),
|
||||
"async fn generator return type not an inference variable: {ret_ty}"
|
||||
|
@ -359,10 +359,12 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
let (def_id, substs) = match *ty.kind() {
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||
if matches!(
|
||||
self.tcx.def_kind(def_id),
|
||||
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
|
||||
) =>
|
||||
if matches!(self.tcx.def_kind(def_id), DefKind::OpaqueTy) =>
|
||||
{
|
||||
(def_id, substs)
|
||||
}
|
||||
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||
if self.tcx.is_impl_trait_in_trait(def_id) =>
|
||||
{
|
||||
(def_id, substs)
|
||||
}
|
||||
@ -1754,8 +1756,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
)
|
||||
}
|
||||
(true, ty::Alias(ty::Projection, proj))
|
||||
if self.tcx.def_kind(proj.def_id)
|
||||
== DefKind::ImplTraitPlaceholder =>
|
||||
if self.tcx.is_impl_trait_in_trait(proj.def_id) =>
|
||||
{
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let pos = sm.lookup_char_pos(self.tcx.def_span(proj.def_id).lo());
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::TypeErrCtxt;
|
||||
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect};
|
||||
use rustc_errors::{pluralize, Diagnostic, MultiSpan};
|
||||
use rustc_hir::{self as hir, def::DefKind};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::traits::ObligationCauseCode;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
use rustc_middle::ty::print::Printer;
|
||||
@ -75,7 +75,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
diag.note("an associated type was expected, but a different one was found");
|
||||
}
|
||||
(ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p))
|
||||
if tcx.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder =>
|
||||
if !tcx.is_impl_trait_in_trait(proj.def_id) =>
|
||||
{
|
||||
let p_def_id = tcx
|
||||
.generics_of(body_owner_def_id)
|
||||
@ -222,7 +222,7 @@ impl<T> Trait<T> for X {
|
||||
diag.span_label(p_span, "this type parameter");
|
||||
}
|
||||
}
|
||||
(ty::Alias(ty::Projection, proj_ty), _) if tcx.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
|
||||
(ty::Alias(ty::Projection, proj_ty), _) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
|
||||
self.expected_projection(
|
||||
diag,
|
||||
proj_ty,
|
||||
@ -231,7 +231,7 @@ impl<T> Trait<T> for X {
|
||||
cause.code(),
|
||||
);
|
||||
}
|
||||
(_, ty::Alias(ty::Projection, proj_ty)) if tcx.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
|
||||
(_, ty::Alias(ty::Projection, proj_ty)) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
|
||||
let msg = format!(
|
||||
"consider constraining the associated type `{}` to `{}`",
|
||||
values.found, values.expected,
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::errors::OpaqueHiddenTypeDiag;
|
||||
use crate::infer::{DefiningAnchor, InferCtxt, InferOk};
|
||||
use crate::traits;
|
||||
use hir::def::DefKind;
|
||||
use hir::def_id::{DefId, LocalDefId};
|
||||
use hir::OpaqueTyOrigin;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
@ -481,9 +480,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
ty::Alias(ty::Projection, proj)
|
||||
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => {
|
||||
// Skip lifetime parameters that are not captures.
|
||||
let variances = self.tcx.variances_of(proj.def_id);
|
||||
|
||||
@ -563,8 +560,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
|
||||
ty::Alias(ty::Projection, projection_ty)
|
||||
if !projection_ty.has_escaping_bound_vars()
|
||||
&& tcx.def_kind(projection_ty.def_id)
|
||||
!= DefKind::ImplTraitPlaceholder =>
|
||||
&& !tcx.is_impl_trait_in_trait(projection_ty.def_id) =>
|
||||
{
|
||||
self.infer_projection(
|
||||
param_env,
|
||||
|
@ -2578,6 +2578,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
|
||||
|
||||
if self.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
return !self.associated_items_for_impl_trait_in_trait(trait_item_def_id).is_empty();
|
||||
}
|
||||
|
||||
// FIXME(RPITIT): This does a somewhat manual walk through the signature
|
||||
// of the trait fn to look for any RPITITs, but that's kinda doing a lot
|
||||
// of work. We can probably remove this when we refactor RPITITs to be
|
||||
|
@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
}
|
||||
ty::Alias(ty::Projection, ref data) => {
|
||||
if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get()))
|
||||
&& self.tcx().def_kind(data.def_id) == DefKind::ImplTraitPlaceholder
|
||||
&& self.tcx().is_impl_trait_in_trait(data.def_id)
|
||||
{
|
||||
return self.pretty_print_opaque_impl_type(data.def_id, data.substs);
|
||||
} else {
|
||||
|
@ -268,7 +268,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
|
||||
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
|
||||
if let ty::Alias(ty::Projection, alias_ty) = *ty.kind()
|
||||
&& self.tcx.def_kind(alias_ty.def_id) == DefKind::ImplTraitPlaceholder
|
||||
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) need to project to the opaque, could
|
||||
// get it via type_of + subst.
|
||||
&& self.tcx.is_impl_trait_in_trait(alias_ty.def_id)
|
||||
&& self.tcx.impl_trait_in_trait_parent_fn(alias_ty.def_id) == self.fn_def_id
|
||||
&& self.seen.insert(alias_ty.def_id)
|
||||
{
|
||||
|
@ -426,7 +426,7 @@ fn clean_projection<'tcx>(
|
||||
cx: &mut DocContext<'tcx>,
|
||||
def_id: Option<DefId>,
|
||||
) -> Type {
|
||||
if cx.tcx.def_kind(ty.skip_binder().def_id) == DefKind::ImplTraitPlaceholder {
|
||||
if cx.tcx.is_impl_trait_in_trait(ty.skip_binder().def_id) {
|
||||
let bounds = cx
|
||||
.tcx
|
||||
.explicit_item_bounds(ty.skip_binder().def_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user