Skip to content

Commit e41491f

Browse files
committed
ImplTraitPlaceholder -> is_impl_trait_in_trait
1 parent 39d19ca commit e41491f

File tree

10 files changed

+41
-34
lines changed

10 files changed

+41
-34
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::autoderef::Autoderef;
22
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
33

4-
use hir::def::DefKind;
54
use rustc_ast as ast;
65
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
76
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
@@ -1549,7 +1548,12 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
15491548
for arg in fn_output.walk() {
15501549
if let ty::GenericArgKind::Type(ty) = arg.unpack()
15511550
&& let ty::Alias(ty::Opaque, proj) = ty.kind()
1552-
&& tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
1551+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) we should just check
1552+
// `tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder`. Right now
1553+
// `check_associated_type_bounds` is not called for RPITITs synthesized as
1554+
// associated types. See `check_mod_type_wf` to see how synthesized associated
1555+
// types are missed due to iterating over HIR.
1556+
&& tcx.is_impl_trait_in_trait(proj.def_id)
15531557
&& tcx.impl_trait_in_trait_parent_fn(proj.def_id) == fn_def_id.to_def_id()
15541558
{
15551559
let span = tcx.def_span(proj.def_id);

compiler/rustc_hir_analysis/src/variance/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
112112
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
113113
match t.kind() {
114114
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
115-
if matches!(
116-
self.tcx.def_kind(*def_id),
117-
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
118-
) =>
115+
if matches!(self.tcx.def_kind(*def_id), DefKind::OpaqueTy) =>
116+
{
117+
self.visit_opaque(*def_id, substs)
118+
}
119+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) check whether this is necessary
120+
// at all for RPITITs.
121+
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
122+
if self.tcx.is_impl_trait_in_trait(*def_id) =>
119123
{
120124
self.visit_opaque(*def_id, substs)
121125
}

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
44

5-
use hir::def::DefKind;
65
use rustc_errors::ErrorGuaranteed;
76
use rustc_hir as hir;
87
use rustc_hir::lang_items::LangItem;
@@ -713,14 +712,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
713712
.subst_iter_copied(self.tcx, substs)
714713
.find_map(|(p, s)| get_future_output(p, s))?,
715714
ty::Error(_) => return None,
716-
ty::Alias(ty::Projection, proj)
717-
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
718-
{
719-
self.tcx
720-
.bound_explicit_item_bounds(proj.def_id)
721-
.subst_iter_copied(self.tcx, proj.substs)
722-
.find_map(|(p, s)| get_future_output(p, s))?
723-
}
715+
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
716+
.tcx
717+
.bound_explicit_item_bounds(proj.def_id)
718+
.subst_iter_copied(self.tcx, proj.substs)
719+
.find_map(|(p, s)| get_future_output(p, s))?,
724720
_ => span_bug!(
725721
self.tcx.def_span(expr_def_id),
726722
"async fn generator return type not an inference variable: {ret_ty}"

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,12 @@ impl<'tcx> InferCtxt<'tcx> {
359359
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
360360
let (def_id, substs) = match *ty.kind() {
361361
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
362-
if matches!(
363-
self.tcx.def_kind(def_id),
364-
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
365-
) =>
362+
if matches!(self.tcx.def_kind(def_id), DefKind::OpaqueTy) =>
363+
{
364+
(def_id, substs)
365+
}
366+
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
367+
if self.tcx.is_impl_trait_in_trait(def_id) =>
366368
{
367369
(def_id, substs)
368370
}
@@ -1754,8 +1756,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17541756
)
17551757
}
17561758
(true, ty::Alias(ty::Projection, proj))
1757-
if self.tcx.def_kind(proj.def_id)
1758-
== DefKind::ImplTraitPlaceholder =>
1759+
if self.tcx.is_impl_trait_in_trait(proj.def_id) =>
17591760
{
17601761
let sm = self.tcx.sess.source_map();
17611762
let pos = sm.lookup_char_pos(self.tcx.def_span(proj.def_id).lo());

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::TypeErrCtxt;
22
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect};
33
use rustc_errors::{pluralize, Diagnostic, MultiSpan};
4-
use rustc_hir::{self as hir, def::DefKind};
4+
use rustc_hir as hir;
55
use rustc_middle::traits::ObligationCauseCode;
66
use rustc_middle::ty::error::ExpectedFound;
77
use rustc_middle::ty::print::Printer;
@@ -75,7 +75,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
7575
diag.note("an associated type was expected, but a different one was found");
7676
}
7777
(ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p))
78-
if tcx.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder =>
78+
if !tcx.is_impl_trait_in_trait(proj.def_id) =>
7979
{
8080
let p_def_id = tcx
8181
.generics_of(body_owner_def_id)
@@ -222,7 +222,7 @@ impl<T> Trait<T> for X {
222222
diag.span_label(p_span, "this type parameter");
223223
}
224224
}
225-
(ty::Alias(ty::Projection, proj_ty), _) if tcx.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
225+
(ty::Alias(ty::Projection, proj_ty), _) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
226226
self.expected_projection(
227227
diag,
228228
proj_ty,
@@ -231,7 +231,7 @@ impl<T> Trait<T> for X {
231231
cause.code(),
232232
);
233233
}
234-
(_, ty::Alias(ty::Projection, proj_ty)) if tcx.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
234+
(_, ty::Alias(ty::Projection, proj_ty)) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
235235
let msg = format!(
236236
"consider constraining the associated type `{}` to `{}`",
237237
values.found, values.expected,

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::errors::OpaqueHiddenTypeDiag;
22
use crate::infer::{DefiningAnchor, InferCtxt, InferOk};
33
use crate::traits;
4-
use hir::def::DefKind;
54
use hir::def_id::{DefId, LocalDefId};
65
use hir::OpaqueTyOrigin;
76
use rustc_data_structures::sync::Lrc;
@@ -481,9 +480,7 @@ where
481480
}
482481
}
483482

484-
ty::Alias(ty::Projection, proj)
485-
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
486-
{
483+
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => {
487484
// Skip lifetime parameters that are not captures.
488485
let variances = self.tcx.variances_of(proj.def_id);
489486

@@ -563,8 +560,7 @@ impl<'tcx> InferCtxt<'tcx> {
563560
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
564561
ty::Alias(ty::Projection, projection_ty)
565562
if !projection_ty.has_escaping_bound_vars()
566-
&& tcx.def_kind(projection_ty.def_id)
567-
!= DefKind::ImplTraitPlaceholder =>
563+
&& !tcx.is_impl_trait_in_trait(projection_ty.def_id) =>
568564
{
569565
self.infer_projection(
570566
param_env,

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,10 @@ impl<'tcx> TyCtxt<'tcx> {
25782578

25792579
let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
25802580

2581+
if self.lower_impl_trait_in_trait_to_assoc_ty() {
2582+
return !self.associated_items_for_impl_trait_in_trait(trait_item_def_id).is_empty();
2583+
}
2584+
25812585
// FIXME(RPITIT): This does a somewhat manual walk through the signature
25822586
// of the trait fn to look for any RPITITs, but that's kinda doing a lot
25832587
// of work. We can probably remove this when we refactor RPITITs to be

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>:
728728
}
729729
ty::Alias(ty::Projection, ref data) => {
730730
if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get()))
731-
&& self.tcx().def_kind(data.def_id) == DefKind::ImplTraitPlaceholder
731+
&& self.tcx().is_impl_trait_in_trait(data.def_id)
732732
{
733733
return self.pretty_print_opaque_impl_type(data.def_id, data.substs);
734734
} else {

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
268268

269269
fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
270270
if let ty::Alias(ty::Projection, alias_ty) = *ty.kind()
271-
&& self.tcx.def_kind(alias_ty.def_id) == DefKind::ImplTraitPlaceholder
271+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) need to project to the opaque, could
272+
// get it via type_of + subst.
273+
&& self.tcx.is_impl_trait_in_trait(alias_ty.def_id)
272274
&& self.tcx.impl_trait_in_trait_parent_fn(alias_ty.def_id) == self.fn_def_id
273275
&& self.seen.insert(alias_ty.def_id)
274276
{

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ fn clean_projection<'tcx>(
426426
cx: &mut DocContext<'tcx>,
427427
def_id: Option<DefId>,
428428
) -> Type {
429-
if cx.tcx.def_kind(ty.skip_binder().def_id) == DefKind::ImplTraitPlaceholder {
429+
if cx.tcx.is_impl_trait_in_trait(ty.skip_binder().def_id) {
430430
let bounds = cx
431431
.tcx
432432
.explicit_item_bounds(ty.skip_binder().def_id)

0 commit comments

Comments
 (0)