11//! Code shared by trait and projection goals for candidate assembly.
22
33use rustc_hir:: def_id:: DefId ;
4+ use rustc_hir:: LangItem ;
45use rustc_infer:: infer:: InferCtxt ;
56use rustc_infer:: traits:: query:: NoSolution ;
67use rustc_middle:: bug;
@@ -481,7 +482,6 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
481482 candidates : & mut Vec < Candidate < ' tcx > > ,
482483 ) {
483484 let tcx = self . interner ( ) ;
484- let lang_items = tcx. lang_items ( ) ;
485485 let trait_def_id = goal. predicate . trait_def_id ( tcx) ;
486486
487487 // N.B. When assembling built-in candidates for lang items that are also
@@ -497,43 +497,43 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
497497 G :: consider_auto_trait_candidate ( self , goal)
498498 } else if tcx. trait_is_alias ( trait_def_id) {
499499 G :: consider_trait_alias_candidate ( self , goal)
500- } else if lang_items . sized_trait ( ) == Some ( trait_def_id) {
500+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: Sized ) {
501501 G :: consider_builtin_sized_candidate ( self , goal)
502- } else if lang_items . copy_trait ( ) == Some ( trait_def_id)
503- || lang_items . clone_trait ( ) == Some ( trait_def_id)
502+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: Copy )
503+ || tcx . is_lang_item ( trait_def_id, LangItem :: Clone )
504504 {
505505 G :: consider_builtin_copy_clone_candidate ( self , goal)
506- } else if lang_items . pointer_like ( ) == Some ( trait_def_id) {
506+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: PointerLike ) {
507507 G :: consider_builtin_pointer_like_candidate ( self , goal)
508- } else if lang_items . fn_ptr_trait ( ) == Some ( trait_def_id) {
508+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: FnPtrTrait ) {
509509 G :: consider_builtin_fn_ptr_trait_candidate ( self , goal)
510510 } else if let Some ( kind) = self . interner ( ) . fn_trait_kind_from_def_id ( trait_def_id) {
511511 G :: consider_builtin_fn_trait_candidates ( self , goal, kind)
512512 } else if let Some ( kind) = self . interner ( ) . async_fn_trait_kind_from_def_id ( trait_def_id) {
513513 G :: consider_builtin_async_fn_trait_candidates ( self , goal, kind)
514- } else if lang_items . async_fn_kind_helper ( ) == Some ( trait_def_id) {
514+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: AsyncFnKindHelper ) {
515515 G :: consider_builtin_async_fn_kind_helper_candidate ( self , goal)
516- } else if lang_items . tuple_trait ( ) == Some ( trait_def_id) {
516+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: Tuple ) {
517517 G :: consider_builtin_tuple_candidate ( self , goal)
518- } else if lang_items . pointee_trait ( ) == Some ( trait_def_id) {
518+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: PointeeTrait ) {
519519 G :: consider_builtin_pointee_candidate ( self , goal)
520- } else if lang_items . future_trait ( ) == Some ( trait_def_id) {
520+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: Future ) {
521521 G :: consider_builtin_future_candidate ( self , goal)
522- } else if lang_items . iterator_trait ( ) == Some ( trait_def_id) {
522+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: Iterator ) {
523523 G :: consider_builtin_iterator_candidate ( self , goal)
524- } else if lang_items . fused_iterator_trait ( ) == Some ( trait_def_id) {
524+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: FusedIterator ) {
525525 G :: consider_builtin_fused_iterator_candidate ( self , goal)
526- } else if lang_items . async_iterator_trait ( ) == Some ( trait_def_id) {
526+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: AsyncIterator ) {
527527 G :: consider_builtin_async_iterator_candidate ( self , goal)
528- } else if lang_items . coroutine_trait ( ) == Some ( trait_def_id) {
528+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: Coroutine ) {
529529 G :: consider_builtin_coroutine_candidate ( self , goal)
530- } else if lang_items . discriminant_kind_trait ( ) == Some ( trait_def_id) {
530+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: DiscriminantKind ) {
531531 G :: consider_builtin_discriminant_kind_candidate ( self , goal)
532- } else if lang_items . async_destruct_trait ( ) == Some ( trait_def_id) {
532+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: AsyncDestruct ) {
533533 G :: consider_builtin_async_destruct_candidate ( self , goal)
534- } else if lang_items . destruct_trait ( ) == Some ( trait_def_id) {
534+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: Destruct ) {
535535 G :: consider_builtin_destruct_candidate ( self , goal)
536- } else if lang_items . transmute_trait ( ) == Some ( trait_def_id) {
536+ } else if tcx . is_lang_item ( trait_def_id, LangItem :: TransmuteTrait ) {
537537 G :: consider_builtin_transmute_candidate ( self , goal)
538538 } else {
539539 Err ( NoSolution )
@@ -543,7 +543,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
543543
544544 // There may be multiple unsize candidates for a trait with several supertraits:
545545 // `trait Foo: Bar<A> + Bar<B>` and `dyn Foo: Unsize<dyn Bar<_>>`
546- if lang_items . unsize_trait ( ) == Some ( trait_def_id) {
546+ if tcx . is_lang_item ( trait_def_id, LangItem :: Unsize ) {
547547 candidates. extend ( G :: consider_structural_builtin_unsize_candidates ( self , goal) ) ;
548548 }
549549 }
0 commit comments