Lift TraitRef into rustc_type_ir
This commit is contained in:
@@ -973,9 +973,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
//
|
||||
// NOTE: This should be kept in sync with the similar code in
|
||||
// `rustc_ty_utils::instance::resolve_associated_item()`.
|
||||
let node_item =
|
||||
specialization_graph::assoc_def(selcx.tcx(), impl_data.impl_def_id, obligation.predicate.def_id)
|
||||
.map_err(|ErrorGuaranteed { .. }| ())?;
|
||||
let node_item = specialization_graph::assoc_def(
|
||||
selcx.tcx(),
|
||||
impl_data.impl_def_id,
|
||||
obligation.predicate.def_id,
|
||||
)
|
||||
.map_err(|ErrorGuaranteed { .. }| ())?;
|
||||
|
||||
if node_item.is_final() {
|
||||
// Non-specializable items are always projectable.
|
||||
@@ -1018,7 +1021,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
lang_items.async_fn_trait(),
|
||||
lang_items.async_fn_mut_trait(),
|
||||
lang_items.async_fn_once_trait(),
|
||||
].contains(&Some(trait_ref.def_id))
|
||||
]
|
||||
.contains(&Some(trait_ref.def_id))
|
||||
{
|
||||
true
|
||||
} else if lang_items.async_fn_kind_helper() == Some(trait_ref.def_id) {
|
||||
@@ -1031,7 +1035,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
true
|
||||
} else {
|
||||
obligation.predicate.args.type_at(0).to_opt_closure_kind().is_some()
|
||||
&& obligation.predicate.args.type_at(1).to_opt_closure_kind().is_some()
|
||||
&& obligation.predicate.args.type_at(1).to_opt_closure_kind().is_some()
|
||||
}
|
||||
} else if lang_items.discriminant_kind_trait() == Some(trait_ref.def_id) {
|
||||
match self_ty.kind() {
|
||||
@@ -1158,12 +1162,20 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
// Otherwise, type parameters, opaques, and unnormalized projections have
|
||||
// unit metadata if they're known (e.g. by the param_env) to be sized.
|
||||
ty::Param(_) | ty::Alias(..)
|
||||
if self_ty != tail || selcx.infcx.predicate_must_hold_modulo_regions(
|
||||
&obligation.with(
|
||||
selcx.tcx(),
|
||||
ty::TraitRef::from_lang_item(selcx.tcx(), LangItem::Sized, obligation.cause.span(),[self_ty]),
|
||||
),
|
||||
) =>
|
||||
if self_ty != tail
|
||||
|| selcx.infcx.predicate_must_hold_modulo_regions(
|
||||
&obligation.with(
|
||||
selcx.tcx(),
|
||||
ty::TraitRef::new(
|
||||
selcx.tcx(),
|
||||
selcx.tcx().require_lang_item(
|
||||
LangItem::Sized,
|
||||
Some(obligation.cause.span()),
|
||||
),
|
||||
[self_ty],
|
||||
),
|
||||
),
|
||||
) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
@@ -1226,7 +1238,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
obligation.cause.span,
|
||||
format!("Cannot project an associated type from `{impl_source:?}`"),
|
||||
);
|
||||
return Err(())
|
||||
return Err(());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1555,10 +1567,9 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
// and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`.
|
||||
// FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't
|
||||
// exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
|
||||
let sized_predicate = ty::TraitRef::from_lang_item(
|
||||
let sized_predicate = ty::TraitRef::new(
|
||||
tcx,
|
||||
LangItem::Sized,
|
||||
obligation.cause.span(),
|
||||
tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span())),
|
||||
[self_ty],
|
||||
);
|
||||
obligations.push(obligation.with(tcx, sized_predicate));
|
||||
|
||||
Reference in New Issue
Block a user