Use is_lang_item more aggressively
This commit is contained in:
@@ -1015,6 +1015,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
// not eligible.
|
||||
let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
|
||||
|
||||
let tcx = selcx.tcx();
|
||||
let lang_items = selcx.tcx().lang_items();
|
||||
if [
|
||||
lang_items.coroutine_trait(),
|
||||
@@ -1031,7 +1032,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
.contains(&Some(trait_ref.def_id))
|
||||
{
|
||||
true
|
||||
} else if lang_items.async_fn_kind_helper() == Some(trait_ref.def_id) {
|
||||
} else if tcx.is_lang_item(trait_ref.def_id, LangItem::AsyncFnKindHelper) {
|
||||
// FIXME(async_closures): Validity constraints here could be cleaned up.
|
||||
if obligation.predicate.args.type_at(0).is_ty_var()
|
||||
|| obligation.predicate.args.type_at(4).is_ty_var()
|
||||
@@ -1043,7 +1044,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
obligation.predicate.args.type_at(0).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) {
|
||||
} else if tcx.is_lang_item(trait_ref.def_id, LangItem::DiscriminantKind) {
|
||||
match self_ty.kind() {
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
@@ -1080,7 +1081,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
| ty::Infer(..)
|
||||
| ty::Error(_) => false,
|
||||
}
|
||||
} else if lang_items.async_destruct_trait() == Some(trait_ref.def_id) {
|
||||
} else if tcx.is_lang_item(trait_ref.def_id, LangItem::AsyncDestruct) {
|
||||
match self_ty.kind() {
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
@@ -1116,7 +1117,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
| ty::Infer(_)
|
||||
| ty::Error(_) => false,
|
||||
}
|
||||
} else if lang_items.pointee_trait() == Some(trait_ref.def_id) {
|
||||
} else if tcx.is_lang_item(trait_ref.def_id, LangItem::PointeeTrait) {
|
||||
let tail = selcx.tcx().struct_tail_with_normalize(
|
||||
self_ty,
|
||||
|ty| {
|
||||
@@ -1300,15 +1301,15 @@ fn confirm_select_candidate<'cx, 'tcx>(
|
||||
match impl_source {
|
||||
ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, data) => {
|
||||
let trait_def_id = obligation.predicate.trait_def_id(selcx.tcx());
|
||||
let lang_items = selcx.tcx().lang_items();
|
||||
if lang_items.coroutine_trait() == Some(trait_def_id) {
|
||||
let tcx = selcx.tcx();
|
||||
let trait_def_id = obligation.predicate.trait_def_id(tcx);
|
||||
if tcx.is_lang_item(trait_def_id, LangItem::Coroutine) {
|
||||
confirm_coroutine_candidate(selcx, obligation, data)
|
||||
} else if lang_items.future_trait() == Some(trait_def_id) {
|
||||
} else if tcx.is_lang_item(trait_def_id, LangItem::Future) {
|
||||
confirm_future_candidate(selcx, obligation, data)
|
||||
} else if lang_items.iterator_trait() == Some(trait_def_id) {
|
||||
} else if tcx.is_lang_item(trait_def_id, LangItem::Iterator) {
|
||||
confirm_iterator_candidate(selcx, obligation, data)
|
||||
} else if lang_items.async_iterator_trait() == Some(trait_def_id) {
|
||||
} else if tcx.is_lang_item(trait_def_id, LangItem::AsyncIterator) {
|
||||
confirm_async_iterator_candidate(selcx, obligation, data)
|
||||
} else if selcx.tcx().fn_trait_kind_from_def_id(trait_def_id).is_some() {
|
||||
if obligation.predicate.self_ty().is_closure()
|
||||
@@ -1320,7 +1321,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
|
||||
}
|
||||
} else if selcx.tcx().async_fn_trait_kind_from_def_id(trait_def_id).is_some() {
|
||||
confirm_async_closure_candidate(selcx, obligation, data)
|
||||
} else if lang_items.async_fn_kind_helper() == Some(trait_def_id) {
|
||||
} else if tcx.is_lang_item(trait_def_id, LangItem::AsyncFnKindHelper) {
|
||||
confirm_async_fn_kind_helper_candidate(selcx, obligation, data)
|
||||
} else {
|
||||
confirm_builtin_candidate(selcx, obligation, data)
|
||||
@@ -1373,10 +1374,9 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
|
||||
coroutine_sig,
|
||||
);
|
||||
|
||||
let lang_items = tcx.lang_items();
|
||||
let ty = if Some(obligation.predicate.def_id) == lang_items.coroutine_return() {
|
||||
let ty = if tcx.is_lang_item(obligation.predicate.def_id, LangItem::CoroutineReturn) {
|
||||
return_ty
|
||||
} else if Some(obligation.predicate.def_id) == lang_items.coroutine_yield() {
|
||||
} else if tcx.is_lang_item(obligation.predicate.def_id, LangItem::CoroutineYield) {
|
||||
yield_ty
|
||||
} else {
|
||||
span_bug!(
|
||||
@@ -1539,21 +1539,20 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
) -> Progress<'tcx> {
|
||||
let tcx = selcx.tcx();
|
||||
let self_ty = obligation.predicate.self_ty();
|
||||
let lang_items = tcx.lang_items();
|
||||
let item_def_id = obligation.predicate.def_id;
|
||||
let trait_def_id = tcx.trait_of_item(item_def_id).unwrap();
|
||||
let args = tcx.mk_args(&[self_ty.into()]);
|
||||
let (term, obligations) = if lang_items.discriminant_kind_trait() == Some(trait_def_id) {
|
||||
let (term, obligations) = if tcx.is_lang_item(trait_def_id, LangItem::DiscriminantKind) {
|
||||
let discriminant_def_id = tcx.require_lang_item(LangItem::Discriminant, None);
|
||||
assert_eq!(discriminant_def_id, item_def_id);
|
||||
|
||||
(self_ty.discriminant_ty(tcx).into(), Vec::new())
|
||||
} else if lang_items.async_destruct_trait() == Some(trait_def_id) {
|
||||
} else if tcx.is_lang_item(trait_def_id, LangItem::AsyncDestruct) {
|
||||
let destructor_def_id = tcx.associated_item_def_ids(trait_def_id)[0];
|
||||
assert_eq!(destructor_def_id, item_def_id);
|
||||
|
||||
(self_ty.async_destructor_ty(tcx).into(), Vec::new())
|
||||
} else if lang_items.pointee_trait() == Some(trait_def_id) {
|
||||
} else if tcx.is_lang_item(trait_def_id, LangItem::PointeeTrait) {
|
||||
let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None);
|
||||
assert_eq!(metadata_def_id, item_def_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user