Make it clearer that we're just checking for an RPITIT

This commit is contained in:
Michael Goulet 2023-07-14 15:18:19 +00:00
parent bacf5bcbc7
commit 14672eba8b
9 changed files with 14 additions and 10 deletions

View File

@ -123,7 +123,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let all_candidate_names: Vec<_> = all_candidates()
.flat_map(|r| self.tcx().associated_items(r.def_id()).in_definition_order())
.filter_map(|item| {
if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
if !item.is_impl_trait_in_trait() && item.kind == ty::AssocKind::Type {
Some(item.name)
} else {
None
@ -164,7 +164,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.tcx().associated_items(*trait_def_id).in_definition_order()
})
.filter_map(|item| {
if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
if !item.is_impl_trait_in_trait() && item.kind == ty::AssocKind::Type {
Some(item.name)
} else {
None

View File

@ -173,7 +173,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.associated_items(pred.def_id())
.in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Type)
.filter(|item| item.opt_rpitit_info.is_none())
.filter(|item| !item.is_impl_trait_in_trait())
.map(|item| item.def_id),
);
}

View File

@ -1319,7 +1319,7 @@ fn compare_number_of_generics<'tcx>(
// has mismatched type or const generic arguments, then the method that it's
// inheriting the generics from will also have mismatched arguments, and
// we'll report an error for that instead. Delay a bug for safety, though.
if trait_.opt_rpitit_info.is_some() {
if trait_.is_impl_trait_in_trait() {
return Err(tcx.sess.delay_span_bug(
rustc_span::DUMMY_SP,
"errors comparing numbers of generics of trait/impl functions were not emitted",
@ -2111,7 +2111,7 @@ pub(super) fn check_type_bounds<'tcx>(
// A synthetic impl Trait for RPITIT desugaring has no HIR, which we currently use to get the
// span for an impl's associated type. Instead, for these, use the def_span for the synthesized
// associated type.
let impl_ty_span = if impl_ty.opt_rpitit_info.is_some() {
let impl_ty_span = if impl_ty.is_impl_trait_in_trait() {
tcx.def_span(impl_ty_def_id)
} else {
match tcx.hir().get_by_def_id(impl_ty_def_id) {

View File

@ -188,7 +188,7 @@ fn missing_items_err(
full_impl_span: Span,
) {
let missing_items =
missing_items.iter().filter(|trait_item| trait_item.opt_rpitit_info.is_none());
missing_items.iter().filter(|trait_item| !trait_item.is_impl_trait_in_trait());
let missing_items_msg = missing_items
.clone()

View File

@ -1136,7 +1136,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
// the default projection predicates in default trait methods
// with RPITITs.
ty::AssocItemContainer::TraitContainer => {
assoc_item.defaultness(tcx).has_value() || assoc_item.opt_rpitit_info.is_some()
assoc_item.defaultness(tcx).has_value() || assoc_item.is_impl_trait_in_trait()
}
}
}

View File

@ -92,6 +92,10 @@ impl AssocItem {
}
}
}
pub fn is_impl_trait_in_trait(&self) -> bool {
self.opt_rpitit_info.is_some()
}
}
#[derive(Copy, Clone, PartialEq, Debug, HashStable, Eq, Hash, Encodable, Decodable)]

View File

@ -276,7 +276,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
// Avoid accessing the HIR for the synthesized associated type generated for RPITITs.
if self.tcx.opt_rpitit_info(id.to_def_id()).is_some() {
if self.tcx.is_impl_trait_in_trait(id.to_def_id()) {
self.live_symbols.insert(id);
continue;
}

View File

@ -435,7 +435,7 @@ fn suggest_restriction<'tcx>(
) {
if hir_generics.where_clause_span.from_expansion()
|| hir_generics.where_clause_span.desugaring_kind().is_some()
|| projection.is_some_and(|projection| tcx.opt_rpitit_info(projection.def_id).is_some())
|| projection.is_some_and(|projection| tcx.is_impl_trait_in_trait(projection.def_id))
{
return;
}

View File

@ -393,7 +393,7 @@ fn object_safety_violation_for_assoc_item(
ty::AssocKind::Type => {
if !tcx.features().generic_associated_types_extended
&& !tcx.generics_of(item.def_id).params.is_empty()
&& item.opt_rpitit_info.is_none()
&& !item.is_impl_trait_in_trait()
{
Some(ObjectSafetyViolation::GAT(item.name, item.ident(tcx).span))
} else {