@@ -64,109 +64,82 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
6464 // and applicable impls. There is a certain set of precedence rules here.
6565 let def_id = obligation. predicate . def_id ( ) ;
6666 let tcx = self . tcx ( ) ;
67-
68- match tcx. as_lang_item ( def_id) {
69- Some ( LangItem :: Copy ) => {
70- debug ! ( obligation_self_ty = ?obligation. predicate. skip_binder( ) . self_ty( ) ) ;
71-
72- // User-defined copy impls are permitted, but only for
73- // structs and enums.
74- self . assemble_candidates_from_impls ( obligation, & mut candidates) ;
75-
76- // For other types, we'll use the builtin rules.
77- let copy_conditions = self . copy_clone_conditions ( obligation) ;
78- self . assemble_builtin_bound_candidates ( copy_conditions, & mut candidates) ;
79- }
80- Some ( LangItem :: DiscriminantKind ) => {
81- // `DiscriminantKind` is automatically implemented for every type.
82- candidates. vec . push ( BuiltinCandidate { has_nested : false } ) ;
83- }
84- Some ( LangItem :: PointeeTrait ) => {
85- // `Pointee` is automatically implemented for every type.
86- candidates. vec . push ( BuiltinCandidate { has_nested : false } ) ;
87- }
88- Some ( LangItem :: Sized ) => {
89- self . assemble_builtin_sized_candidate (
90- obligation,
91- & mut candidates,
92- SizedTraitKind :: Sized ,
93- ) ;
94- }
95- Some ( LangItem :: MetaSized ) => {
96- self . assemble_builtin_sized_candidate (
97- obligation,
98- & mut candidates,
99- SizedTraitKind :: MetaSized ,
100- ) ;
101- }
102- Some ( LangItem :: PointeeSized ) => {
103- bug ! ( "`PointeeSized` is removed during lowering" ) ;
104- }
105- Some ( LangItem :: Unsize ) => {
106- self . assemble_candidates_for_unsizing ( obligation, & mut candidates) ;
107- }
108- Some ( LangItem :: Destruct ) => {
109- self . assemble_const_destruct_candidates ( obligation, & mut candidates) ;
110- }
111- Some ( LangItem :: TransmuteTrait ) => {
112- // User-defined transmutability impls are permitted.
113- self . assemble_candidates_from_impls ( obligation, & mut candidates) ;
114- self . assemble_candidates_for_transmutability ( obligation, & mut candidates) ;
115- }
116- Some ( LangItem :: Tuple ) => {
117- self . assemble_candidate_for_tuple ( obligation, & mut candidates) ;
118- }
119- Some ( LangItem :: FnPtrTrait ) => {
120- self . assemble_candidates_for_fn_ptr_trait ( obligation, & mut candidates) ;
121- }
122- Some ( LangItem :: BikeshedGuaranteedNoDrop ) => {
123- self . assemble_candidates_for_bikeshed_guaranteed_no_drop_trait (
124- obligation,
125- & mut candidates,
126- ) ;
67+ if tcx. is_lang_item ( def_id, LangItem :: Copy ) {
68+ debug ! ( obligation_self_ty = ?obligation. predicate. skip_binder( ) . self_ty( ) ) ;
69+ // User-defined copy impls are permitted, but only for
70+ // structs and enums.
71+ self . assemble_candidates_from_impls ( obligation, & mut candidates) ;
72+ // For other types, we'll use the builtin rules.
73+ let copy_conditions = self . copy_clone_conditions ( obligation) ;
74+ self . assemble_builtin_bound_candidates ( copy_conditions, & mut candidates) ;
75+ } else if tcx. is_lang_item ( def_id, LangItem :: DiscriminantKind ) {
76+ // `DiscriminantKind` is automatically implemented for every type.
77+ candidates. vec . push ( BuiltinCandidate { has_nested : false } ) ;
78+ } else if tcx. is_lang_item ( def_id, LangItem :: PointeeTrait ) {
79+ // `Pointee` is automatically implemented for every type.
80+ candidates. vec . push ( BuiltinCandidate { has_nested : false } ) ;
81+ } else if tcx. is_lang_item ( def_id, LangItem :: Sized ) {
82+ self . assemble_builtin_sized_candidate (
83+ obligation,
84+ & mut candidates,
85+ SizedTraitKind :: Sized ,
86+ ) ;
87+ } else if tcx. is_lang_item ( def_id, LangItem :: MetaSized ) {
88+ self . assemble_builtin_sized_candidate (
89+ obligation,
90+ & mut candidates,
91+ SizedTraitKind :: MetaSized ,
92+ ) ;
93+ } else if tcx. is_lang_item ( def_id, LangItem :: PointeeSized ) {
94+ self . assemble_builtin_sized_candidate (
95+ obligation,
96+ & mut candidates,
97+ SizedTraitKind :: PointeeSized ,
98+ ) ;
99+ } else if tcx. is_lang_item ( def_id, LangItem :: Unsize ) {
100+ self . assemble_candidates_for_unsizing ( obligation, & mut candidates) ;
101+ } else if tcx. is_lang_item ( def_id, LangItem :: Destruct ) {
102+ self . assemble_const_destruct_candidates ( obligation, & mut candidates) ;
103+ } else if tcx. is_lang_item ( def_id, LangItem :: TransmuteTrait ) {
104+ // User-defined transmutability impls are permitted.
105+ self . assemble_candidates_from_impls ( obligation, & mut candidates) ;
106+ self . assemble_candidates_for_transmutability ( obligation, & mut candidates) ;
107+ } else if tcx. is_lang_item ( def_id, LangItem :: Tuple ) {
108+ self . assemble_candidate_for_tuple ( obligation, & mut candidates) ;
109+ } else if tcx. is_lang_item ( def_id, LangItem :: FnPtrTrait ) {
110+ self . assemble_candidates_for_fn_ptr_trait ( obligation, & mut candidates) ;
111+ } else if tcx. is_lang_item ( def_id, LangItem :: BikeshedGuaranteedNoDrop ) {
112+ self . assemble_candidates_for_bikeshed_guaranteed_no_drop_trait (
113+ obligation,
114+ & mut candidates,
115+ ) ;
116+ } else {
117+ if tcx. is_lang_item ( def_id, LangItem :: Clone ) {
118+ // Same builtin conditions as `Copy`, i.e., every type which has builtin support
119+ // for `Copy` also has builtin support for `Clone`, and tuples/arrays of `Clone`
120+ // types have builtin support for `Clone`.
121+ let clone_conditions = self . copy_clone_conditions ( obligation) ;
122+ self . assemble_builtin_bound_candidates ( clone_conditions, & mut candidates) ;
127123 }
128- lang_item => {
129- if matches ! ( lang_item, Some ( LangItem :: Clone ) ) {
130- // Same builtin conditions as `Copy`, i.e., every type which has builtin support
131- // for `Copy` also has builtin support for `Clone`, and tuples/arrays of `Clone`
132- // types have builtin support for `Clone`.
133- let clone_conditions = self . copy_clone_conditions ( obligation) ;
134- self . assemble_builtin_bound_candidates ( clone_conditions, & mut candidates) ;
135- }
136-
137- match lang_item {
138- Some ( LangItem :: Coroutine ) => {
139- self . assemble_coroutine_candidates ( obligation, & mut candidates) ;
140- }
141- Some ( LangItem :: Future ) => {
142- self . assemble_future_candidates ( obligation, & mut candidates) ;
143- }
144- Some ( LangItem :: Iterator ) => {
145- self . assemble_iterator_candidates ( obligation, & mut candidates) ;
146- }
147- Some ( LangItem :: FusedIterator ) => {
148- self . assemble_fused_iterator_candidates ( obligation, & mut candidates) ;
149- }
150- Some ( LangItem :: AsyncIterator ) => {
151- self . assemble_async_iterator_candidates ( obligation, & mut candidates) ;
152- }
153- Some ( LangItem :: AsyncFnKindHelper ) => {
154- self . assemble_async_fn_kind_helper_candidates (
155- obligation,
156- & mut candidates,
157- ) ;
158- }
159- _ => ( ) ,
160- }
161-
162- // FIXME: Put these into `else if` blocks above, since they're built-in.
163- self . assemble_closure_candidates ( obligation, & mut candidates) ;
164- self . assemble_async_closure_candidates ( obligation, & mut candidates) ;
165- self . assemble_fn_pointer_candidates ( obligation, & mut candidates) ;
166-
167- self . assemble_candidates_from_impls ( obligation, & mut candidates) ;
168- self . assemble_candidates_from_object_ty ( obligation, & mut candidates) ;
124+ if tcx. is_lang_item ( def_id, LangItem :: Coroutine ) {
125+ self . assemble_coroutine_candidates ( obligation, & mut candidates) ;
126+ } else if tcx. is_lang_item ( def_id, LangItem :: Future ) {
127+ self . assemble_future_candidates ( obligation, & mut candidates) ;
128+ } else if tcx. is_lang_item ( def_id, LangItem :: Iterator ) {
129+ self . assemble_iterator_candidates ( obligation, & mut candidates) ;
130+ } else if tcx. is_lang_item ( def_id, LangItem :: FusedIterator ) {
131+ self . assemble_fused_iterator_candidates ( obligation, & mut candidates) ;
132+ } else if tcx. is_lang_item ( def_id, LangItem :: AsyncIterator ) {
133+ self . assemble_async_iterator_candidates ( obligation, & mut candidates) ;
134+ } else if tcx. is_lang_item ( def_id, LangItem :: AsyncFnKindHelper ) {
135+ self . assemble_async_fn_kind_helper_candidates ( obligation, & mut candidates) ;
169136 }
137+ // FIXME: Put these into `else if` blocks above, since they're built-in.
138+ self . assemble_closure_candidates ( obligation, & mut candidates) ;
139+ self . assemble_async_closure_candidates ( obligation, & mut candidates) ;
140+ self . assemble_fn_pointer_candidates ( obligation, & mut candidates) ;
141+ self . assemble_candidates_from_impls ( obligation, & mut candidates) ;
142+ self . assemble_candidates_from_object_ty ( obligation, & mut candidates) ;
170143 }
171144
172145 self . assemble_candidates_from_projected_tys ( obligation, & mut candidates) ;
0 commit comments