1
1
//! Code shared by trait and projection goals for candidate assembly.
2
2
3
3
use rustc_hir:: def_id:: DefId ;
4
+ use rustc_hir:: LangItem ;
4
5
use rustc_infer:: infer:: InferCtxt ;
5
6
use rustc_infer:: traits:: query:: NoSolution ;
6
7
use rustc_middle:: bug;
@@ -481,7 +482,6 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
481
482
candidates : & mut Vec < Candidate < ' tcx > > ,
482
483
) {
483
484
let tcx = self . interner ( ) ;
484
- let lang_items = tcx. lang_items ( ) ;
485
485
let trait_def_id = goal. predicate . trait_def_id ( tcx) ;
486
486
487
487
// N.B. When assembling built-in candidates for lang items that are also
@@ -497,43 +497,43 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
497
497
G :: consider_auto_trait_candidate ( self , goal)
498
498
} else if tcx. trait_is_alias ( trait_def_id) {
499
499
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 ) {
501
501
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 )
504
504
{
505
505
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 ) {
507
507
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 ) {
509
509
G :: consider_builtin_fn_ptr_trait_candidate ( self , goal)
510
510
} else if let Some ( kind) = self . interner ( ) . fn_trait_kind_from_def_id ( trait_def_id) {
511
511
G :: consider_builtin_fn_trait_candidates ( self , goal, kind)
512
512
} else if let Some ( kind) = self . interner ( ) . async_fn_trait_kind_from_def_id ( trait_def_id) {
513
513
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 ) {
515
515
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 ) {
517
517
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 ) {
519
519
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 ) {
521
521
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 ) {
523
523
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 ) {
525
525
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 ) {
527
527
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 ) {
529
529
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 ) {
531
531
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 ) {
533
533
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 ) {
535
535
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 ) {
537
537
G :: consider_builtin_transmute_candidate ( self , goal)
538
538
} else {
539
539
Err ( NoSolution )
@@ -543,7 +543,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
543
543
544
544
// There may be multiple unsize candidates for a trait with several supertraits:
545
545
// `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 ) {
547
547
candidates. extend ( G :: consider_structural_builtin_unsize_candidates ( self , goal) ) ;
548
548
}
549
549
}
0 commit comments