|
8 | 8 | // option. This file may not be copied, modified, or distributed |
9 | 9 | // except according to those terms. |
10 | 10 |
|
11 | | -use abi::Abi; |
12 | | -use common::*; |
13 | | - |
14 | 11 | use rustc::hir::def_id::DefId; |
15 | 12 | use rustc::middle::lang_items::DropInPlaceFnLangItem; |
16 | 13 | use rustc::traits; |
@@ -99,123 +96,14 @@ pub fn resolve_closure<'a, 'tcx> ( |
99 | 96 | } |
100 | 97 | } |
101 | 98 |
|
102 | | -fn resolve_associated_item<'a, 'tcx>( |
103 | | - tcx: TyCtxt<'a, 'tcx, 'tcx>, |
104 | | - trait_item: &ty::AssociatedItem, |
105 | | - trait_id: DefId, |
106 | | - rcvr_substs: &'tcx Substs<'tcx> |
107 | | -) -> Instance<'tcx> { |
108 | | - let def_id = trait_item.def_id; |
109 | | - debug!("resolve_associated_item(trait_item={:?}, \ |
110 | | - trait_id={:?}, \ |
111 | | - rcvr_substs={:?})", |
112 | | - def_id, trait_id, rcvr_substs); |
113 | | - |
114 | | - let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs); |
115 | | - let vtbl = tcx.trans_fulfill_obligation( |
116 | | - DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), ty::Binder(trait_ref)); |
117 | | - |
118 | | - // Now that we know which impl is being used, we can dispatch to |
119 | | - // the actual function: |
120 | | - match vtbl { |
121 | | - traits::VtableImpl(impl_data) => { |
122 | | - let (def_id, substs) = traits::find_associated_item( |
123 | | - tcx, trait_item, rcvr_substs, &impl_data); |
124 | | - let substs = tcx.erase_regions(&substs); |
125 | | - ty::Instance::new(def_id, substs) |
126 | | - } |
127 | | - traits::VtableGenerator(closure_data) => { |
128 | | - Instance { |
129 | | - def: ty::InstanceDef::Item(closure_data.closure_def_id), |
130 | | - substs: closure_data.substs.substs |
131 | | - } |
132 | | - } |
133 | | - traits::VtableClosure(closure_data) => { |
134 | | - let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap(); |
135 | | - resolve_closure(tcx, closure_data.closure_def_id, closure_data.substs, |
136 | | - trait_closure_kind) |
137 | | - } |
138 | | - traits::VtableFnPointer(ref data) => { |
139 | | - Instance { |
140 | | - def: ty::InstanceDef::FnPtrShim(trait_item.def_id, data.fn_ty), |
141 | | - substs: rcvr_substs |
142 | | - } |
143 | | - } |
144 | | - traits::VtableObject(ref data) => { |
145 | | - let index = tcx.get_vtable_index_of_object_method(data, def_id); |
146 | | - Instance { |
147 | | - def: ty::InstanceDef::Virtual(def_id, index), |
148 | | - substs: rcvr_substs |
149 | | - } |
150 | | - } |
151 | | - traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items().clone_trait() => { |
152 | | - Instance { |
153 | | - def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()), |
154 | | - substs: rcvr_substs |
155 | | - } |
156 | | - } |
157 | | - _ => { |
158 | | - bug!("static call to invalid vtable: {:?}", vtbl) |
159 | | - } |
160 | | - } |
161 | | -} |
162 | | - |
163 | | -/// The point where linking happens. Resolve a (def_id, substs) |
164 | | -/// pair to an instance. |
165 | | -pub fn resolve<'a, 'tcx>( |
166 | | - tcx: TyCtxt<'a, 'tcx, 'tcx>, |
167 | | - def_id: DefId, |
168 | | - substs: &'tcx Substs<'tcx> |
169 | | -) -> Instance<'tcx> { |
170 | | - debug!("resolve(def_id={:?}, substs={:?})", |
171 | | - def_id, substs); |
172 | | - let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) { |
173 | | - debug!(" => associated item, attempting to find impl"); |
174 | | - let item = tcx.associated_item(def_id); |
175 | | - resolve_associated_item(tcx, &item, trait_def_id, substs) |
176 | | - } else { |
177 | | - let item_type = def_ty(tcx, def_id, substs); |
178 | | - let def = match item_type.sty { |
179 | | - ty::TyFnDef(..) if { |
180 | | - let f = item_type.fn_sig(tcx); |
181 | | - f.abi() == Abi::RustIntrinsic || |
182 | | - f.abi() == Abi::PlatformIntrinsic |
183 | | - } => |
184 | | - { |
185 | | - debug!(" => intrinsic"); |
186 | | - ty::InstanceDef::Intrinsic(def_id) |
187 | | - } |
188 | | - _ => { |
189 | | - if Some(def_id) == tcx.lang_items().drop_in_place_fn() { |
190 | | - let ty = substs.type_at(0); |
191 | | - if type_needs_drop(tcx, ty) { |
192 | | - debug!(" => nontrivial drop glue"); |
193 | | - ty::InstanceDef::DropGlue(def_id, Some(ty)) |
194 | | - } else { |
195 | | - debug!(" => trivial drop glue"); |
196 | | - ty::InstanceDef::DropGlue(def_id, None) |
197 | | - } |
198 | | - } else { |
199 | | - debug!(" => free item"); |
200 | | - ty::InstanceDef::Item(def_id) |
201 | | - } |
202 | | - } |
203 | | - }; |
204 | | - Instance { def, substs } |
205 | | - }; |
206 | | - debug!("resolve(def_id={:?}, substs={:?}) = {}", |
207 | | - def_id, substs, result); |
208 | | - result |
209 | | -} |
210 | | - |
211 | 99 | pub fn resolve_drop_in_place<'a, 'tcx>( |
212 | 100 | tcx: TyCtxt<'a, 'tcx, 'tcx>, |
213 | 101 | ty: Ty<'tcx>) |
214 | 102 | -> ty::Instance<'tcx> |
215 | 103 | { |
216 | 104 | let def_id = tcx.require_lang_item(DropInPlaceFnLangItem); |
217 | 105 | let substs = tcx.intern_substs(&[Kind::from(ty)]); |
218 | | - resolve(tcx, def_id, substs) |
| 106 | + Instance::resolve(tcx, ty::ParamEnv::empty(traits::Reveal::All), def_id, substs).unwrap() |
219 | 107 | } |
220 | 108 |
|
221 | 109 | pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, |
|
0 commit comments